Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/resolver/, pym/_emerge/, pym/portage/, pym/portage/dbapi/, ...
Date: Wed, 04 Mar 2015 21:37:57
Message-Id: 1425504727.34055adae6bd90fc64f18421e2cec5f8da6f7c33.zmedico@gentoo
1 commit: 34055adae6bd90fc64f18421e2cec5f8da6f7c33
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Tue Feb 17 22:56:47 2015 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed Mar 4 21:32:07 2015 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=34055ada
7
8 binpkg-multi-instance 1 of 7
9
10 Extend the _pkg_str class with build_id, build_time, file_size, and
11 mtime attributes. These will be used to distinguish binary package
12 instances that have the same cpv. Package sorting accounts for
13 build_time, which will be used to prefer newer builds over older builds
14 when their versions are identical.
15
16 pym/_emerge/Package.py | 51 +++++++++++++++++++++----------
17 pym/_emerge/resolver/output.py | 21 ++++++++++---
18 pym/portage/cache/index/pkg_desc_index.py | 1 +
19 pym/portage/dbapi/__init__.py | 10 ++++--
20 pym/portage/dbapi/vartree.py | 8 +++--
21 pym/portage/versions.py | 28 +++++++++++++++--
22 6 files changed, 93 insertions(+), 26 deletions(-)
23
24 diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
25 index e8a13cb..975335d 100644
26 --- a/pym/_emerge/Package.py
27 +++ b/pym/_emerge/Package.py
28 @@ -41,12 +41,12 @@ class Package(Task):
29 "_validated_atoms", "_visible")
30
31 metadata_keys = [
32 - "BUILD_TIME", "CHOST", "COUNTER", "DEPEND", "EAPI",
33 - "HDEPEND", "INHERITED", "IUSE", "KEYWORDS",
34 - "LICENSE", "PDEPEND", "PROVIDE", "RDEPEND",
35 - "repository", "PROPERTIES", "RESTRICT", "SLOT", "USE",
36 - "_mtime_", "DEFINED_PHASES", "REQUIRED_USE", "PROVIDES",
37 - "REQUIRES"]
38 + "BUILD_ID", "BUILD_TIME", "CHOST", "COUNTER", "DEFINED_PHASES",
39 + "DEPEND", "EAPI", "HDEPEND", "INHERITED", "IUSE", "KEYWORDS",
40 + "LICENSE", "MD5", "PDEPEND", "PROVIDE", "PROVIDES",
41 + "RDEPEND", "repository", "REQUIRED_USE",
42 + "PROPERTIES", "REQUIRES", "RESTRICT", "SIZE",
43 + "SLOT", "USE", "_mtime_"]
44
45 _dep_keys = ('DEPEND', 'HDEPEND', 'PDEPEND', 'RDEPEND')
46 _buildtime_keys = ('DEPEND', 'HDEPEND')
47 @@ -114,13 +114,14 @@ class Package(Task):
48 return self._metadata["EAPI"]
49
50 @property
51 + def build_id(self):
52 + return self.cpv.build_id
53 +
54 + @property
55 def build_time(self):
56 if not self.built:
57 raise AttributeError('build_time')
58 - try:
59 - return long(self._metadata['BUILD_TIME'])
60 - except (KeyError, ValueError):
61 - return 0
62 + return self.cpv.build_time
63
64 @property
65 def defined_phases(self):
66 @@ -509,9 +510,15 @@ class Package(Task):
67 else:
68 cpv_color = "PKG_NOMERGE"
69
70 + build_id_str = ""
71 + if isinstance(self.cpv.build_id, long) and self.cpv.build_id > 0:
72 + build_id_str = "-%s" % self.cpv.build_id
73 +
74 s = "(%s, %s" \
75 - % (portage.output.colorize(cpv_color, self.cpv + _slot_separator + \
76 - self.slot + "/" + self.sub_slot + _repo_separator + self.repo) , self.type_name)
77 + % (portage.output.colorize(cpv_color, self.cpv +
78 + build_id_str + _slot_separator + self.slot + "/" +
79 + self.sub_slot + _repo_separator + self.repo),
80 + self.type_name)
81
82 if self.type_name == "installed":
83 if self.root_config.settings['ROOT'] != "/":
84 @@ -755,29 +762,41 @@ class Package(Task):
85 def __lt__(self, other):
86 if other.cp != self.cp:
87 return self.cp < other.cp
88 - if portage.vercmp(self.version, other.version) < 0:
89 + result = portage.vercmp(self.version, other.version)
90 + if result < 0:
91 return True
92 + if result == 0 and self.built and other.built:
93 + return self.build_time < other.build_time
94 return False
95
96 def __le__(self, other):
97 if other.cp != self.cp:
98 return self.cp <= other.cp
99 - if portage.vercmp(self.version, other.version) <= 0:
100 + result = portage.vercmp(self.version, other.version)
101 + if result <= 0:
102 return True
103 + if result == 0 and self.built and other.built:
104 + return self.build_time <= other.build_time
105 return False
106
107 def __gt__(self, other):
108 if other.cp != self.cp:
109 return self.cp > other.cp
110 - if portage.vercmp(self.version, other.version) > 0:
111 + result = portage.vercmp(self.version, other.version)
112 + if result > 0:
113 return True
114 + if result == 0 and self.built and other.built:
115 + return self.build_time > other.build_time
116 return False
117
118 def __ge__(self, other):
119 if other.cp != self.cp:
120 return self.cp >= other.cp
121 - if portage.vercmp(self.version, other.version) >= 0:
122 + result = portage.vercmp(self.version, other.version)
123 + if result >= 0:
124 return True
125 + if result == 0 and self.built and other.built:
126 + return self.build_time >= other.build_time
127 return False
128
129 def with_use(self, use):
130
131 diff --git a/pym/_emerge/resolver/output.py b/pym/_emerge/resolver/output.py
132 index 7df0302..400617d 100644
133 --- a/pym/_emerge/resolver/output.py
134 +++ b/pym/_emerge/resolver/output.py
135 @@ -424,6 +424,18 @@ class Display(object):
136 pkg_str += _repo_separator + pkg.repo
137 return pkg_str
138
139 + def _append_build_id(self, pkg_str, pkg, pkg_info):
140 + """Potentially appends repository to package string.
141 +
142 + @param pkg_str: string
143 + @param pkg: _emerge.Package.Package instance
144 + @param pkg_info: dictionary
145 + @rtype string
146 + """
147 + if pkg.type_name == "binary" and pkg.cpv.build_id is not None:
148 + pkg_str += "-%s" % pkg.cpv.build_id
149 + return pkg_str
150 +
151 def _set_non_root_columns(self, pkg, pkg_info):
152 """sets the indent level and formats the output
153
154 @@ -431,7 +443,7 @@ class Display(object):
155 @param pkg_info: dictionary
156 @rtype string
157 """
158 - ver_str = pkg_info.ver
159 + ver_str = self._append_build_id(pkg_info.ver, pkg, pkg_info)
160 if self.conf.verbosity == 3:
161 ver_str = self._append_slot(ver_str, pkg, pkg_info)
162 ver_str = self._append_repository(ver_str, pkg, pkg_info)
163 @@ -470,7 +482,7 @@ class Display(object):
164 @rtype string
165 Modifies self.verboseadd
166 """
167 - ver_str = pkg_info.ver
168 + ver_str = self._append_build_id(pkg_info.ver, pkg, pkg_info)
169 if self.conf.verbosity == 3:
170 ver_str = self._append_slot(ver_str, pkg, pkg_info)
171 ver_str = self._append_repository(ver_str, pkg, pkg_info)
172 @@ -507,7 +519,7 @@ class Display(object):
173 @param pkg_info: dictionary
174 @rtype the updated addl
175 """
176 - pkg_str = pkg.cpv
177 + pkg_str = self._append_build_id(pkg.cpv, pkg, pkg_info)
178 if self.conf.verbosity == 3:
179 pkg_str = self._append_slot(pkg_str, pkg, pkg_info)
180 pkg_str = self._append_repository(pkg_str, pkg, pkg_info)
181 @@ -868,7 +880,8 @@ class Display(object):
182 if self.conf.columns:
183 myprint = self._set_non_root_columns(pkg, pkg_info)
184 else:
185 - pkg_str = pkg.cpv
186 + pkg_str = self._append_build_id(
187 + pkg.cpv, pkg, pkg_info)
188 if self.conf.verbosity == 3:
189 pkg_str = self._append_slot(pkg_str, pkg, pkg_info)
190 pkg_str = self._append_repository(pkg_str, pkg, pkg_info)
191
192 diff --git a/pym/portage/cache/index/pkg_desc_index.py b/pym/portage/cache/index/pkg_desc_index.py
193 index a2e45da..dbcbb83 100644
194 --- a/pym/portage/cache/index/pkg_desc_index.py
195 +++ b/pym/portage/cache/index/pkg_desc_index.py
196 @@ -26,6 +26,7 @@ class pkg_node(_unicode):
197 self.__dict__['cp'] = cp
198 self.__dict__['repo'] = repo
199 self.__dict__['version'] = version
200 + self.__dict__['build_time'] = None
201
202 def __new__(cls, cp, version, repo=None):
203 return _unicode.__new__(cls, cp + "-" + version)
204
205 diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
206 index 34dfaa7..044faec 100644
207 --- a/pym/portage/dbapi/__init__.py
208 +++ b/pym/portage/dbapi/__init__.py
209 @@ -31,7 +31,8 @@ class dbapi(object):
210 _use_mutable = False
211 _known_keys = frozenset(x for x in auxdbkeys
212 if not x.startswith("UNUSED_0"))
213 - _pkg_str_aux_keys = ("EAPI", "KEYWORDS", "SLOT", "repository")
214 + _pkg_str_aux_keys = ("BUILD_TIME", "EAPI", "BUILD_ID",
215 + "KEYWORDS", "SLOT", "repository")
216
217 def __init__(self):
218 pass
219 @@ -57,7 +58,12 @@ class dbapi(object):
220
221 @staticmethod
222 def _cmp_cpv(cpv1, cpv2):
223 - return vercmp(cpv1.version, cpv2.version)
224 + result = vercmp(cpv1.version, cpv2.version)
225 + if (result == 0 and cpv1.build_time is not None and
226 + cpv2.build_time is not None):
227 + result = ((cpv1.build_time > cpv2.build_time) -
228 + (cpv1.build_time < cpv2.build_time))
229 + return result
230
231 @staticmethod
232 def _cpv_sort_ascending(cpv_list):
233
234 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
235 index cf31c8e..277c2f1 100644
236 --- a/pym/portage/dbapi/vartree.py
237 +++ b/pym/portage/dbapi/vartree.py
238 @@ -173,7 +173,8 @@ class vardbapi(dbapi):
239 self.vartree = vartree
240 self._aux_cache_keys = set(
241 ["BUILD_TIME", "CHOST", "COUNTER", "DEPEND", "DESCRIPTION",
242 - "EAPI", "HDEPEND", "HOMEPAGE", "IUSE", "KEYWORDS",
243 + "EAPI", "HDEPEND", "HOMEPAGE",
244 + "BUILD_ID", "IUSE", "KEYWORDS",
245 "LICENSE", "PDEPEND", "PROPERTIES", "PROVIDE", "RDEPEND",
246 "repository", "RESTRICT" , "SLOT", "USE", "DEFINED_PHASES",
247 "PROVIDES", "REQUIRES"
248 @@ -425,7 +426,10 @@ class vardbapi(dbapi):
249 continue
250 if len(mysplit) > 1:
251 if ps[0] == mysplit[1]:
252 - returnme.append(_pkg_str(mysplit[0]+"/"+x))
253 + cpv = "%s/%s" % (mysplit[0], x)
254 + metadata = dict(zip(self._aux_cache_keys,
255 + self.aux_get(cpv, self._aux_cache_keys)))
256 + returnme.append(_pkg_str(cpv, metadata=metadata))
257 self._cpv_sort_ascending(returnme)
258 if use_cache:
259 self.cpcache[mycp] = [mystat, returnme[:]]
260
261 diff --git a/pym/portage/versions.py b/pym/portage/versions.py
262 index 2c9fe5b..1ca9a36 100644
263 --- a/pym/portage/versions.py
264 +++ b/pym/portage/versions.py
265 @@ -18,6 +18,7 @@ if sys.hexversion < 0x3000000:
266 _unicode = unicode
267 else:
268 _unicode = str
269 + long = int
270
271 import portage
272 portage.proxy.lazyimport.lazyimport(globals(),
273 @@ -361,11 +362,13 @@ class _pkg_str(_unicode):
274 """
275
276 def __new__(cls, cpv, metadata=None, settings=None, eapi=None,
277 - repo=None, slot=None):
278 + repo=None, slot=None, build_time=None, build_id=None,
279 + file_size=None, mtime=None):
280 return _unicode.__new__(cls, cpv)
281
282 def __init__(self, cpv, metadata=None, settings=None, eapi=None,
283 - repo=None, slot=None):
284 + repo=None, slot=None, build_time=None, build_id=None,
285 + file_size=None, mtime=None):
286 if not isinstance(cpv, _unicode):
287 # Avoid TypeError from _unicode.__init__ with PyPy.
288 cpv = _unicode_decode(cpv)
289 @@ -375,10 +378,19 @@ class _pkg_str(_unicode):
290 slot = metadata.get('SLOT', slot)
291 repo = metadata.get('repository', repo)
292 eapi = metadata.get('EAPI', eapi)
293 + build_time = metadata.get('BUILD_TIME', build_time)
294 + file_size = metadata.get('SIZE', file_size)
295 + build_id = metadata.get('BUILD_ID', build_id)
296 + mtime = metadata.get('_mtime_', mtime)
297 if settings is not None:
298 self.__dict__['_settings'] = settings
299 if eapi is not None:
300 self.__dict__['eapi'] = eapi
301 +
302 + self.__dict__['build_time'] = self._long(build_time, 0)
303 + self.__dict__['file_size'] = self._long(file_size, None)
304 + self.__dict__['build_id'] = self._long(build_id, None)
305 + self.__dict__['mtime'] = self._long(mtime, None)
306 self.__dict__['cpv_split'] = catpkgsplit(cpv, eapi=eapi)
307 if self.cpv_split is None:
308 raise InvalidData(cpv)
309 @@ -419,6 +431,18 @@ class _pkg_str(_unicode):
310 raise AttributeError("_pkg_str instances are immutable",
311 self.__class__, name, value)
312
313 + @staticmethod
314 + def _long(var, default):
315 + if var is not None:
316 + try:
317 + var = long(var)
318 + except ValueError:
319 + if var:
320 + var = -1
321 + else:
322 + var = default
323 + return var
324 +
325 @property
326 def stable(self):
327 try: