1 |
commit: e21be5ccba638ae1588d181db23f0e8380a5836d |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jul 26 07:12:30 2011 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jul 26 07:12:30 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=e21be5cc |
7 |
|
8 |
Support removing conditionals from depsets. |
9 |
|
10 |
--- |
11 |
gentoopm/basepm/depend.py | 49 ++++++++++++++++++++++++++++++++++++++++++++- |
12 |
1 files changed, 48 insertions(+), 1 deletions(-) |
13 |
|
14 |
diff --git a/gentoopm/basepm/depend.py b/gentoopm/basepm/depend.py |
15 |
index 78e5c02..e504594 100644 |
16 |
--- a/gentoopm/basepm/depend.py |
17 |
+++ b/gentoopm/basepm/depend.py |
18 |
@@ -21,11 +21,46 @@ class PMBaseDep(ABCObject): |
19 |
""" |
20 |
pass |
21 |
|
22 |
+ @abstractproperty |
23 |
+ def without_conditionals(self): |
24 |
+ """ |
25 |
+ Return the depspec with all conditionals resolved. |
26 |
+ |
27 |
+ @type: L{PMUncondDep} |
28 |
+ """ |
29 |
+ pass |
30 |
+ |
31 |
+class PMUncondDep(PMBaseDep): |
32 |
+ def __init__(self, parent): |
33 |
+ self._parent = parent |
34 |
+ |
35 |
+ @property |
36 |
+ def without_conditionals(self): |
37 |
+ return self |
38 |
+ |
39 |
+ def _iter_deps(self, deps): |
40 |
+ for d in deps: |
41 |
+ if isinstance(d, PMConditionalDep): |
42 |
+ if d.enabled: |
43 |
+ for d in self._iter_deps(d): |
44 |
+ yield d |
45 |
+ elif isinstance(d, PMOneOfDep): |
46 |
+ yield PMUncondOneOfDep(d) |
47 |
+ else: |
48 |
+ yield d |
49 |
+ |
50 |
+ def __iter__(self): |
51 |
+ return self._iter_deps(self._parent) |
52 |
+ |
53 |
class PMConditionalDep(PMBaseDep): |
54 |
""" |
55 |
A conditional dependency set (enabled by a condition of some kind). |
56 |
""" |
57 |
|
58 |
+ @property |
59 |
+ def without_conditionals(self): |
60 |
+ return PMUncondDep((self,)) |
61 |
+ |
62 |
@abstractproperty |
63 |
def enabled(self): |
64 |
""" |
65 |
@@ -36,10 +71,22 @@ class PMConditionalDep(PMBaseDep): |
66 |
pass |
67 |
|
68 |
class PMOneOfDep(PMBaseDep): |
69 |
+ """ |
70 |
+ A one-of dependency set (C{|| ( ... )}). |
71 |
+ """ |
72 |
+ |
73 |
+ @property |
74 |
+ def without_conditionals(self): |
75 |
+ return PMUncondOneOfDep(self) |
76 |
+ |
77 |
+class PMUncondOneOfDep(PMOneOfDep, PMUncondDep): |
78 |
pass |
79 |
|
80 |
class PMPackageDepSet(PMBaseDep): |
81 |
""" |
82 |
A base class representing a depset of a single package. |
83 |
""" |
84 |
- pass |
85 |
+ |
86 |
+ @property |
87 |
+ def without_conditionals(self): |
88 |
+ return PMUncondDep(self) |