Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/layman:master commit in: layman/overlays/
Date: Wed, 27 Apr 2011 11:00:21
Message-Id: 0a82306f384ab032a30cce35513a7a4a7c194991.dol-sen@gentoo
1 commit: 0a82306f384ab032a30cce35513a7a4a7c194991
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Sat Feb 26 02:46:44 2011 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Sun Mar 27 02:39:13 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=0a82306f
7
8 replace more exception raising with error reporting and proper return values.
9 some long line cleanup.
10
11 ---
12 layman/overlays/bzr.py | 5 +++--
13 layman/overlays/cvs.py | 5 +++--
14 layman/overlays/darcs.py | 8 +++++---
15 layman/overlays/g_common.py | 15 ++++++++-------
16 layman/overlays/git.py | 8 +++++---
17 layman/overlays/mercurial.py | 5 +++--
18 layman/overlays/rsync.py | 13 ++++++++-----
19 layman/overlays/source.py | 23 ++++++++++-------------
20 layman/overlays/svn.py | 4 ++--
21 layman/overlays/tar.py | 7 +++++--
22 10 files changed, 52 insertions(+), 41 deletions(-)
23
24 diff --git a/layman/overlays/bzr.py b/layman/overlays/bzr.py
25 index 1c2c702..957f9e7 100644
26 --- a/layman/overlays/bzr.py
27 +++ b/layman/overlays/bzr.py
28 @@ -84,5 +84,6 @@ class BzrOverlay(OverlaySource):
29 def supported(self):
30 '''Overlay type supported?'''
31
32 - return require_supported([(self.command(), 'bzr',
33 - 'dev-vcs/bzr'),])
34 + return require_supported(
35 + [(self.command(), 'bzr', 'dev-vcs/bzr'),],
36 + self.output.error)
37
38 diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py
39 index 2e76aa5..69e0dd1 100644
40 --- a/layman/overlays/cvs.py
41 +++ b/layman/overlays/cvs.py
42 @@ -109,5 +109,6 @@ class CvsOverlay(OverlaySource):
43 def supported(self):
44 '''Overlay type supported?'''
45
46 - return require_supported([(self.command(), 'cvs',
47 - 'dev-vcs/cvs'),])
48 + return require_supported(
49 + [(self.command(), 'cvs', 'dev-vcs/cvs'),],
50 + self.output.error)
51
52 diff --git a/layman/overlays/darcs.py b/layman/overlays/darcs.py
53 index 566d6ba..14a415b 100644
54 --- a/layman/overlays/darcs.py
55 +++ b/layman/overlays/darcs.py
56 @@ -42,7 +42,8 @@ class DarcsOverlay(OverlaySource):
57
58 def __init__(self, parent, config, _location, ignore = 0, quiet = False):
59
60 - super(DarcsOverlay, self).__init__(parent, config, _location, ignore, quiet)
61 + super(DarcsOverlay, self).__init__(parent, config,
62 + _location, ignore, quiet)
63
64 def add(self, base, quiet = False):
65 '''Add overlay.'''
66 @@ -84,5 +85,6 @@ class DarcsOverlay(OverlaySource):
67 def supported(self):
68 '''Overlay type supported?'''
69
70 - return require_supported([(self.command(), 'darcs',
71 - 'dev-vcs/darcs'),])
72 + return require_supported(
73 + [(self.command(), 'darcs', 'dev-vcs/darcs'),],
74 + self.output.error)
75
76 diff --git a/layman/overlays/g_common.py b/layman/overlays/g_common.py
77 index 5be191d..fae11df 100644
78 --- a/layman/overlays/g_common.py
79 +++ b/layman/overlays/g_common.py
80 @@ -39,7 +39,8 @@ class GCommonOverlay(OverlaySource):
81 type_key = 'g-common'
82
83 def __init__(self, parent, config, _location, ignore = 0, quiet = False):
84 - super(GCommonOverlay, self).__init__(parent, config, _location, ignore, quiet)
85 + super(GCommonOverlay, self).__init__(parent, config,
86 + _location, ignore, quiet)
87 #split source into driver and remote uri.
88 self.driver=self.src[:self.src.find(' ')]
89 self.remote_uri=self.src[self.src.find(' ')+1:]
90 @@ -73,9 +74,9 @@ class GCommonOverlay(OverlaySource):
91 '''Overlay type supported?'''
92
93 return require_supported(
94 - [(self.command(),
95 - 'g-common',
96 - 'app-portage/g-common'),
97 - ('/usr/share/g-common/drivers/'+self.driver+'.cfg',
98 - 'g-common for '+self.driver,
99 - 'app-portage/g-'+self.driver),])
100 + [(self.command(),
101 + 'g-common',
102 + 'app-portage/g-common'),
103 + ('/usr/share/g-common/drivers/'+self.driver+'.cfg',
104 + 'g-common for '+self.driver,
105 + 'app-portage/g-'+self.driver),], self.output.error)
106
107 diff --git a/layman/overlays/git.py b/layman/overlays/git.py
108 index 0c0404f..d65a5d3 100644
109 --- a/layman/overlays/git.py
110 +++ b/layman/overlays/git.py
111 @@ -46,7 +46,8 @@ class GitOverlay(OverlaySource):
112 def add(self, base, quiet = False):
113 '''Add overlay.'''
114
115 - self.supported()
116 + if not self.supported():
117 + return False
118
119 def fix_git_source(source):
120 # http:// should get trailing slash, other protocols shouldn't
121 @@ -89,5 +90,6 @@ class GitOverlay(OverlaySource):
122 def supported(self):
123 '''Overlay type supported?'''
124
125 - return require_supported([(self.command(), 'git',
126 - 'dev-vcs/git'),])
127 + return require_supported(
128 + [(self.command(), 'git', 'dev-vcs/git'),],
129 + self.output.error)
130
131 diff --git a/layman/overlays/mercurial.py b/layman/overlays/mercurial.py
132 index 1d0cb92..748588b 100644
133 --- a/layman/overlays/mercurial.py
134 +++ b/layman/overlays/mercurial.py
135 @@ -85,5 +85,6 @@ class MercurialOverlay(OverlaySource):
136 def supported(self):
137 '''Overlay type supported?'''
138
139 - return require_supported([(self.command(), 'mercurial',
140 - 'dev-vcs/mercurial'),])
141 + return require_supported(
142 + [(self.command(), 'mercurial', 'dev-vcs/mercurial'),],
143 + self.output.error)
144
145 diff --git a/layman/overlays/rsync.py b/layman/overlays/rsync.py
146 index 1d6e831..76b289e 100644
147 --- a/layman/overlays/rsync.py
148 +++ b/layman/overlays/rsync.py
149 @@ -42,7 +42,8 @@ class RsyncOverlay(OverlaySource):
150
151 def __init__(self, parent, config, _location, ignore = 0, quiet = False):
152
153 - super(RsyncOverlay, self).__init__(parent, config, _location, ignore, quiet)
154 + super(RsyncOverlay, self).__init__(parent, config,
155 + _location, ignore, quiet)
156
157 def add(self, base, quiet = False):
158 '''Add overlay.'''
159 @@ -59,8 +60,9 @@ class RsyncOverlay(OverlaySource):
160 self.supported()
161
162 # rsync OPTIONS [-q] SOURCE TARGET
163 - args = ['-rlptDvz', '--progress', '--delete', '--delete-after', '--timeout=180',
164 - '--exclude=distfiles/*', '--exclude=local/*', '--exclude=packages/*']
165 + args = ['-rlptDvz', '--progress', '--delete', '--delete-after',
166 + '--timeout=180', '--exclude=distfiles/*', '--exclude=local/*',
167 + '--exclude=packages/*']
168
169 cfg_opts = self.config["rsync_syncopts"]
170 target = path([base, self.parent.name])
171 @@ -79,5 +81,6 @@ class RsyncOverlay(OverlaySource):
172 def supported(self):
173 '''Overlay type supported?'''
174
175 - return require_supported([(self.command(), 'rsync',
176 - 'net-misc/rsync'),])
177 + return require_supported(
178 + [(self.command(), 'rsync', 'net-misc/rsync'),],
179 + self.output.error)
180
181 diff --git a/layman/overlays/source.py b/layman/overlays/source.py
182 index be7b639..b88131f 100644
183 --- a/layman/overlays/source.py
184 +++ b/layman/overlays/source.py
185 @@ -21,10 +21,11 @@ import subprocess
186 from layman.utils import path
187
188
189 -def _resolve_command(command):
190 +def _resolve_command(command, error_output):
191 if os.path.isabs(command):
192 if not os.path.exists(command):
193 - raise Exception('Program "%s" not found' % command)
194 + error_output('Program "%s" not found' % command)
195 + return ('File', None)
196 return ('File', command)
197 else:
198 kind = 'Command'
199 @@ -33,18 +34,19 @@ def _resolve_command(command):
200 f = os.path.join(d, command)
201 if os.path.exists(f):
202 return ('Command', f)
203 - raise Exception('Cound not resolve command ' +\
204 + error_output('Cound not resolve command ' +\
205 '"%s" based on PATH "%s"' % (command, env_path))
206 + return ('Command', None)
207
208
209 -def require_supported(binaries):
210 +def require_supported(binaries, error_output):
211 for command, mtype, package in binaries:
212 - found = False
213 - kind, path = _resolve_command(command)
214 + kind, path = _resolve_command(command, error_output)
215 if not path:
216 - raise Exception(kind + ' ' + command + ' seems to be missing!'
217 + error_output(kind + ' ' + command + ' seems to be missing!'
218 ' Overlay type "' + mtype + '" not support'
219 'ed. Did you emerge ' + package + '?')
220 + return False
221 return True
222
223
224 @@ -104,12 +106,7 @@ class OverlaySource(object):
225
226 def is_supported(self):
227 '''Is the overlay type supported?'''
228 -
229 - try:
230 - self.supported()
231 - return True
232 - except:
233 - return False
234 + return self.supported()
235
236 def command(self):
237 return self.config['%s_command' % self.__class__.type_key]
238
239 diff --git a/layman/overlays/svn.py b/layman/overlays/svn.py
240 index 147a641..e0eb632 100644
241 --- a/layman/overlays/svn.py
242 +++ b/layman/overlays/svn.py
243 @@ -99,5 +99,5 @@ class SvnOverlay(OverlaySource):
244 '''Overlay type supported?'''
245
246 return require_supported(
247 - [(self.command(), 'svn','dev-vcs/subversion'),]
248 - )
249 + [(self.command(), 'svn','dev-vcs/subversion'),],
250 + self.output.error)
251
252 diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
253 index 5f1f606..9d59b71 100644
254 --- a/layman/overlays/tar.py
255 +++ b/layman/overlays/tar.py
256 @@ -75,7 +75,8 @@ class TarOverlay(OverlaySource):
257
258 def __init__(self, parent, config, _location, ignore = 0, quiet = False):
259
260 - super(TarOverlay, self).__init__(parent, config, _location, ignore, quiet)
261 + super(TarOverlay, self).__init__(parent,
262 + config, _location, ignore, quiet)
263
264 self.output = config['output']
265
266 @@ -199,7 +200,9 @@ class TarOverlay(OverlaySource):
267 def supported(self):
268 '''Overlay type supported?'''
269
270 - return require_supported([(self.command(), 'tar', 'app-arch/tar'), ])
271 + return require_supported(
272 + [(self.command(), 'tar', 'app-arch/tar'), ],
273 + self.output.error)
274
275 if __name__ == '__main__':
276 import doctest