Gentoo Archives: gentoo-commits

From: Devan Franchini <twitch153@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/layman:gsoc2014 commit in: layman/sync/
Date: Fri, 27 Jun 2014 04:07:55
Message-Id: 1403149797.f6ed5510885847653473190d59d32e8159a3f1c2.twitch153@gentoo
1 commit: f6ed5510885847653473190d59d32e8159a3f1c2
2 Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jun 17 01:21:57 2014 +0000
4 Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
5 CommitDate: Thu Jun 19 03:49:57 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=f6ed5510
7
8 Adds initial files for layman sync plugin
9
10 ---
11 layman/sync/__init__.py | 45 +++++++++++++++++++
12 layman/sync/layman.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++++
13 2 files changed, 161 insertions(+)
14
15 diff --git a/layman/sync/__init__.py b/layman/sync/__init__.py
16 new file mode 100644
17 index 0000000..303f996
18 --- /dev/null
19 +++ b/layman/sync/__init__.py
20 @@ -0,0 +1,45 @@
21 +# Copyright 2014 Gentoo Foundation
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +'''Layman plug-in module for portage.
25 +Performs layman sync actions for layman overlays.
26 +'''
27 +
28 +import os
29 +
30 +from portage.sync.config_checks import CheckSyncConfig
31 +
32 +
33 +DEFAULT_CLASS = 'Layman'
34 +AVAILABLE_CLASSES = [ 'Layman', 'PyLayman']
35 +options = {'1': 'Layman', '2': 'PyLayman'}
36 +
37 +
38 +config_class = DEFAULT_CLASS
39 +try:
40 + test_param = os.environ["TESTIT"]
41 + if test_param in options:
42 + config_class = options[test_param]
43 +except KeyError:
44 + pass
45 +
46 +
47 +module_spec = {
48 + 'name': 'layman',
49 + 'description': __doc__,
50 + 'provides':{
51 + 'layman-module': {
52 + 'name': 'layman',
53 + 'class': config_class,
54 + 'description': __doc__,
55 + 'functions': ['sync', 'new', 'exists'],
56 + 'func_desc': {
57 + 'sync': 'Performs a layman sync of the specified overlay',
58 + 'new': 'Currently does nothing',
59 + 'exists': 'Returns a boolean of whether the specified dir ' +
60 + 'exists and is a valid repository',
61 + },
62 + 'validate_config': CheckSyncConfig,
63 + },
64 + }
65 +}
66
67 diff --git a/layman/sync/layman.py b/layman/sync/layman.py
68 new file mode 100644
69 index 0000000..7adf8c6
70 --- /dev/null
71 +++ b/layman/sync/layman.py
72 @@ -0,0 +1,116 @@
73 +# Copyright 2014 Gentoo Foundation
74 +# Distributed under the terms of the GNU General Public License v2
75 +'''Layman module for portage'''
76 +
77 +import logging
78 +
79 +from layman.api import LaymanAPI
80 +from layman.config import BareConfig, OptionConfig
81 +from layman.output import Message
82 +
83 +import portage
84 +from portage import os
85 +from portage.util import writemsg_level
86 +from portage.output import create_color_func
87 +good = create_color_func("GOOD")
88 +bad = create_color_func("BAD")
89 +warn = create_color_func("WARN")
90 +from portage.sync.syncbase import SyncBase
91 +
92 +import sys
93 +
94 +class Layman(SyncBase):
95 + '''Layman sync class'''
96 +
97 + short_desc = "Perform sync operations on webrsync based repositories"
98 +
99 + @staticmethod
100 + def name():
101 + return "Layman"
102 +
103 +
104 + def __init__(self):
105 + SyncBase.__init__(self, 'layman', 'app-portage/layman')
106 +
107 +
108 + def new(self, **kwargs):
109 + '''Do the initial download and install of the repository'''
110 + pass
111 +
112 +
113 + def _sync(self):
114 + ''' Update existing repository'''
115 + emerge_config = self.options.get('emerge_config', None)
116 + portdb = self.options.get('portdb', None)
117 + args = []
118 + msg = '>>> Starting layman sync for %s...' % self.repo.location
119 + self.logger(self.xterm_titles, msg)
120 + writemsg_level(msg + '\n')
121 + args.append('layman -n')
122 +
123 + if self.settings:
124 + if self.settings.get('NOCOLOR'):
125 + args.append('-N')
126 + if self.settings.get('PORTAGE_QUIET'):
127 + args.append('-q')
128 +
129 + args.append('-s')
130 + args.append(self.repo.name)
131 + exitcode = portage.process.spawn_bash("%s" % \
132 + (' '.join(args)),
133 + **portage._native_kwargs(self.spawn_kwargs))
134 + if exitcode != os.EX_OK:
135 + msg = "!!! layman sync error in %s" % self.repo.name
136 + self.logger(self.xterm_titles, msg)
137 + writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
138 + return (exitcode, False)
139 + msg = ">>> layman sync succeeded: %s" % self.repo.name
140 + self.logger(self.xterm_titles, msg)
141 + writemsg_level(msg + "\n")
142 +
143 + return (exitcode, True)
144 +
145 +
146 +class PyLayman(SyncBase):
147 + '''Layman sync class'''
148 +
149 + short_desc = "Perform sync operations on webrsync based repositories"
150 +
151 + @staticmethod
152 + def name():
153 + return "Layman"
154 +
155 + def __init__(self):
156 +
157 + SyncBase.__init__(self, '', 'app-portage/layman')
158 +
159 + config = BareConfig()
160 + self.message = Message(out=sys.stdout, err=sys.stderr)
161 +
162 + options = {
163 + 'config': config.get_option('config'),
164 + 'quiet': portage.settings.get('PORTAGE_QUIET'),
165 + 'quietness': config.get_option('quietness'),
166 + 'output': self.message,
167 + 'nocolor': portage.settings.get('NOCOLOR'),
168 + 'root': portage.settings.get('EROOT'),
169 + 'verbose': portage.settings.get('PORTAGE_VERBOSE'),
170 + 'width': portage.settings.get('COLUMNWIDTH'),
171 +
172 + }
173 +
174 + self.config = OptionConfig(options=options)
175 +
176 + LaymanAPI.__init__(self, self.config,
177 + report_errors=True,
178 + output=self.config['output']
179 + )
180 +
181 + def new(self, **kwargs):
182 + '''Do the initial download and install of the repository'''
183 + pass
184 +
185 +
186 + def _sync(self):
187 + ''' Update existing repository'''
188 + pass