1 |
Author: zmedico |
2 |
Date: 2009-04-30 07:11:29 +0000 (Thu, 30 Apr 2009) |
3 |
New Revision: 13501 |
4 |
|
5 |
Modified: |
6 |
main/branches/2.1.6/pym/_emerge/__init__.py |
7 |
Log: |
8 |
Split out an action_uninstall() function to handle argument validation for |
9 |
clean, depclean, prune, and unmerge actions. (trunk r13344) |
10 |
|
11 |
Modified: main/branches/2.1.6/pym/_emerge/__init__.py |
12 |
=================================================================== |
13 |
--- main/branches/2.1.6/pym/_emerge/__init__.py 2009-04-30 07:10:58 UTC (rev 13500) |
14 |
+++ main/branches/2.1.6/pym/_emerge/__init__.py 2009-04-30 07:11:29 UTC (rev 13501) |
15 |
@@ -13601,6 +13601,57 @@ |
16 |
sys.exit(1) |
17 |
searchinstance.output() |
18 |
|
19 |
+def action_uninstall(settings, trees, ldpath_mtimes, |
20 |
+ opts, action, files, spinner): |
21 |
+ |
22 |
+ # For backward compat, some actions do not require leading '='. |
23 |
+ ignore_missing_eq = action in ('clean', 'unmerge') |
24 |
+ vardb = trees[settings["ROOT"]]["vartree"].dbapi |
25 |
+ valid_atoms = [] |
26 |
+ |
27 |
+ # Ensure atoms are valid before calling unmerge(). |
28 |
+ # For backward compat, leading '=' is not required. |
29 |
+ for x in files: |
30 |
+ if not (is_valid_package_atom(x) or \ |
31 |
+ (ignore_missing_eq and is_valid_package_atom("=" + x))): |
32 |
+ |
33 |
+ msg = [] |
34 |
+ msg.append("'%s' is not a valid package atom." % (x,)) |
35 |
+ msg.append("Please check ebuild(5) for full details.") |
36 |
+ writemsg_level("".join("!!! %s\n" % line for line in msg), |
37 |
+ level=logging.ERROR, noiselevel=-1) |
38 |
+ return 1 |
39 |
+ |
40 |
+ try: |
41 |
+ valid_atoms.append( |
42 |
+ portage.dep_expand(x, mydb=vardb, settings=settings)) |
43 |
+ except portage.exception.AmbiguousPackageName, e: |
44 |
+ msg = "The short ebuild name \"" + x + \ |
45 |
+ "\" is ambiguous. Please specify " + \ |
46 |
+ "one of the following " + \ |
47 |
+ "fully-qualified ebuild names instead:" |
48 |
+ for line in textwrap.wrap(msg, 70): |
49 |
+ writemsg_level("!!! %s\n" % (line,), |
50 |
+ level=logging.ERROR, noiselevel=-1) |
51 |
+ for i in e[0]: |
52 |
+ writemsg_level(" %s\n" % colorize("INFORM", i), |
53 |
+ level=logging.ERROR, noiselevel=-1) |
54 |
+ writemsg_level("\n", level=logging.ERROR, noiselevel=-1) |
55 |
+ return 1 |
56 |
+ |
57 |
+ if action in ('clean', 'unmerge') or \ |
58 |
+ (action == 'prune' and "--nodeps" in opts): |
59 |
+ # When given a list of atoms, unmerge them in the order given. |
60 |
+ ordered = action == 'unmerge' |
61 |
+ unmerge(trees[settings["ROOT"]]['root_config'], opts, action, |
62 |
+ valid_atoms, ldpath_mtimes, ordered=ordered) |
63 |
+ rval = os.EX_OK |
64 |
+ else: |
65 |
+ rval = action_depclean(settings, trees, ldpath_mtimes, |
66 |
+ opts, action, valid_atoms, spinner) |
67 |
+ |
68 |
+ return rval |
69 |
+ |
70 |
def action_depclean(settings, trees, ldpath_mtimes, |
71 |
myopts, action, myfiles, spinner): |
72 |
# Kill packages that aren't explicitly merged or are required as a |
73 |
@@ -13681,28 +13732,7 @@ |
74 |
import textwrap |
75 |
args_set = InternalPackageSet() |
76 |
if myfiles: |
77 |
- for x in myfiles: |
78 |
- if not is_valid_package_atom(x): |
79 |
- writemsg_level("!!! '%s' is not a valid package atom.\n" % x, |
80 |
- level=logging.ERROR, noiselevel=-1) |
81 |
- writemsg_level("!!! Please check ebuild(5) for full details.\n") |
82 |
- return |
83 |
- try: |
84 |
- atom = portage.dep_expand(x, mydb=vardb, settings=settings) |
85 |
- except portage.exception.AmbiguousPackageName, e: |
86 |
- msg = "The short ebuild name \"" + x + \ |
87 |
- "\" is ambiguous. Please specify " + \ |
88 |
- "one of the following " + \ |
89 |
- "fully-qualified ebuild names instead:" |
90 |
- for line in textwrap.wrap(msg, 70): |
91 |
- writemsg_level("!!! %s\n" % (line,), |
92 |
- level=logging.ERROR, noiselevel=-1) |
93 |
- for i in e[0]: |
94 |
- writemsg_level(" %s\n" % colorize("INFORM", i), |
95 |
- level=logging.ERROR, noiselevel=-1) |
96 |
- writemsg_level("\n", level=logging.ERROR, noiselevel=-1) |
97 |
- return |
98 |
- args_set.add(atom) |
99 |
+ args_set.update(myfiles) |
100 |
matched_packages = False |
101 |
for x in args_set: |
102 |
if vardb.match(x): |
103 |
@@ -15359,33 +15389,17 @@ |
104 |
validate_ebuild_environment(trees) |
105 |
action_search(trees[settings["ROOT"]]["root_config"], |
106 |
myopts, myfiles, spinner) |
107 |
- elif myaction in ("clean", "unmerge") or \ |
108 |
- (myaction == "prune" and "--nodeps" in myopts): |
109 |
+ |
110 |
+ elif myaction in ('clean', 'depclean', 'prune', 'unmerge'): |
111 |
validate_ebuild_environment(trees) |
112 |
+ rval = action_uninstall(settings, trees, mtimedb["ldpath"], |
113 |
+ myopts, myaction, myfiles, spinner) |
114 |
+ if not (buildpkgonly or fetchonly or pretend): |
115 |
+ post_emerge(root_config, myopts, mtimedb, rval) |
116 |
+ return rval |
117 |
|
118 |
- # Ensure atoms are valid before calling unmerge(). |
119 |
- # For backward compat, leading '=' is not required. |
120 |
- for x in myfiles: |
121 |
- if is_valid_package_atom(x) or \ |
122 |
- is_valid_package_atom("=" + x): |
123 |
- continue |
124 |
- msg = [] |
125 |
- msg.append("'%s' is not a valid package atom." % (x,)) |
126 |
- msg.append("Please check ebuild(5) for full details.") |
127 |
- writemsg_level("".join("!!! %s\n" % line for line in msg), |
128 |
- level=logging.ERROR, noiselevel=-1) |
129 |
- return 1 |
130 |
+ elif myaction == 'info': |
131 |
|
132 |
- # When given a list of atoms, unmerge |
133 |
- # them in the order given. |
134 |
- ordered = myaction == "unmerge" |
135 |
- if 1 == unmerge(root_config, myopts, myaction, myfiles, |
136 |
- mtimedb["ldpath"], ordered=ordered): |
137 |
- if not (buildpkgonly or fetchonly or pretend): |
138 |
- post_emerge(root_config, myopts, mtimedb, os.EX_OK) |
139 |
- |
140 |
- elif myaction in ("depclean", "info", "prune"): |
141 |
- |
142 |
# Ensure atoms are valid before calling unmerge(). |
143 |
vardb = trees[settings["ROOT"]]["vartree"].dbapi |
144 |
valid_atoms = [] |
145 |
@@ -15415,14 +15429,8 @@ |
146 |
level=logging.ERROR, noiselevel=-1) |
147 |
return 1 |
148 |
|
149 |
- if myaction == "info": |
150 |
- return action_info(settings, trees, myopts, valid_atoms) |
151 |
+ return action_info(settings, trees, myopts, valid_atoms) |
152 |
|
153 |
- validate_ebuild_environment(trees) |
154 |
- action_depclean(settings, trees, mtimedb["ldpath"], |
155 |
- myopts, myaction, valid_atoms, spinner) |
156 |
- if not (buildpkgonly or fetchonly or pretend): |
157 |
- post_emerge(root_config, myopts, mtimedb, os.EX_OK) |
158 |
# "update", "system", or just process files: |
159 |
else: |
160 |
validate_ebuild_environment(trees) |