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/
Date: Wed, 27 Apr 2011 10:59:55
Message-Id: 4c51f94ca343338c0d266fae5c5ab6500df5e258.dol-sen@gentoo
1 commit: 4c51f94ca343338c0d266fae5c5ab6500df5e258
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Thu Feb 24 06:10:33 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=4c51f94c
7
8 add 2 new functions, add_new & add_from_dict.
9 Modify the __init__ params a bit
10 whitespace additions between functions.
11
12 ---
13 layman/dbbase.py | 46 ++++++++++++++++++++++++++++++++++++++++++++--
14 1 files changed, 44 insertions(+), 2 deletions(-)
15
16 diff --git a/layman/dbbase.py b/layman/dbbase.py
17 index 5d082a0..53c2946 100644
18 --- a/layman/dbbase.py
19 +++ b/layman/dbbase.py
20 @@ -76,7 +76,9 @@ class BrokenOverlayCatalog(ValueError):
21 class DbBase:
22 ''' Handle a list of overlays.'''
23
24 - def __init__(self, paths, config, ignore = 0, quiet = False, ignore_init_read_errors=False):
25 + def __init__(self, config, paths=None, ignore = 0,
26 + quiet = False, ignore_init_read_errors=False
27 + ):
28
29 self.config = config
30 self.quiet = quiet
31 @@ -97,15 +99,18 @@ class DbBase:
32 except Exception, error:
33 if not ignore_init_read_errors: raise error
34
35 +
36 def __eq__(self, other):
37 for key in set(self.overlays.keys() + other.overlays.keys()):
38 if self.overlays[key] != other.overlays[key]:
39 return False
40 return True
41
42 +
43 def __ne__(self, other):
44 return not self.__eq__(other)
45
46 +
47 def read_file(self, path):
48 '''Read the overlay definition file.'''
49
50 @@ -118,11 +123,13 @@ class DbBase:
51
52 self.read(document, origin=path)
53
54 +
55 def _broken_catalog_hint(self):
56 this_function_name = sys._getframe().f_code.co_name
57 raise NotImplementedError('Method "%s.%s" not implemented' % \
58 (self.__class__.__name__, this_function_name))
59
60 +
61 def read(self, text, origin):
62 '''
63 Read an xml list of overlays (adding to and potentially overwriting existing entries)
64 @@ -147,11 +154,46 @@ class DbBase:
65 for overlay in overlays:
66 self.output.debug('Parsing overlay entry', 8)
67 try:
68 - ovl = Overlay(overlay, self.config, self.ignore, self.quiet)
69 + ovl = Overlay(config=self.config, xml=overlay,
70 + ignore=self.ignore, quiet=self.quiet)
71 + except Exception, error:
72 + raise error
73 + self.output.warn("DbBase(); Error creating overlay instance", 3)
74 + self.output.warn("Original error was: " + str(error), 3)
75 + else:
76 + self.overlays[ovl.name] = ovl
77 + return
78 +
79 +
80 + def add_new(self, xml=None, origin=None, from_dict=None):
81 + '''Reads xml text and dictionary definitions and adds
82 + them to the db.
83 + '''
84 + if xml:
85 + self.read(xml, origin)
86 + if from_dict:
87 + self.output.info("DbBase: add_new() from_dict")
88 + if isinstance(from_dict, dict):
89 + from_dict = [from_dict]
90 + self.add_from_dict(from_dict)
91 +
92 + return
93 +
94 +
95 + def add_from_dict(self, overlays=None):
96 + """Add a new overlay from a list of dictionary values
97 + """
98 + self.output.info("DbBase: add_from_dict()")
99 + for overlay in overlays:
100 + self.output.debug('Parsing overlay entry', 8)
101 + try:
102 + ovl = Overlay(self.config, ovl_dict=overlay,
103 + ignore=self.ignore, quiet=self.quiet)
104 except Exception, error:
105 self.output.warn(str(error), 3)
106 else:
107 self.overlays[ovl.name] = ovl
108 + return
109
110
111 def write(self, path):