1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/repository/prototype.py,v 1.2 2005/07/13 05:51:35 ferringb Exp $
from portage.util.dicts import IndexableSequence
from weakref import proxy
def ix_cat_callable(*cat):
return "/".join(cat)
class tree(object):
package_class = None
def __init__(self, frozen=True):
self.categories = IndexableSequence(self._get_categories, self._get_categories,
returnIterFunc=ix_cat_callable, returnEmpty=True, modifiable=(not frozen))
self.packages = IndexableSequence(self.categories.iterkeys, self._get_packages, \
returnIterFunc=lambda x,y: str(x)+"/"+str(y), modifiable=(not frozen))
self.versions = IndexableSequence(self.packages.__iter__, self._get_versions, \
returnIterFunc=lambda x,y: str(x)+"-"+str(y), modifiable=(not frozen))
self.raw_repo = proxy(self)
self.frozen = frozen
def _get_categories(self, *arg):
raise NotImplementedError
def _get_packages(self, category):
raise NotImplementedError
def _get_versions(self, package):
raise NotImplementedError
def __getitem__(self, cpv):
cpv_inst = self.package_class(cpv)
if cpv_inst.fullver not in self.versions[cpv_inst.key]:
del cpv_inst
raise KeyError(cpv)
return cpv_inst
def __setitem__(self, *values):
raise AttributeError
def __delitem__(self, cpv):
raise AttributeError
def __iter__(self):
for cpv in self.versions:
yield self.package_class(cpv)
return
def match(self, atom):
return list(self.itermatch(atom))
def itermatch(self, atom):
if atom.category == None:
candidates = self.packages
else:
if atom.package == None:
try: candidates = self.packages[atom.category]
except KeyError:
# just stop now. no category matches == no yielded cpvs.
return
else:
try:
if atom.package not in self.packages[atom.category]:
# no matches possible
return
candidates = [atom.key]
except KeyError:
# atom.category wasn't valid. no matches possible.
return
#actual matching.
for catpkg in candidates:
for ver in self.versions[catpkg]:
if atom.match(self.package_class(catpkg+"-"+ver)):
yield self[catpkg+"-"+ver]
return
def add_package(self, pkg):
if self.frozen:
raise AttributeError,"repo is frozen"
return self._add_new_package(self, pkg)
def _add_new_package(self, pkg):
raise NotImplementedError
def del_package(self, key):
if self.frozen:
raise AttributeError,"repo is frozen"
return self._del_package(self,key)
def _del_package(self,pkg):
raise NotImplementedError
|