Gentoo Archives: gentoo-commits

From: "Marius Mauch (genone)" <genone@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r11542 - main/trunk/pym/_emerge
Date: Thu, 25 Sep 2008 15:45:21
Message-Id: E1Kit1m-0000T2-Su@stork.gentoo.org
1 Author: genone
2 Date: 2008-09-25 15:45:13 +0000 (Thu, 25 Sep 2008)
3 New Revision: 11542
4
5 Modified:
6 main/trunk/pym/_emerge/__init__.py
7 Log:
8 move set expansion code into its own function
9
10 Modified: main/trunk/pym/_emerge/__init__.py
11 ===================================================================
12 --- main/trunk/pym/_emerge/__init__.py 2008-09-25 15:26:50 UTC (rev 11541)
13 +++ main/trunk/pym/_emerge/__init__.py 2008-09-25 15:45:13 UTC (rev 11542)
14 @@ -13353,6 +13353,67 @@
15 writemsg_level("".join("%s\n" % l for l in msg),
16 level=logging.ERROR, noiselevel=-1)
17
18 +def expand_set_arguments(myfiles, myaction, root_config):
19 + retval = os.EX_OK
20 + setconfig = root_config.setconfig
21 +
22 + # display errors that occured while loading the SetConfig instance
23 + for e in setconfig.errors:
24 + print colorize("BAD", "Error during set creation: %s" % e)
25 +
26 + sets = setconfig.getSets()
27 +
28 + # emerge relies on the existance of sets with names "world" and "system"
29 + required_sets = ("world", "system")
30 +
31 + for s in required_sets:
32 + if s not in sets:
33 + msg = ["emerge: incomplete set configuration, " + \
34 + "no \"%s\" set defined" % s]
35 + msg.append(" sets defined: %s" % ", ".join(sets))
36 + for line in msg:
37 + sys.stderr.write(line + "\n")
38 + retval = 1
39 + unmerge_actions = ("unmerge", "prune", "clean", "depclean")
40 +
41 + # In order to know exactly which atoms/sets should be added to the
42 + # world file, the depgraph performs set expansion later. It will get
43 + # confused about where the atoms came from if it's not allowed to
44 + # expand them itself.
45 + do_not_expand = (None, )
46 + newargs = []
47 + for a in myfiles:
48 + if a in ("system", "world"):
49 + newargs.append(SETPREFIX+a)
50 + else:
51 + newargs.append(a)
52 + myfiles = newargs
53 + del newargs
54 + newargs = []
55 + for a in myfiles:
56 + if a.startswith(SETPREFIX):
57 + s = a[len(SETPREFIX):]
58 + if s not in sets:
59 + display_missing_pkg_set(root_config, s)
60 + return (None, 1)
61 + setconfig.active.append(s)
62 + if myaction in unmerge_actions and \
63 + not sets[s].supportsOperation("unmerge"):
64 + sys.stderr.write("emerge: the given set '%s' does " % s + \
65 + "not support unmerge operations\n")
66 + retval = 1
67 + elif not setconfig.getSetAtoms(s):
68 + print "emerge: '%s' is an empty set" % s
69 + elif myaction not in do_not_expand:
70 + newargs.extend(setconfig.getSetAtoms(s))
71 + else:
72 + newargs.append(SETPREFIX+s)
73 + for e in sets[s].errors:
74 + print e
75 + else:
76 + newargs.append(a)
77 + return (newargs, retval)
78 +
79 def emerge_main():
80 global portage # NFC why this is necessary now - genone
81 portage._disable_legacy_globals()
82 @@ -13492,62 +13553,10 @@
83 # only expand sets for actions taking package arguments
84 oldargs = myfiles[:]
85 if myaction in ("clean", "config", "depclean", "info", "prune", "unmerge", None):
86 - setconfig = root_config.setconfig
87 - # display errors that occured while loading the SetConfig instance
88 - for e in setconfig.errors:
89 - print colorize("BAD", "Error during set creation: %s" % e)
90 -
91 - sets = setconfig.getSets()
92 - # emerge relies on the existance of sets with names "world" and "system"
93 - required_sets = ("world", "system")
94 - for s in required_sets:
95 - if s not in sets:
96 - msg = ["emerge: incomplete set configuration, " + \
97 - "no \"%s\" set defined" % s]
98 - msg.append(" sets defined: %s" % ", ".join(sets))
99 - for line in msg:
100 - sys.stderr.write(line + "\n")
101 - return 1
102 - unmerge_actions = ("unmerge", "prune", "clean", "depclean")
103 -
104 - # In order to know exactly which atoms/sets should be added to the
105 - # world file, the depgraph performs set expansion later. It will get
106 - # confused about where the atoms came from if it's not allowed to
107 - # expand them itself.
108 - do_not_expand = (None, )
109 - newargs = []
110 - for a in myfiles:
111 - if a in ("system", "world"):
112 - newargs.append(SETPREFIX+a)
113 - else:
114 - newargs.append(a)
115 - myfiles = newargs
116 - del newargs
117 - newargs = []
118 - for a in myfiles:
119 - if a.startswith(SETPREFIX):
120 - s = a[len(SETPREFIX):]
121 - if s not in sets:
122 - display_missing_pkg_set(root_config, s)
123 - return 1
124 - setconfig.active.append(s)
125 - if myaction in unmerge_actions and \
126 - not sets[s].supportsOperation("unmerge"):
127 - sys.stderr.write("emerge: the given set '%s' does " % s + \
128 - "not support unmerge operations\n")
129 - return 1
130 - if not setconfig.getSetAtoms(s):
131 - print "emerge: '%s' is an empty set" % s
132 - elif myaction not in do_not_expand:
133 - newargs.extend(setconfig.getSetAtoms(s))
134 - else:
135 - newargs.append(SETPREFIX+s)
136 - for e in sets[s].errors:
137 - print e
138 - else:
139 - newargs.append(a)
140 - myfiles = newargs
141 - del newargs
142 + myfiles, retval = expand_set_arguments(myfiles, myaction, root_config)
143 + if retval != os.EX_OK:
144 + return retval
145 +
146 # Need to handle empty sets specially, otherwise emerge will react
147 # with the help message for empty argument lists
148 if oldargs and not myfiles: