commit:     f6ed5510885847653473190d59d32e8159a3f1c2
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 17 01:21:57 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Thu Jun 19 03:49:57 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=f6ed5510

Adds initial files for layman sync plugin

---
 layman/sync/__init__.py |  45 +++++++++++++++++++
 layman/sync/layman.py   | 116 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 161 insertions(+)

diff --git a/layman/sync/__init__.py b/layman/sync/__init__.py
new file mode 100644
index 0000000..303f996
--- /dev/null
+++ b/layman/sync/__init__.py
@@ -0,0 +1,45 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+'''Layman plug-in module for portage.
+Performs layman sync actions for layman overlays.
+'''
+
+import os
+
+from portage.sync.config_checks import CheckSyncConfig
+
+
+DEFAULT_CLASS = 'Layman'
+AVAILABLE_CLASSES = [ 'Layman',  'PyLayman']
+options = {'1': 'Layman', '2': 'PyLayman'}
+
+
+config_class = DEFAULT_CLASS
+try:
+    test_param = os.environ["TESTIT"]
+    if test_param in options:
+        config_class = options[test_param]
+except KeyError:
+    pass
+
+
+module_spec = {
+    'name': 'layman',
+    'description': __doc__,
+    'provides':{
+        'layman-module': {
+            'name': 'layman',
+            'class': config_class,
+            'description': __doc__,
+            'functions': ['sync', 'new', 'exists'],
+            'func_desc': {
+                'sync': 'Performs a layman sync of the specified overlay',
+                'new': 'Currently does nothing',
+                'exists': 'Returns a boolean of whether the specified dir ' +
+                    'exists and is a valid repository',
+            },
+            'validate_config': CheckSyncConfig,
+        },
+    }
+}

diff --git a/layman/sync/layman.py b/layman/sync/layman.py
new file mode 100644
index 0000000..7adf8c6
--- /dev/null
+++ b/layman/sync/layman.py
@@ -0,0 +1,116 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+'''Layman module for portage'''
+
+import logging
+
+from layman.api import LaymanAPI
+from layman.config import BareConfig, OptionConfig
+from layman.output import Message
+
+import portage
+from portage import os
+from portage.util import writemsg_level
+from portage.output import create_color_func
+good = create_color_func("GOOD")
+bad = create_color_func("BAD")
+warn = create_color_func("WARN")
+from portage.sync.syncbase import SyncBase
+
+import sys
+
+class Layman(SyncBase):
+    '''Layman sync class'''
+
+    short_desc = "Perform sync operations on webrsync based repositories"
+
+    @staticmethod
+    def name():
+        return "Layman"
+
+
+    def __init__(self):
+        SyncBase.__init__(self, 'layman', 'app-portage/layman')
+
+
+    def new(self, **kwargs):
+        '''Do the initial download and install of the repository'''
+        pass
+
+
+    def _sync(self):
+        ''' Update existing repository'''
+        emerge_config = self.options.get('emerge_config', None)
+        portdb = self.options.get('portdb', None)
+        args = []
+        msg = '>>> Starting layman sync for %s...' % self.repo.location
+        self.logger(self.xterm_titles, msg)
+        writemsg_level(msg + '\n')
+        args.append('layman -n')
+
+        if self.settings:
+            if self.settings.get('NOCOLOR'):
+                args.append('-N')
+            if self.settings.get('PORTAGE_QUIET'):
+                args.append('-q')
+
+        args.append('-s')
+        args.append(self.repo.name)
+        exitcode = portage.process.spawn_bash("%s" % \
+            (' '.join(args)),
+            **portage._native_kwargs(self.spawn_kwargs))
+        if exitcode != os.EX_OK:
+            msg = "!!! layman sync error in %s" % self.repo.name
+            self.logger(self.xterm_titles, msg)
+            writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
+            return (exitcode, False)
+        msg = ">>> layman sync succeeded: %s" % self.repo.name
+        self.logger(self.xterm_titles, msg)
+        writemsg_level(msg + "\n")
+
+        return (exitcode, True)
+
+
+class PyLayman(SyncBase):
+    '''Layman sync class'''
+
+    short_desc = "Perform sync operations on webrsync based repositories"
+
+    @staticmethod
+    def name():
+        return "Layman"
+
+    def __init__(self):
+
+        SyncBase.__init__(self, '', 'app-portage/layman')
+
+        config = BareConfig()
+        self.message = Message(out=sys.stdout, err=sys.stderr)
+        
+        options = {
+            'config': config.get_option('config'),
+            'quiet': portage.settings.get('PORTAGE_QUIET'),
+            'quietness': config.get_option('quietness'),
+            'output': self.message,
+            'nocolor': portage.settings.get('NOCOLOR'),
+            'root': portage.settings.get('EROOT'),
+            'verbose': portage.settings.get('PORTAGE_VERBOSE'),
+            'width': portage.settings.get('COLUMNWIDTH'),
+
+        }
+
+        self.config = OptionConfig(options=options)
+        
+        LaymanAPI.__init__(self, self.config,
+                             report_errors=True,
+                             output=self.config['output']
+                            )
+
+    def new(self, **kwargs):
+        '''Do the initial download and install of the repository'''
+        pass
+
+   
+    def _sync(self):
+        ''' Update existing repository'''
+        pass

Reply via email to