commit: 0d6e5980d18b75832cb95f78e2053e8a9c0c2902
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 1 21:09:22 2014 +0000
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Fri Aug 15 21:42:42 2014 +0000
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=0d6e5980
Adds stub module
In the event that a user doesn't install layman with a specific
overlay type, the StubOverlay class will be used.
---
layman/overlays/modules/stub/__init__.py | 26 ++++++++++++++
layman/overlays/modules/stub/stub.py | 62 ++++++++++++++++++++++++++++++++
layman/overlays/overlay.py | 7 ++--
3 files changed, 91 insertions(+), 4 deletions(-)
diff --git a/layman/overlays/modules/stub/__init__.py
b/layman/overlays/modules/stub/__init__.py
new file mode 100644
index 0000000..a124d6a
--- /dev/null
+++ b/layman/overlays/modules/stub/__init__.py
@@ -0,0 +1,26 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+'''
+Stub plug-in module for layman.
+'''
+
+module_spec = {
+ 'name': 'stub',
+ 'description': __doc__,
+ 'provides':{
+ 'stub-module': {
+ 'name': 'stub',
+ 'class': 'StubOverlay',
+ 'description': __doc__,
+ 'functions': ['add', 'supported', 'sync', 'update'],
+ 'func_desc': {
+ 'add': 'Stub add function',
+ 'supported': 'Stub supported function',
+ 'sync': 'Stub sync function',
+ 'update': 'Stub update function',
+ },
+ }
+ }
+}
+
diff --git a/layman/overlays/modules/stub/stub.py
b/layman/overlays/modules/stub/stub.py
new file mode 100644
index 0000000..86612fe
--- /dev/null
+++ b/layman/overlays/modules/stub/stub.py
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.source import OverlaySource
+
+#===============================================================================
+#
+# Class StubOverlay
+#
+#-------------------------------------------------------------------------------
+
+class StubOverlay(OverlaySource):
+ ''' Handles overlays with missing modules. '''
+
+ type = 'N/A'
+ type_key = 'n/a'
+
+ def __init__(self, parent, config, _location, ignore = 0):
+ super(StubOverlay, self).__init__(parent,
+ config, _location, ignore)
+ self.branch = self.parent.branch
+ self.info = {'name': self.parent.name, 'type': self.parent.ovl_type}
+ self.missing_msg = 'Overlay "%(name)s" is missing "%(type)s" module!'\
+ % self.info
+ self.hint = 'Did you install layman with "%(type)s" support?'\
+ % self.info
+
+
+ def add(self, base):
+ '''Add overlay.'''
+ self.output.error(self.missing_msg)
+ self.output.warn(self.hint)
+ return True
+
+
+ def update(self, base, src):
+ '''
+ Updates overlay src-url.
+ '''
+ self.output.error(self.missing_msg)
+ self.output.warn(self.hint)
+ return True
+
+
+ def sync(self, base):
+ '''Sync overlay.'''
+ self.output.error(self.missing_msg)
+ self.output.warn(self.hint)
+ return True
+
+
+ def supported(self):
+ '''Overlay type supported?'''
+ return False
diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 8dd0b4b..ee2c279 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -107,8 +107,7 @@ class Overlay(object):
try:
_class = self.module_controller.get_class(_type)
except InvalidModuleName:
- raise Exception('Overlay from_xml(), "' + self.name + \
- '" Unknown overlay type "%s"!' % _type)
+ _class = self.module_controller.get_class('stub')
_location = encode(strip_text(source_elem))
@@ -219,8 +218,8 @@ class Overlay(object):
try:
_class = self.module_controller.get_class(_type)
except InvalidModuleName:
- raise Exception('Overlay from_dict(), "' + self.name +
- '" Unknown overlay type "%s"!' % _type)
+ _class = self.module_controller.get_class('stub')
+
_location = encode(_src)
if _sub:
self.branch = encode(_sub)