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 10:59:46
Message-Id: ba5f0cd5c948bb7a65ab21008c940caf0fbe38e7.dol-sen@gentoo
1 commit: ba5f0cd5c948bb7a65ab21008c940caf0fbe38e7
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Thu Feb 24 05:58:49 2011 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Thu Feb 24 06:49:58 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=ba5f0cd5
7
8 removal of xml from the vcs class parameters.
9
10 ---
11 layman/overlays/bzr.py | 5 +-
12 layman/overlays/cvs.py | 11 +--
13 layman/overlays/darcs.py | 4 +-
14 layman/overlays/g_common.py | 4 +-
15 layman/overlays/git.py | 6 +-
16 layman/overlays/mercurial.py | 6 +-
17 layman/overlays/overlay.py | 177 +++++++++++++++++++++++++++++++++++-------
18 layman/overlays/rsync.py | 4 +-
19 layman/overlays/source.py | 3 +-
20 layman/overlays/svn.py | 4 +-
21 layman/overlays/tar.py | 12 +---
22 11 files changed, 171 insertions(+), 65 deletions(-)
23
24 diff --git a/layman/overlays/bzr.py b/layman/overlays/bzr.py
25 index 6f1b560..1c2c702 100644
26 --- a/layman/overlays/bzr.py
27 +++ b/layman/overlays/bzr.py
28 @@ -41,9 +41,10 @@ class BzrOverlay(OverlaySource):
29 type = 'Bzr'
30 type_key = 'bzr'
31
32 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
33 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
34
35 - super(BzrOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
36 + super(BzrOverlay, self).__init__(parent,
37 + config, _location, ignore, quiet)
38
39 def add(self, base, quiet = False):
40 '''Add overlay.'''
41
42 diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py
43 index 7d3f28f..2e76aa5 100644
44 --- a/layman/overlays/cvs.py
45 +++ b/layman/overlays/cvs.py
46 @@ -41,17 +41,10 @@ class CvsOverlay(OverlaySource):
47 type = 'cvs'
48 type_key = 'cvs'
49
50 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
51 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
52
53 - super(CvsOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
54 + super(CvsOverlay, self).__init__(parent, config, _location, ignore, quiet)
55
56 - _subpath = xml.find('subpath')
57 - if _subpath != None:
58 - self.subpath = ensure_unicode(_subpath.text.strip())
59 - elif 'subpath' in xml.attrib:
60 - self.subpath = ensure_unicode(xml.attrib['subpath'])
61 - else:
62 - self.subpath = ''
63
64 def __eq__(self, other):
65 res = super(CvsOverlay, self).__eq__(other) \
66
67 diff --git a/layman/overlays/darcs.py b/layman/overlays/darcs.py
68 index d393be7..566d6ba 100644
69 --- a/layman/overlays/darcs.py
70 +++ b/layman/overlays/darcs.py
71 @@ -40,9 +40,9 @@ class DarcsOverlay(OverlaySource):
72 type = 'Darcs'
73 type_key = 'darcs'
74
75 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
76 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
77
78 - super(DarcsOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
79 + super(DarcsOverlay, self).__init__(parent, config, _location, ignore, quiet)
80
81 def add(self, base, quiet = False):
82 '''Add overlay.'''
83
84 diff --git a/layman/overlays/g_common.py b/layman/overlays/g_common.py
85 index 5367c69..5be191d 100644
86 --- a/layman/overlays/g_common.py
87 +++ b/layman/overlays/g_common.py
88 @@ -38,8 +38,8 @@ class GCommonOverlay(OverlaySource):
89 type = 'g-common'
90 type_key = 'g-common'
91
92 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
93 - super(GCommonOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
94 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
95 + super(GCommonOverlay, self).__init__(parent, config, _location, ignore, quiet)
96 #split source into driver and remote uri.
97 self.driver=self.src[:self.src.find(' ')]
98 self.remote_uri=self.src[self.src.find(' ')+1:]
99
100 diff --git a/layman/overlays/git.py b/layman/overlays/git.py
101 index 23103f6..0c0404f 100644
102 --- a/layman/overlays/git.py
103 +++ b/layman/overlays/git.py
104 @@ -39,9 +39,9 @@ class GitOverlay(OverlaySource):
105 type = 'Git'
106 type_key = 'git'
107
108 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
109 -
110 - super(GitOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
111 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
112 + super(GitOverlay, self).__init__(parent, config,
113 + _location, ignore, quiet)
114
115 def add(self, base, quiet = False):
116 '''Add overlay.'''
117
118 diff --git a/layman/overlays/mercurial.py b/layman/overlays/mercurial.py
119 index df4f789..1d0cb92 100644
120 --- a/layman/overlays/mercurial.py
121 +++ b/layman/overlays/mercurial.py
122 @@ -40,9 +40,11 @@ class MercurialOverlay(OverlaySource):
123 type = 'Mercurial'
124 type_key = 'mercurial'
125
126 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
127 + def __init__(self, parent, config,
128 + _location, ignore = 0, quiet = False):
129
130 - super(MercurialOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
131 + super(MercurialOverlay, self).__init__(parent,
132 + config, _location, ignore, quiet)
133
134 def add(self, base, quiet = False):
135 '''Add overlay.'''
136
137 diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
138 index 3f8c3b8..aada4a2 100644
139 --- a/layman/overlays/overlay.py
140 +++ b/layman/overlays/overlay.py
141 @@ -1,8 +1,8 @@
142 #!/usr/bin/python
143 # -*- coding: utf-8 -*-
144 -#################################################################################
145 +################################################################################
146 # LAYMAN OVERLAY BASE CLASS
147 -#################################################################################
148 +################################################################################
149 # File: overlay.py
150 #
151 # Base class for the different overlay types.
152 @@ -20,7 +20,7 @@
153 #
154 ''' Basic overlay class.'''
155
156 -__version__ = "$Id: overlay.py 273 2006-12-30 15:54:50Z wrobel $"
157 +__version__ = "0.2"
158
159 #===============================================================================
160 #
161 @@ -35,7 +35,6 @@ import xml.etree.ElementTree as ET # Python 2.5
162
163 from layman.utils import (pad, terminal_width, get_encoding, encoder,
164 ensure_unicode)
165 -#from layman.debug import OUT
166
167 from layman.overlays.bzr import BzrOverlay
168 from layman.overlays.darcs import DarcsOverlay
169 @@ -69,20 +68,17 @@ QUALITY_LEVELS = 'core|stable|testing|experimental|graveyard'.split('|')
170
171 WHITESPACE_REGEX = re.compile('\s+')
172
173 -#===============================================================================
174 -#
175 -# Class Overlay
176 -#
177 -#-------------------------------------------------------------------------------
178
179 class Overlay(object):
180 ''' Derive the real implementations from this.'''
181
182 - def __init__(self, xml, config, ignore = 0, quiet = False):
183 + def __init__(self, config, xml=None, ovl_dict=None,
184 + ignore = 0, quiet = False
185 + ):
186 '''
187 >>> here = os.path.dirname(os.path.realpath(__file__))
188 >>> import xml.etree.ElementTree as ET # Python 2.5
189 - >>> document = ET.parse(here + '/../tests/testfiles/global-overlays.xml')
190 + >>> document =ET.parse(here + '/../tests/testfiles/global-overlays.xml')
191 >>> overlays = document.findall('overlay') + document.findall('repo')
192 >>> a = Overlay(overlays[0], dict())
193 >>> a.name
194 @@ -101,10 +97,19 @@ class Overlay(object):
195 >>> b.is_official()
196 False
197 '''
198 -
199 + self.config = config
200 self.output = config['output']
201 self._encoding_ = get_encoding(self.output)
202
203 + if xml:
204 + self.from_xml(xml, ignore, quiet)
205 + elif ovl_dict:
206 + self.from_dict(ovl_dict, ignore, quiet)
207 +
208 +
209 + def from_xml(self, xml, ignore, quiet):
210 + """Process an xml overlay definition
211 + """
212 def strip_text(node):
213 res = node.text
214 if res is None:
215 @@ -128,10 +133,6 @@ class Overlay(object):
216 _sources = [s]
217 del s
218
219 - if not _sources:
220 - raise Exception('Overlay "' + self.name + '" is missing a "source" entry!')
221 -
222 -
223 def create_overlay_source(source_elem):
224 _type = source_elem.attrib['type']
225 try:
226 @@ -139,10 +140,22 @@ class Overlay(object):
227 except KeyError:
228 raise Exception('Unknown overlay type "%s"!' % _type)
229 _location = ensure_unicode(strip_text(source_elem))
230 - return _class(self, xml, config, _location, ignore, quiet)
231 + return _class(parent=self, config=self.config,
232 + _location=_location, ignore=ignore, quiet=quiet)
233 +
234 + if not _sources:
235 + raise Exception('Overlay "' + self.name + \
236 + '" is missing a "source" entry!')
237
238 self.sources = [create_overlay_source(e) for e in _sources]
239
240 + _subpath = xml.find('subpath')
241 + if _subpath != None:
242 + self.subpath = ensure_unicode(_subpath.text.strip())
243 + elif 'subpath' in xml.attrib:
244 + self.subpath = ensure_unicode(xml.attrib['subpath'])
245 + else:
246 + self.subpath = ''
247
248 _owner = xml.find('owner')
249 if _owner == None:
250 @@ -169,7 +182,6 @@ class Overlay(object):
251 self.output.warn('Overlay "' + self.name + '" is missing a '
252 '"owner.email" entry!', 4)
253
254 -
255 _desc = xml.find('description')
256 if _desc != None:
257 d = WHITESPACE_REGEX.sub(' ', strip_text(_desc))
258 @@ -208,7 +220,8 @@ class Overlay(object):
259 else:
260 self.homepage = None
261
262 - self.feeds = [ensure_unicode(strip_text(e)) for e in xml.findall('feed')]
263 + self.feeds = [ensure_unicode(strip_text(e)) \
264 + for e in xml.findall('feed')]
265
266 _irc = xml.find('irc')
267 if _irc != None:
268 @@ -217,6 +230,100 @@ class Overlay(object):
269 self.irc = None
270
271
272 + def from_dict(self, overlay, ignore, quiet):
273 + """Process an xml overlay definition
274 + """
275 + print "overlay", overlay
276 + _name = overlay['name']
277 + if _name != None:
278 + self.name = ensure_unicode(_name)
279 + else:
280 + raise Exception('Overlay is missing a "name" entry!')
281 +
282 + _sources = overlay['sources']
283 +
284 + if not _sources:
285 + raise Exception('Overlay "' + self.name +
286 + '" is missing a "source" entry!')
287 +
288 + def create_dict_overlay_source(source_):
289 + _src, _type, _sub = source_
290 + try:
291 + _class = OVERLAY_TYPES[_type]
292 + except KeyError:
293 + raise Exception('Unknown overlay type "%s"!' % _type)
294 + _location = ensure_unicode(_src)
295 + return _class(parent=self, config=self.config,
296 + _location=_location, ignore=ignore, quiet=quiet)
297 +
298 + self.sources = [create_dict_overlay_source(e) for e in _sources]
299 +
300 + _owner = overlay['owner_name']
301 + if _owner == None:
302 + self.owner_name = None
303 + _email = None
304 + else:
305 + self.owner_name = ensure_unicode(_owner)
306 + _email = overlay['owner_email']
307 + if _email != None:
308 + self.owner_email = ensure_unicode(_email)
309 + else:
310 + self.owner_email = None
311 + if not ignore:
312 + raise Exception('Overlay "' + self.name + '" is missing a '
313 + '"owner.email" entry!')
314 + elif ignore == 1:
315 + self.output.warn('Overlay "' + self.name + '" is missing a '
316 + '"owner.email" entry!', 4)
317 +
318 + _desc = overlay['description']
319 + if _desc != None:
320 + d = WHITESPACE_REGEX.sub(' ', _desc)
321 + self.description = ensure_unicode(d)
322 + del d
323 + else:
324 + self.description = ''
325 + if not ignore:
326 + raise Exception('Overlay "' + self.name + '" is missing a '
327 + '"description" entry!')
328 + elif ignore == 1:
329 + self.output.warn('Overlay "' + self.name + '" is missing a '
330 + '"description" entry!', 4)
331 +
332 + if overlay['status']:
333 + self.status = ensure_unicode(overlay['status'])
334 + else:
335 + self.status = None
336 +
337 + self.quality = u'experimental'
338 + if overlay['quality']:
339 + if overlay['quality'] in set(QUALITY_LEVELS):
340 + self.quality = ensure_unicode(overlay['quality'])
341 +
342 + if overlay['priority']:
343 + self.priority = int(overlay['priority'])
344 + else:
345 + self.priority = 50
346 +
347 + h = overlay['homepage']
348 + if h != None:
349 + self.homepage = ensure_unicode(h)
350 + else:
351 + self.homepage = None
352 +
353 + self.feeds = [ensure_unicode(e) \
354 + for e in overlay['feeds']]
355 +
356 + _irc = overlay['irc']
357 + if _irc != None:
358 + self.irc = ensure_unicode(_irc)
359 + else:
360 + self.irc = None
361 +
362 + #xml = self.to_xml()
363 + # end of from_dict
364 +
365 +
366 def __eq__(self, other):
367 for i in ('description', 'homepage', 'name', 'owner_email',
368 'owner_name', 'priority', 'status'):
369 @@ -229,17 +336,18 @@ class Overlay(object):
370 return False
371 return True
372
373 +
374 def __ne__(self, other):
375 return not self.__eq__(other)
376
377 +
378 def set_priority(self, priority):
379 '''Set the priority of this overlay.'''
380 -
381 self.priority = int(priority)
382
383 +
384 def to_xml(self):
385 '''Convert to xml.'''
386 -
387 repo = ET.Element('repo')
388 if self.status != None:
389 repo.attrib['status'] = self.status
390 @@ -284,6 +392,7 @@ class Overlay(object):
391 del feed
392 return repo
393
394 +
395 def add(self, base, quiet = False):
396 res = 1
397 first_s = True
398 @@ -301,19 +410,22 @@ class Overlay(object):
399 first_s = False
400 return res
401
402 +
403 def sync(self, base, quiet = False):
404 assert len(self.sources) == 1
405 return self.sources[0].sync(base, quiet)
406
407 +
408 def delete(self, base):
409 assert len(self.sources) == 1
410 return self.sources[0].delete(base)
411
412 +
413 def get_infostr(self):
414 '''
415 >>> here = os.path.dirname(os.path.realpath(__file__))
416 >>> import xml.etree.ElementTree as ET # Python 2.5
417 - >>> document = ET.parse(here + '/../tests/testfiles/global-overlays.xml')
418 + >>> document =ET.parse(here + '/../tests/testfiles/global-overlays.xml')
419 >>> overlays = document.findall('overlay') + document.findall('repo')
420 >>> a = Overlay(overlays[0], dict())
421 >>> print str(a)
422 @@ -342,13 +454,15 @@ class Overlay(object):
423 result += '\n'
424
425 if self.owner_name != None:
426 - result += u'\nContact : %s <%s>' % (self.owner_name, self.owner_email)
427 + result += u'\nContact : %s <%s>' \
428 + % (self.owner_name, self.owner_email)
429 else:
430 result += u'\nContact : ' + self.owner_email
431 if len(self.sources) == 1:
432 result += u'\nType : ' + self.sources[0].type
433 else:
434 - result += u'\nType : ' + '/'.join(sorted(set(e.type for e in self.sources)))
435 + result += u'\nType : ' + '/'.join(
436 + sorted(set(e.type for e in self.sources)))
437 result += u'; Priority: ' + str(self.priority) + u'\n'
438 result += u'Quality : ' + self.quality + u'\n'
439
440 @@ -379,17 +493,17 @@ class Overlay(object):
441
442 return encoder(result, self._encoding_)
443
444 +
445 def short_list(self, width = 0):
446 '''
447 >>> here = os.path.dirname(os.path.realpath(__file__))
448 >>> import xml.etree.ElementTree as ET # Python 2.5
449 - >>> document = ET.parse(here + '/../tests/testfiles/global-overlays.xml')
450 + >>> document =ET.parse(here + '/../tests/testfiles/global-overlays.xml')
451 >>> overlays = document.findall('repo') + document.findall('overlay')
452 >>> a = Overlay(overlays[0], dict())
453 >>> print a.short_list(80)
454 - wrobel [Subversion] (https://o.g.o/svn/dev/wrobel )
455 + wrobel [Subversion] (https://o.g.o/svn/dev/wrobel )
456 '''
457 -
458 name = pad(self.name, 25)
459
460 if len(set(e.type for e in self.sources)) == 1:
461 @@ -408,28 +522,31 @@ class Overlay(object):
462
463 return encoder(name + mtype + source, self._encoding_)
464
465 +
466 def is_official(self):
467 '''Is the overlay official?'''
468 -
469 return self.status == 'official'
470
471 +
472 def is_supported(self):
473 return any(e.is_supported() for e in self.sources)
474
475 +
476 def source_uris(self):
477 for i in self.sources:
478 yield i.src
479
480 +
481 def source_types(self):
482 for i in self.sources:
483 yield i.type
484
485
486 -#================================================================================
487 +#==============================================================================
488 #
489 # Testing
490 #
491 -#--------------------------------------------------------------------------------
492 +#------------------------------------------------------------------------------
493
494 if __name__ == '__main__':
495 import doctest
496
497 diff --git a/layman/overlays/rsync.py b/layman/overlays/rsync.py
498 index 84836dd..1d6e831 100644
499 --- a/layman/overlays/rsync.py
500 +++ b/layman/overlays/rsync.py
501 @@ -40,9 +40,9 @@ class RsyncOverlay(OverlaySource):
502 type_key = 'rsync'
503
504
505 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
506 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
507
508 - super(RsyncOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
509 + super(RsyncOverlay, self).__init__(parent, config, _location, ignore, quiet)
510
511 def add(self, base, quiet = False):
512 '''Add overlay.'''
513
514 diff --git a/layman/overlays/source.py b/layman/overlays/source.py
515 index b0bc9a3..586ec6c 100644
516 --- a/layman/overlays/source.py
517 +++ b/layman/overlays/source.py
518 @@ -53,13 +53,14 @@ class OverlaySource(object):
519
520 type_key = None
521
522 - def __init__(self, parent, xml, config, _location,
523 + def __init__(self, parent, config, _location,
524 ignore = 0, quiet = False):
525 self.parent = parent
526 self.src = _location
527 self.config = config
528 self.ignore = ignore
529 self.quiet = quiet
530 +
531 self.output = config['output']
532
533 def __eq__(self, other):
534
535 diff --git a/layman/overlays/svn.py b/layman/overlays/svn.py
536 index c237ea4..147a641 100644
537 --- a/layman/overlays/svn.py
538 +++ b/layman/overlays/svn.py
539 @@ -39,11 +39,11 @@ class SvnOverlay(OverlaySource):
540 type = 'Subversion'
541 type_key = 'svn'
542
543 - def __init__(self, parent, xml, config, _location,
544 + def __init__(self, parent, config, _location,
545 ignore = 0, quiet = False):
546
547 super(SvnOverlay, self).__init__(
548 - parent, xml,config, _location, ignore, quiet)
549 + parent, config, _location, ignore, quiet)
550
551 def add(self, base, quiet = False):
552 '''Add overlay.'''
553
554 diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
555 index 09ed979..5f1f606 100644
556 --- a/layman/overlays/tar.py
557 +++ b/layman/overlays/tar.py
558 @@ -73,17 +73,9 @@ class TarOverlay(OverlaySource):
559 type = 'Tar'
560 type_key = 'tar'
561
562 - def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
563 + def __init__(self, parent, config, _location, ignore = 0, quiet = False):
564
565 - super(TarOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
566 -
567 - _subpath = xml.find('subpath')
568 - if _subpath != None:
569 - self.subpath = ensure_unicode(_subpath.text.strip())
570 - elif 'subpath' in xml.attrib:
571 - self.subpath = ensure_unicode(xml.attrib['subpath'])
572 - else:
573 - self.subpath = ''
574 + super(TarOverlay, self).__init__(parent, config, _location, ignore, quiet)
575
576 self.output = config['output']