1 |
commit: 195ba334eec316454996d4e8552afaeb0de1dd4d |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jul 6 15:29:51 2011 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jul 6 15:29:51 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=195ba334 |
7 |
|
8 |
Get rid of structured tree, just use flat interface. |
9 |
|
10 |
--- |
11 |
gentoopm/basepm/pkg.py | 154 +++------------------------------------- |
12 |
gentoopm/basepm/repo.py | 19 +---- |
13 |
gentoopm/basepm/stack.py | 76 ++------------------ |
14 |
gentoopm/paludispm/pkg.py | 42 +---------- |
15 |
gentoopm/paludispm/repo.py | 31 +++----- |
16 |
gentoopm/pkgcorepm/pkg.py | 50 +------------ |
17 |
gentoopm/pkgcorepm/repo.py | 16 +---- |
18 |
gentoopm/portagepm/__init__.py | 2 +- |
19 |
gentoopm/portagepm/db.py | 64 +++++++---------- |
20 |
gentoopm/portagepm/pkg.py | 57 ++------------- |
21 |
gentoopm/portagepm/repo.py | 13 ++-- |
22 |
11 files changed, 81 insertions(+), 443 deletions(-) |
23 |
|
24 |
diff --git a/gentoopm/basepm/pkg.py b/gentoopm/basepm/pkg.py |
25 |
index 9b2a796..39514cd 100644 |
26 |
--- a/gentoopm/basepm/pkg.py |
27 |
+++ b/gentoopm/basepm/pkg.py |
28 |
@@ -3,58 +3,10 @@ |
29 |
# (c) 2011 Michał Górny <mgorny@g.o> |
30 |
# Released under the terms of the 2-clause BSD license. |
31 |
|
32 |
-import collections |
33 |
from abc import abstractmethod, abstractproperty |
34 |
|
35 |
from gentoopm.util import ABCObject |
36 |
|
37 |
-class PMKeyedPackageBase(ABCObject): |
38 |
- """ |
39 |
- Base class for key-identified package sets. |
40 |
- """ |
41 |
- |
42 |
- def __init__(self, key, parent): |
43 |
- self._key_ = key |
44 |
- self._parent_ = parent |
45 |
- |
46 |
- @property |
47 |
- def _parent(self): |
48 |
- """ |
49 |
- A parent (higher level) PMKeyedPackageDict or None if top-level. |
50 |
- """ |
51 |
- return self._parent_ |
52 |
- |
53 |
- @property |
54 |
- def _key(self): |
55 |
- """ |
56 |
- The key for this level of PMKeyedPackageDict. |
57 |
- """ |
58 |
- return self._key_ |
59 |
- |
60 |
- @abstractproperty |
61 |
- def _key_name(self): |
62 |
- """ |
63 |
- The metadata key name for this key. |
64 |
- """ |
65 |
- pass |
66 |
- |
67 |
- @property |
68 |
- def key(self): |
69 |
- """ |
70 |
- The set of keys uniquely identifying the package set (i.e. the parent |
71 |
- keys and this one). |
72 |
- """ |
73 |
- key_names = [] |
74 |
- keys = [] |
75 |
- o = self |
76 |
- while o and o._key is not None: |
77 |
- keys.insert(0, o._key) |
78 |
- key_names.insert(0, o._key_name) |
79 |
- o = o._parent |
80 |
- t = collections.namedtuple('%sKeyTuple' % self.__class__.__name__, |
81 |
- ' '.join(key_names)) |
82 |
- return t(*keys) |
83 |
- |
84 |
class PMPackageSet(ABCObject): |
85 |
@abstractmethod |
86 |
def __iter__(self): |
87 |
@@ -63,13 +15,6 @@ class PMPackageSet(ABCObject): |
88 |
""" |
89 |
pass |
90 |
|
91 |
- @property |
92 |
- def flattened(self): |
93 |
- """ |
94 |
- Flatten the package set and iterate over it. Yield PMPackages. |
95 |
- """ |
96 |
- return PMFlattenedPackageSet(iter(self)) |
97 |
- |
98 |
def filter(self, *args, **kwargs): |
99 |
""" |
100 |
Filter the packages based on keys passed as arguments. Positional |
101 |
@@ -89,32 +34,7 @@ class PMPackageSet(ABCObject): |
102 |
can provide a class with __eq__() redefined as an argument. |
103 |
""" |
104 |
|
105 |
- myargs = collections.defaultdict(lambda: None, enumerate(args)) |
106 |
- mykwargs = collections.defaultdict(lambda: None, **kwargs) |
107 |
- |
108 |
- i = 0 |
109 |
- try: |
110 |
- el = next(iter(self)) |
111 |
- except StopIteration: |
112 |
- return PMFilteredPackageSet((), None, None, None) |
113 |
- else: |
114 |
- k = el._key_name |
115 |
- if myargs[i] is not None: |
116 |
- if mykwargs[k] is not None: |
117 |
- raise TypeError('args[%d] and kwargs[%s] refer to the same key.' % \ |
118 |
- (i, k)) |
119 |
- m = myargs[i] |
120 |
- else: |
121 |
- m = mykwargs[k] |
122 |
- |
123 |
- newargs = args[1:] |
124 |
- newkwargs = kwargs.copy() |
125 |
- try: |
126 |
- del newkwargs[k] |
127 |
- except KeyError: |
128 |
- pass |
129 |
- |
130 |
- return PMFilteredPackageSet(iter(self), m, newargs, newkwargs) |
131 |
+ return PMFilteredPackageSet(iter(self), args, kwargs) |
132 |
|
133 |
@property |
134 |
def best(self): |
135 |
@@ -123,7 +43,7 @@ class PMPackageSet(ABCObject): |
136 |
the results and return the first one). |
137 |
""" |
138 |
try: |
139 |
- return sorted(self.flattened, reverse = True)[0] |
140 |
+ return sorted(self, reverse = True)[0] |
141 |
except IndexError: |
142 |
raise TypeError('.best called on an empty set') |
143 |
except TypeError: |
144 |
@@ -143,76 +63,23 @@ class PMPackageSet(ABCObject): |
145 |
raise ValueError('Ambiguous filter (matches more than a single package name).') |
146 |
|
147 |
class PMFilteredPackageSet(PMPackageSet): |
148 |
- def __init__(self, it, key, newargs, newkwargs): |
149 |
+ def __init__(self, it, args, kwargs): |
150 |
self._iter = it |
151 |
- self._key = key |
152 |
- self._newargs = newargs |
153 |
- self._newkwargs = newkwargs |
154 |
+ self._args = args |
155 |
+ self._kwargs = kwargs |
156 |
|
157 |
def __iter__(self): |
158 |
for el in self._iter: |
159 |
- if self._key is None or self._key == el._key: |
160 |
- if self._newargs or self._newkwargs: |
161 |
- for i in el.filter(*self._newargs, **self._newkwargs): |
162 |
- yield i |
163 |
- else: |
164 |
- yield el |
165 |
- |
166 |
-class PMFlattenedPackageSet(PMPackageSet): |
167 |
- def __init__(self, it): |
168 |
- self._iter = it |
169 |
- |
170 |
- def __iter__(self): |
171 |
- for i in self._iter: |
172 |
- if isinstance(i, PMKeyedPackageDict): |
173 |
- for hi in i.flattened: |
174 |
- yield hi |
175 |
- else: |
176 |
- yield i |
177 |
- |
178 |
-class PMKeyedPackageDict(PMKeyedPackageBase, PMPackageSet): |
179 |
- """ |
180 |
- A dict-like object representing a set of packages matched by a N-level key. |
181 |
- If it's a last-level key, the dict evaluates to PMPackage subclass |
182 |
- instances. Otherwise, it evaluates to lower-level PMKeyedPackageDicts. |
183 |
+ for x in el.filter(*self._args, **self._kwargs): |
184 |
+ yield x |
185 |
|
186 |
- Usually, the highest level PMKeyedPackageDict is PMRepository. Then dicts |
187 |
- refer to the category, package name and finally version (where they |
188 |
- transform into PMPackages). |
189 |
- """ |
190 |
- |
191 |
- @abstractmethod |
192 |
- def __iter__(self): |
193 |
- """ |
194 |
- Iterate over child PMKeyedPackageDicts or PMPackages when bottom-level. |
195 |
- """ |
196 |
- pass |
197 |
- |
198 |
- def __getitem__(self, key): |
199 |
- """ |
200 |
- Get a sub-item matching the key. |
201 |
- """ |
202 |
- for i in self: |
203 |
- if i._key == key: |
204 |
- return i |
205 |
- else: |
206 |
- raise KeyError('No packages match keyset: (%s)' % \ |
207 |
- ', '.join(self.key + [key])) |
208 |
- |
209 |
-class PMPackage(PMKeyedPackageBase): |
210 |
+class PMPackage(ABCObject): |
211 |
""" |
212 |
An abstract class representing a single, uniquely-keyed package |
213 |
in the package tree. |
214 |
""" |
215 |
|
216 |
- @property |
217 |
- def flattened(self): |
218 |
- """ |
219 |
- A convenience property. Returns the package itself, as an iterator. |
220 |
- """ |
221 |
- yield self |
222 |
- |
223 |
- def filter(self, *args, **kwargs): |
224 |
+ def filter(self, **kwargs): |
225 |
""" |
226 |
Filter packages on metadata. This is mostly to extend superclass |
227 |
.filter() method. |
228 |
@@ -222,9 +89,6 @@ class PMPackage(PMKeyedPackageBase): |
229 |
returns an iterator -- either over the package itself or an empty one. |
230 |
""" |
231 |
|
232 |
- if args: |
233 |
- raise IndexError('Unused positional arguments: %s' % args) |
234 |
- |
235 |
for k, m in kwargs.items(): |
236 |
try: |
237 |
v = self.metadata[k] |
238 |
|
239 |
diff --git a/gentoopm/basepm/repo.py b/gentoopm/basepm/repo.py |
240 |
index 80ea4b7..5b1bac0 100644 |
241 |
--- a/gentoopm/basepm/repo.py |
242 |
+++ b/gentoopm/basepm/repo.py |
243 |
@@ -6,9 +6,10 @@ |
244 |
import os.path |
245 |
from abc import abstractmethod, abstractproperty |
246 |
|
247 |
-from gentoopm.basepm.pkg import PMKeyedPackageDict |
248 |
+from gentoopm.basepm.pkg import PMPackageSet |
249 |
+from gentoopm.util import ABCObject |
250 |
|
251 |
-class PMRepositoryDict(PMKeyedPackageDict): |
252 |
+class PMRepositoryDict(ABCObject): |
253 |
""" |
254 |
A dict-like object providing access to a set of repositories. |
255 |
|
256 |
@@ -17,10 +18,6 @@ class PMRepositoryDict(PMKeyedPackageDict): |
257 |
subclass. |
258 |
""" |
259 |
|
260 |
- _key = None |
261 |
- _key_name = None |
262 |
- _parent = None |
263 |
- |
264 |
def __getitem__(self, key): |
265 |
""" |
266 |
Get the repository by its name or path. If using a path as a key, |
267 |
@@ -48,23 +45,15 @@ class PMRepositoryDict(PMKeyedPackageDict): |
268 |
""" |
269 |
pass |
270 |
|
271 |
-class PMRepository(PMKeyedPackageDict): |
272 |
+class PMRepository(PMPackageSet): |
273 |
""" |
274 |
Base abstract class for a single repository. |
275 |
""" |
276 |
- _key_name = None |
277 |
- _parent = None |
278 |
- _key = None |
279 |
|
280 |
class PMEbuildRepository(PMRepository): |
281 |
""" |
282 |
Base abstract class for an ebuild repository (on livefs). |
283 |
""" |
284 |
- _key_name = 'REPOSITORY' |
285 |
- |
286 |
- @property |
287 |
- def _key(self): |
288 |
- return self.name |
289 |
|
290 |
@abstractproperty |
291 |
def name(self): |
292 |
|
293 |
diff --git a/gentoopm/basepm/stack.py b/gentoopm/basepm/stack.py |
294 |
index 4febc07..ab13dd3 100644 |
295 |
--- a/gentoopm/basepm/stack.py |
296 |
+++ b/gentoopm/basepm/stack.py |
297 |
@@ -3,77 +3,13 @@ |
298 |
# (c) 2011 Michał Górny <mgorny@g.o> |
299 |
# Released under the terms of the 2-clause BSD license. |
300 |
|
301 |
-import collections |
302 |
- |
303 |
-from gentoopm.basepm.pkg import PMKeyedPackageDict, PMPackage |
304 |
from gentoopm.basepm.repo import PMRepository |
305 |
|
306 |
-class PMPackageWrapper(PMPackage): |
307 |
- _key_name = 'REPOSITORY' |
308 |
- |
309 |
- def __init__(self, wrapped, parent): |
310 |
- self._wrapped = wrapped |
311 |
- self._parent_ = parent |
312 |
- |
313 |
- @property |
314 |
- def metadata(self): |
315 |
- return self._wrapped.metadata |
316 |
- |
317 |
- @property |
318 |
- def _key(self): |
319 |
- return self._repo._key |
320 |
- |
321 |
- @property |
322 |
- def _repo(self): |
323 |
- p = self._wrapped._parent |
324 |
- while p._key_name != 'REPOSITORY': |
325 |
- p = p._parent |
326 |
- return p |
327 |
- |
328 |
- @property |
329 |
- def path(self): |
330 |
- return self._wrapped.path |
331 |
- |
332 |
- def __cmp__(self, other): |
333 |
- r = cmp(self._wrapped, other._wrapped) |
334 |
- if r == 0: |
335 |
- return cmp(self._repo, other._repo) |
336 |
- return r |
337 |
- |
338 |
-class PMStackWrapper(PMKeyedPackageDict): |
339 |
- def __init__(self, wrapped, parent): |
340 |
- self._wrapped = wrapped |
341 |
- self._parent_ = parent |
342 |
+class PMRepoStackWrapper(PMRepository): |
343 |
+ def __init__(self, repos): |
344 |
+ self._repos = repos |
345 |
|
346 |
def __iter__(self): |
347 |
- keys = collections.defaultdict(list) |
348 |
- for r in self._wrapped: |
349 |
- if isinstance(r, PMPackage): |
350 |
- yield PMPackageWrapper(r, self) |
351 |
- else: |
352 |
- for wr in r: |
353 |
- keys[wr._key].append(wr) |
354 |
- for k, l in keys.items(): |
355 |
- yield PMStackWrapper(l, self) |
356 |
- |
357 |
- @property |
358 |
- def _key(self): |
359 |
- try: |
360 |
- return self._wrapped[0]._key |
361 |
- except IndexError: |
362 |
- return None |
363 |
- |
364 |
- @property |
365 |
- def _key_name(self): |
366 |
- try: |
367 |
- return self._wrapped[0]._key_name |
368 |
- except IndexError: |
369 |
- return None |
370 |
- |
371 |
-class PMRepoStackWrapper(PMStackWrapper, PMRepository): |
372 |
- _key_name = None |
373 |
- _key = None |
374 |
- _parent = None |
375 |
- |
376 |
- def __init__(self, repos): |
377 |
- self._wrapped = repos |
378 |
+ for r in self._repos: |
379 |
+ for p in r: |
380 |
+ yield p |
381 |
|
382 |
diff --git a/gentoopm/paludispm/pkg.py b/gentoopm/paludispm/pkg.py |
383 |
index e83816f..c816f96 100644 |
384 |
--- a/gentoopm/paludispm/pkg.py |
385 |
+++ b/gentoopm/paludispm/pkg.py |
386 |
@@ -6,49 +6,11 @@ |
387 |
import paludis |
388 |
|
389 |
from gentoopm.basepm.metadata import PMPackageMetadata |
390 |
-from gentoopm.basepm.pkg import PMKeyedPackageDict, PMPackage |
391 |
-from gentoopm.util import IterDictWrapper |
392 |
- |
393 |
-class PaludisCategory(PMKeyedPackageDict): |
394 |
- _key_name = 'CATEGORY' |
395 |
- def __init__(self, category, parent): |
396 |
- PMKeyedPackageDict.__init__(self, str(category), parent) |
397 |
- |
398 |
- def __iter__(self): |
399 |
- repo = self._parent |
400 |
- for p in repo._repo.package_names(self._key, []): |
401 |
- yield PaludisPackage(p, self) |
402 |
- |
403 |
- @property |
404 |
- def packages(self): |
405 |
- """ |
406 |
- A convenience wrapper for the package list. |
407 |
- """ |
408 |
- return IterDictWrapper(self) |
409 |
- |
410 |
-class PaludisPackage(PMKeyedPackageDict): |
411 |
- _key_name = 'PN' |
412 |
- def __init__(self, qpn, parent): |
413 |
- PMKeyedPackageDict.__init__(self, str(qpn.package), parent) |
414 |
- self._qpn = qpn |
415 |
- |
416 |
- def __iter__(self): |
417 |
- repo = self._parent._parent |
418 |
- for p in repo._repo.package_ids(self._qpn, []): |
419 |
- yield PaludisID(p, self) |
420 |
- |
421 |
- @property |
422 |
- def versions(self): |
423 |
- """ |
424 |
- A convenience wrapper for the version list. |
425 |
- """ |
426 |
- return IterDictWrapper(self) |
427 |
+from gentoopm.basepm.pkg import PMPackage |
428 |
|
429 |
class PaludisID(PMPackage): |
430 |
- _key_name = 'PVR' |
431 |
- def __init__(self, pkg, parent): |
432 |
+ def __init__(self, pkg): |
433 |
self._pkg = pkg |
434 |
- PMPackage.__init__(self, str(pkg.version), parent) |
435 |
|
436 |
@property |
437 |
def metadata(self): |
438 |
|
439 |
diff --git a/gentoopm/paludispm/repo.py b/gentoopm/paludispm/repo.py |
440 |
index d29e2ac..71214de 100644 |
441 |
--- a/gentoopm/paludispm/repo.py |
442 |
+++ b/gentoopm/paludispm/repo.py |
443 |
@@ -3,42 +3,32 @@ |
444 |
# (c) 2011 Michał Górny <mgorny@g.o> |
445 |
# Released under the terms of the 2-clause BSD license. |
446 |
|
447 |
-import collections, os.path |
448 |
+import paludis |
449 |
|
450 |
from gentoopm.basepm.repo import PMRepository, PMRepositoryDict, \ |
451 |
PMEbuildRepository |
452 |
-from gentoopm.paludispm.pkg import PaludisCategory |
453 |
-from gentoopm.util import IterDictWrapper |
454 |
+from gentoopm.paludispm.pkg import PaludisID |
455 |
|
456 |
class PaludisRepoDict(PMRepositoryDict): |
457 |
def __iter__(self): |
458 |
for r in self._env.repositories: |
459 |
if r.format_key().parse_value() == 'e': |
460 |
- yield PaludisLivefsRepository(r) |
461 |
+ yield PaludisLivefsRepository(r, self._env) |
462 |
|
463 |
def __init__(self, env): |
464 |
self._env = env |
465 |
|
466 |
class PaludisRepository(PMRepository): |
467 |
def __iter__(self): |
468 |
- for c in self._repo.category_names([]): |
469 |
- pc = PaludisCategory(c, self) |
470 |
- try: |
471 |
- next(iter(pc)) |
472 |
- except StopIteration: # omit empty categories |
473 |
- pass |
474 |
- else: |
475 |
- yield pc |
476 |
- |
477 |
- @property |
478 |
- def categories(self): |
479 |
- """ |
480 |
- A convenience wrapper for the category list. |
481 |
- """ |
482 |
- return IterDictWrapper(self) |
483 |
+ for p in self._env[paludis.Selection.AllVersionsSorted( |
484 |
+ paludis.FilteredGenerator( |
485 |
+ paludis.Generator.InRepository(self._repo.name), |
486 |
+ paludis.Filter.All()))]: |
487 |
+ yield PaludisID(p) |
488 |
|
489 |
class PaludisLivefsRepository(PaludisRepository, PMEbuildRepository): |
490 |
- def __init__(self, repo_obj): |
491 |
+ def __init__(self, repo_obj, env): |
492 |
+ self._env = env |
493 |
self._repo = repo_obj |
494 |
|
495 |
@property |
496 |
@@ -51,6 +41,7 @@ class PaludisLivefsRepository(PaludisRepository, PMEbuildRepository): |
497 |
|
498 |
class PaludisInstalledRepo(PaludisRepository): |
499 |
def __init__(self, env): |
500 |
+ self._env = env |
501 |
for r in env.repositories: |
502 |
if str(r.name) == 'installed': # XXX |
503 |
self._repo = r |
504 |
|
505 |
diff --git a/gentoopm/pkgcorepm/pkg.py b/gentoopm/pkgcorepm/pkg.py |
506 |
index 30e6bae..559a229 100644 |
507 |
--- a/gentoopm/pkgcorepm/pkg.py |
508 |
+++ b/gentoopm/pkgcorepm/pkg.py |
509 |
@@ -3,54 +3,12 @@ |
510 |
# (c) 2011 Michał Górny <mgorny@g.o> |
511 |
# Released under the terms of the 2-clause BSD license. |
512 |
|
513 |
-from pkgcore.restrictions.packages import PackageRestriction, AndRestriction |
514 |
-from pkgcore.restrictions.values import StrExactMatch |
515 |
- |
516 |
from gentoopm.basepm.metadata import PMPackageMetadata |
517 |
-from gentoopm.basepm.pkg import PMKeyedPackageDict, PMPackage |
518 |
-from gentoopm.util import IterDictWrapper |
519 |
- |
520 |
-class PkgCoreCategory(PMKeyedPackageDict): |
521 |
- _key_name = 'CATEGORY' |
522 |
- def __iter__(self): |
523 |
- repo = self._parent |
524 |
- try: |
525 |
- for p in repo._repo.packages[self._key]: |
526 |
- yield PkgCorePackage(p, self) |
527 |
- except KeyError: |
528 |
- pass |
529 |
+from gentoopm.basepm.pkg import PMPackage |
530 |
|
531 |
- @property |
532 |
- def packages(self): |
533 |
- """ |
534 |
- A convenience wrapper for the package list. |
535 |
- """ |
536 |
- return IterDictWrapper(self) |
537 |
- |
538 |
-class PkgCorePackage(PMKeyedPackageDict): |
539 |
- _key_name = 'PN' |
540 |
- def __iter__(self): |
541 |
- r = AndRestriction( |
542 |
- PackageRestriction("category", StrExactMatch(self._parent._key)), |
543 |
- PackageRestriction("package", StrExactMatch(self._key)) |
544 |
- ) |
545 |
- |
546 |
- repo = self._parent._parent |
547 |
- for p in repo._repo.itermatch(r): |
548 |
- yield PkgCoreEbuild(p, self) |
549 |
- |
550 |
- @property |
551 |
- def versions(self): |
552 |
- """ |
553 |
- A convenience wrapper for the version list. |
554 |
- """ |
555 |
- return IterDictWrapper(self) |
556 |
- |
557 |
-class PkgCoreEbuild(PMPackage): |
558 |
- _key_name = 'PVR' |
559 |
- def __init__(self, pkg, parent): |
560 |
+class PkgCorePackage(PMPackage): |
561 |
+ def __init__(self, pkg): |
562 |
self._pkg = pkg |
563 |
- PMPackage.__init__(self, pkg.fullver, parent) |
564 |
|
565 |
@property |
566 |
def metadata(self): |
567 |
@@ -61,7 +19,7 @@ class PkgCoreEbuild(PMPackage): |
568 |
return self._pkg.path |
569 |
|
570 |
def __cmp__(self, other): |
571 |
- if not isinstance(other, PkgCoreEbuild): |
572 |
+ if not isinstance(other, PkgCorePackage): |
573 |
raise TypeError('Unable to compare %s against %s' % \ |
574 |
self, other) |
575 |
if self._pkg.key != other._pkg.key: |
576 |
|
577 |
diff --git a/gentoopm/pkgcorepm/repo.py b/gentoopm/pkgcorepm/repo.py |
578 |
index 7a432a7..b0f0593 100644 |
579 |
--- a/gentoopm/pkgcorepm/repo.py |
580 |
+++ b/gentoopm/pkgcorepm/repo.py |
581 |
@@ -3,12 +3,9 @@ |
582 |
# (c) 2011 Michał Górny <mgorny@g.o> |
583 |
# Released under the terms of the 2-clause BSD license. |
584 |
|
585 |
-import os.path |
586 |
- |
587 |
from gentoopm.basepm.repo import PMRepository, PMRepositoryDict, \ |
588 |
PMEbuildRepository |
589 |
-from gentoopm.pkgcorepm.pkg import PkgCoreCategory |
590 |
-from gentoopm.util import IterDictWrapper |
591 |
+from gentoopm.pkgcorepm.pkg import PkgCorePackage |
592 |
|
593 |
class PkgCoreRepoDict(PMRepositoryDict): |
594 |
def __iter__(self): |
595 |
@@ -23,15 +20,8 @@ class PkgCoreRepository(PMRepository): |
596 |
self._repo = repo_obj |
597 |
|
598 |
def __iter__(self): |
599 |
- for c in self._repo.categories: |
600 |
- yield PkgCoreCategory(c, self) |
601 |
- |
602 |
- @property |
603 |
- def categories(self): |
604 |
- """ |
605 |
- A convenience wrapper for the category list. |
606 |
- """ |
607 |
- return IterDictWrapper(self) |
608 |
+ for pkg in self._repo: |
609 |
+ yield PkgCorePackage(pkg) |
610 |
|
611 |
class PkgCoreEbuildRepo(PkgCoreRepository, PMEbuildRepository): |
612 |
def __init__(self, repo_obj, index): |
613 |
|
614 |
diff --git a/gentoopm/portagepm/__init__.py b/gentoopm/portagepm/__init__.py |
615 |
index 60ffa1c..15a9bec 100644 |
616 |
--- a/gentoopm/portagepm/__init__.py |
617 |
+++ b/gentoopm/portagepm/__init__.py |
618 |
@@ -8,7 +8,7 @@ from portage import create_trees |
619 |
|
620 |
from gentoopm.basepm import PackageManager |
621 |
from gentoopm.portagepm.repo import PortageRepoDict |
622 |
-from gentoopm.portagepm.db import VDBRepository, PortDBRepository |
623 |
+from gentoopm.portagepm.db import VDBRepository |
624 |
|
625 |
class PortagePM(PackageManager): |
626 |
name = 'portage' |
627 |
|
628 |
diff --git a/gentoopm/portagepm/db.py b/gentoopm/portagepm/db.py |
629 |
index ce7188f..3eae39a 100644 |
630 |
--- a/gentoopm/portagepm/db.py |
631 |
+++ b/gentoopm/portagepm/db.py |
632 |
@@ -3,32 +3,16 @@ |
633 |
# (c) 2011 Michał Górny <mgorny@g.o> |
634 |
# Released under the terms of the 2-clause BSD license. |
635 |
|
636 |
-import os.path |
637 |
import portage.versions |
638 |
|
639 |
from gentoopm.basepm.metadata import PMPackageMetadata |
640 |
-from gentoopm.basepm.pkg import PMKeyedPackageDict, PMPackage |
641 |
from gentoopm.basepm.repo import PMRepository |
642 |
-from gentoopm.portagepm.pkg import PortageCategory, PortagePackage, PortageCPV |
643 |
-from gentoopm.util import IterDictWrapper |
644 |
+from gentoopm.portagepm.pkg import PortageCPV |
645 |
|
646 |
-class PortageDBCategory(PortageCategory): |
647 |
- def __iter__(self): |
648 |
- for p in self._dbapi.cp_all(): |
649 |
- cat = portage.versions.catsplit(p)[0] |
650 |
- if cat == self._key: |
651 |
- yield PortageDBPackage(p, self, self._dbapi) |
652 |
- |
653 |
-class PortageDBPackage(PortagePackage): |
654 |
- def __iter__(self): |
655 |
- for p in self._dbapi.cp_list(self._qpn): |
656 |
- yield PortageDBCPV(p, self, self._dbapi) |
657 |
+# XXX: cleanup all this mess! |
658 |
|
659 |
class PortageDBCPV(PortageCPV): |
660 |
- _key_name = 'PVR' |
661 |
- def __init__(self, cpv, parent, dbapi): |
662 |
- version = portage.versions.cpv_getversion(cpv) |
663 |
- PMPackage.__init__(self, version, parent) |
664 |
+ def __init__(self, cpv, dbapi): |
665 |
self._cpv = cpv |
666 |
self._dbapi = dbapi |
667 |
|
668 |
@@ -46,30 +30,36 @@ class PortageDBMetadata(PMPackageMetadata): |
669 |
self._cpv = cpv |
670 |
self._dbapi = dbapi |
671 |
|
672 |
- def __getitem__(self, key): |
673 |
+ def __getattr__(self, key): |
674 |
return self._dbapi.aux_get(self._cpv, [key])[0] |
675 |
- |
676 |
+ |
677 |
+ @property |
678 |
+ def CATEGORY(self): |
679 |
+ return portage.versions.catsplit(self._cpv)[0] |
680 |
+ |
681 |
+ @property |
682 |
+ def PN(self): |
683 |
+ return portage.versions.catpkgsplit(self._cpv)[1] |
684 |
+ |
685 |
+ @property |
686 |
+ def PV(self): |
687 |
+ return portage.versions.pkgsplit(self._cpv)[1] |
688 |
+ |
689 |
+ @property |
690 |
+ def PR(self): |
691 |
+ return portage.versions.pkgsplit(self._cpv)[2] |
692 |
+ |
693 |
+ @property |
694 |
+ def PVR(self): |
695 |
+ return portage.versions.cpv_getversion(self._cpv) |
696 |
+ |
697 |
class PortDBRepository(PMRepository): |
698 |
def __init__(self, dbapi): |
699 |
self._dbapi = dbapi |
700 |
|
701 |
- _category_class = PortageDBCategory |
702 |
def __iter__(self): |
703 |
- for c in self._dbapi.categories: |
704 |
- pc = self._category_class(c, self, self._dbapi) |
705 |
- try: |
706 |
- next(iter(pc)) |
707 |
- except StopIteration: # omit empty categories |
708 |
- pass |
709 |
- else: |
710 |
- yield pc |
711 |
- |
712 |
- @property |
713 |
- def categories(self): |
714 |
- """ |
715 |
- A convenience wrapper for the category list. |
716 |
- """ |
717 |
- return IterDictWrapper(self) |
718 |
+ for p in self._dbapi.cpv_all(): # XXX |
719 |
+ yield PortageDBCPV(p, self._dbapi) |
720 |
|
721 |
class VDBRepository(PortDBRepository): |
722 |
pass |
723 |
|
724 |
diff --git a/gentoopm/portagepm/pkg.py b/gentoopm/portagepm/pkg.py |
725 |
index 8588208..8696706 100644 |
726 |
--- a/gentoopm/portagepm/pkg.py |
727 |
+++ b/gentoopm/portagepm/pkg.py |
728 |
@@ -6,68 +6,23 @@ |
729 |
import portage.versions |
730 |
|
731 |
from gentoopm.basepm.metadata import PMPackageMetadata |
732 |
-from gentoopm.basepm.pkg import PMKeyedPackageDict, PMPackage |
733 |
-from gentoopm.util import IterDictWrapper |
734 |
+from gentoopm.basepm.pkg import PMPackage |
735 |
|
736 |
-class PortageCategory(PMKeyedPackageDict): |
737 |
- _key_name = 'CATEGORY' |
738 |
- def __init__(self, category, parent, dbapi): |
739 |
- PMKeyedPackageDict.__init__(self, category, parent) |
740 |
- self._dbapi = dbapi |
741 |
- |
742 |
- def __iter__(self): |
743 |
- repo = self._parent.path |
744 |
- |
745 |
- for p in self._dbapi.cp_all(categories=(self._key,), trees=(repo,)): |
746 |
- yield PortagePackage(p, self, self._dbapi) |
747 |
- |
748 |
- @property |
749 |
- def packages(self): |
750 |
- """ |
751 |
- A convenience wrapper for the package list. |
752 |
- """ |
753 |
- return IterDictWrapper(self) |
754 |
- |
755 |
-class PortagePackage(PMKeyedPackageDict): |
756 |
- _key_name = 'PN' |
757 |
- def __init__(self, qpn, parent, dbapi): |
758 |
- pn = portage.versions.catsplit(qpn)[1] |
759 |
- PMKeyedPackageDict.__init__(self, pn, parent) |
760 |
- self._qpn = qpn |
761 |
- self._dbapi = dbapi |
762 |
- |
763 |
- def __iter__(self): |
764 |
- repo = self._parent._parent.path |
765 |
- |
766 |
- for p in self._dbapi.cp_list(self._qpn, mytree=repo): |
767 |
- yield PortageCPV(p, self, self._dbapi) |
768 |
- |
769 |
- @property |
770 |
- def versions(self): |
771 |
- """ |
772 |
- A convenience wrapper for the version list. |
773 |
- """ |
774 |
- return IterDictWrapper(self) |
775 |
+# XXX: cleanup all this mess! |
776 |
|
777 |
class PortageCPV(PMPackage): |
778 |
- _key_name = 'PVR' |
779 |
- def __init__(self, cpv, parent, dbapi): |
780 |
- version = portage.versions.cpv_getversion(cpv) |
781 |
- PMPackage.__init__(self, version, parent) |
782 |
+ def __init__(self, cpv, dbapi, tree): |
783 |
self._cpv = cpv |
784 |
self._dbapi = dbapi |
785 |
- |
786 |
- @property |
787 |
- def _repo_path(self): |
788 |
- return self._parent._parent._parent.path |
789 |
+ self._tree = tree |
790 |
|
791 |
@property |
792 |
def metadata(self): |
793 |
- return PortageMetadata(self._cpv, self._dbapi, self._repo_path) |
794 |
+ return PortageMetadata(self._cpv, self._dbapi, self._tree) |
795 |
|
796 |
@property |
797 |
def path(self): |
798 |
- return self._dbapi.findname(self._cpv, self._repo_path) |
799 |
+ return self._dbapi.findname(self._cpv, self._tree) |
800 |
|
801 |
def __cmp__(self, other): |
802 |
if not isinstance(other, PortageCPV): |
803 |
|
804 |
diff --git a/gentoopm/portagepm/repo.py b/gentoopm/portagepm/repo.py |
805 |
index 3041db0..8203f92 100644 |
806 |
--- a/gentoopm/portagepm/repo.py |
807 |
+++ b/gentoopm/portagepm/repo.py |
808 |
@@ -5,10 +5,9 @@ |
809 |
|
810 |
import os.path |
811 |
|
812 |
-from gentoopm.basepm.repo import PMRepository, PMRepositoryDict, PMEbuildRepository |
813 |
+from gentoopm.basepm.repo import PMRepositoryDict, PMEbuildRepository |
814 |
from gentoopm.portagepm.db import PortDBRepository |
815 |
-from gentoopm.portagepm.pkg import PortageCategory |
816 |
-from gentoopm.util import IterDictWrapper |
817 |
+from gentoopm.portagepm.pkg import PortageCPV |
818 |
|
819 |
class PortageRepoDict(PMRepositoryDict): |
820 |
def __iter__(self): |
821 |
@@ -35,6 +34,12 @@ class PortageRepository(PortDBRepository, PMEbuildRepository): |
822 |
self._repo = repo_obj |
823 |
PortDBRepository.__init__(self, portdbapi) |
824 |
|
825 |
+ def __iter__(self): |
826 |
+ path = self.path |
827 |
+ for cp in self._dbapi.cp_all(trees = (path,)): |
828 |
+ for p in self._dbapi.cp_list(cp, mytree = path): |
829 |
+ yield PortageCPV(p, self._dbapi, path) |
830 |
+ |
831 |
@property |
832 |
def name(self): |
833 |
return self._repo.name |
834 |
@@ -45,5 +50,3 @@ class PortageRepository(PortDBRepository, PMEbuildRepository): |
835 |
|
836 |
def __cmp__(self, other): |
837 |
return cmp(self._repo.priority, other._repo.priority) |
838 |
- |
839 |
- _category_class = PortageCategory |