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/overlays/
Date: Fri, 27 Jun 2014 04:08:32
Message-Id: 1403149797.5762ca4893af37816d09a39b7254a85381d7fcc2.twitch153@gentoo
1 commit: 5762ca4893af37816d09a39b7254a85381d7fcc2
2 Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jun 18 02:20:14 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=5762ca48
7
8 overlay.py: Improves dictionary checking logic
9
10 ---
11 layman/overlays/overlay.py | 73 ++++++++++++++++++++++++++++------------------
12 1 file changed, 44 insertions(+), 29 deletions(-)
13
14 diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
15 index 72c5d53..176f146 100755
16 --- a/layman/overlays/overlay.py
17 +++ b/layman/overlays/overlay.py
18 @@ -150,13 +150,21 @@ class Overlay(object):
19 del s
20
21 def create_overlay_source(source_elem):
22 + _branch = ''
23 _type = source_elem.attrib['type']
24 + if 'branch' in source_elem.attrib:
25 + _branch = source_elem.attrib['branch']
26 +
27 try:
28 _class = OVERLAY_TYPES[_type]
29 except KeyError:
30 raise Exception('Overlay from_xml(), "' + self.name + \
31 'Unknown overlay type "%s"!' % _type)
32 +
33 _location = encode(strip_text(source_elem))
34 +
35 + self.branch = _branch
36 +
37 return _class(parent=self, config=self.config,
38 _location=_location, ignore=ignore)
39
40 @@ -240,9 +248,9 @@ class Overlay(object):
41
42
43 def from_dict(self, overlay, ignore):
44 - """Process an xml overlay definition
45 + """Process an overlay dictionary definition
46 """
47 - self.output.debug("Overlay from_dict(); overlay" + str(overlay))
48 + self.output.debug("Overlay from_dict(); overlay" + str(overlay), 6)
49 _name = overlay['name']
50 if _name != None:
51 self.name = encode(_name)
52 @@ -264,19 +272,25 @@ class Overlay(object):
53 raise Exception('Overlay from_dict(), "' + self.name +
54 'Unknown overlay type "%s"!' % _type)
55 _location = encode(_src)
56 + if _sub:
57 + self.branch = encode(_sub)
58 + else:
59 + self.branch = None
60 +
61 return _class(parent=self, config=self.config,
62 _location=_location, ignore=ignore)
63
64 self.sources = [create_dict_overlay_source(e) for e in _sources]
65
66 - _owner = overlay['owner_name']
67 - if _owner == None:
68 - self.owner_name = None
69 - _email = None
70 - else:
71 + if 'owner_name' in overlay:
72 + _owner = overlay['owner_name']
73 self.owner_name = encode(_owner)
74 _email = overlay['owner_email']
75 - if _email != None:
76 + else:
77 + self.owner_name = None
78 +
79 + if 'owner_email' in overlay:
80 + _email = overlay['owner_email']
81 self.owner_email = encode(_email)
82 else:
83 self.owner_email = None
84 @@ -287,8 +301,8 @@ class Overlay(object):
85 self.output.warn('Overlay from_dict(), "' + self.name +
86 '" is missing an "owner.email" entry!', 4)
87
88 - _desc = overlay['description']
89 - if _desc != None:
90 + if 'description' in overlay:
91 + _desc = overlay['description']
92 d = WHITESPACE_REGEX.sub(' ', _desc)
93 self.description = encode(d)
94 del d
95 @@ -301,39 +315,39 @@ class Overlay(object):
96 self.output.warn('Overlay from_dict(), "' + self.name +
97 '" is missing a "description" entry!', 4)
98
99 - if overlay['status']:
100 + if 'status' in overlay:
101 self.status = encode(overlay['status'])
102 else:
103 self.status = None
104
105 self.quality = 'experimental'
106 - if len(overlay['quality']):
107 + if 'quality' in overlay:
108 if overlay['quality'] in set(QUALITY_LEVELS):
109 self.quality = encode(overlay['quality'])
110
111 - if overlay['priority']:
112 + if 'priority' in overlay:
113 self.priority = int(overlay['priority'])
114 else:
115 self.priority = 50
116
117 - h = overlay['homepage']
118 - if h != None:
119 - self.homepage = encode(h)
120 + if 'homepage' in overlay:
121 + self.homepage = encode(overlay['homepage'])
122 else:
123 self.homepage = None
124
125 - self.feeds = [encode(e) \
126 - for e in overlay['feeds']]
127 + if 'feed' in overlay:
128 + self.feeds = [encode(e) \
129 + for e in overlay['feeds']]
130 + else:
131 + self.feeds = None
132
133 - _irc = overlay['irc']
134 - if _irc != None:
135 - self.irc = encode(_irc)
136 + if 'irc' in overlay:
137 + self.irc = encode(overlay['irc'])
138 else:
139 self.irc = None
140
141 - _branch = overlay['branch']
142 - if _branch != None:
143 - self.branch = encode(_branch)
144 + if 'branch' in overlay:
145 + self.branch = encode(overlay['branch'])
146 else:
147 self.branch = None
148 #xml = self.to_xml()
149 @@ -405,11 +419,12 @@ class Overlay(object):
150 # NOTE: Two loops on purpose so the
151 # hooks are called with all sources in
152 i.to_xml_hook(repo)
153 - for i in self.feeds:
154 - feed = ET.Element('feed')
155 - feed.text = i
156 - repo.append(feed)
157 - del feed
158 + if self.feeds != None:
159 + for i in self.feeds:
160 + feed = ET.Element('feed')
161 + feed.text = i
162 + repo.append(feed)
163 + del feed
164 return repo