1 |
Allow PORTAGE_CONFIGROOT to be set as a command-line option. It can be |
2 |
annoying to get environment variables to emerge, particularly when you |
3 |
need sudo and you only want the environment variable some of the time. |
4 |
|
5 |
Also cleans up parsing of options which have to be parsed before the |
6 |
command line that includes EMERGE_DEFAULT_OPTS is assembled. |
7 |
|
8 |
Signed-off-by: Daniel Barkalow <barkalow@××××××××.org> |
9 |
|
10 |
Index: bin/emerge |
11 |
=================================================================== |
12 |
--- bin/emerge (revision 5054) |
13 |
+++ bin/emerge (working copy) |
14 |
@@ -4193,6 +4193,26 @@ |
15 |
sys.stderr.write("!!! '%s' or '%s'\n\n" % (action1, action2)) |
16 |
sys.exit(1) |
17 |
|
18 |
+def parse_early_opts(cmdline): |
19 |
+ early={} |
20 |
+ normal=[] |
21 |
+ for i in cmdline: |
22 |
+ isearly = False |
23 |
+ if i in ["--ignore-default-opts"]: |
24 |
+ isearly = True |
25 |
+ for opt in ["--config-root"]: |
26 |
+ if i.startswith(opt + "="): |
27 |
+ isearly = True |
28 |
+ if isearly: |
29 |
+ if "=" in i: |
30 |
+ idx = i.index("=") |
31 |
+ early[i[:idx]] = i[idx+1:] |
32 |
+ else: |
33 |
+ early[i]=True |
34 |
+ else: |
35 |
+ normal.append(i) |
36 |
+ return early, normal |
37 |
+ |
38 |
def parse_opts(tmpcmdline): |
39 |
myaction=None |
40 |
myopts = {} |
41 |
@@ -4286,10 +4306,12 @@ |
42 |
sys.exit(9) |
43 |
del myroot, mysettings |
44 |
|
45 |
-def load_emerge_config(trees=None): |
46 |
+def load_emerge_config(trees=None, config_root=None): |
47 |
kwargs = {} |
48 |
for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")): |
49 |
kwargs[k] = os.environ.get(envvar, "/") |
50 |
+ if config_root: |
51 |
+ kwargs["config_root"] = config_root |
52 |
trees = portage.create_trees(trees=trees, **kwargs) |
53 |
|
54 |
settings = trees["/"]["vartree"].settings |
55 |
@@ -4389,12 +4411,19 @@ |
56 |
def emerge_main(): |
57 |
# Portage needs to ensure a sane umask for the files it creates. |
58 |
os.umask(022) |
59 |
- settings, trees, mtimedb = load_emerge_config() |
60 |
+ |
61 |
+ earlyopts, normalopts = parse_early_opts(sys.argv[1:]) |
62 |
+ |
63 |
+ config_root_opt = None |
64 |
+ if "--config-root" in earlyopts: |
65 |
+ config_root_opt = earlyopts["--config-root"] |
66 |
+ |
67 |
+ settings, trees, mtimedb = load_emerge_config(config_root=config_root_opt) |
68 |
portdb = trees[settings["ROOT"]]["porttree"].dbapi |
69 |
if portage.global_updates(settings, trees, mtimedb["updates"]): |
70 |
mtimedb.commit() |
71 |
# Reload the whole config from scratch. |
72 |
- settings, trees, mtimedb = load_emerge_config(trees=trees) |
73 |
+ settings, trees, mtimedb = load_emerge_config(trees=trees, config_root=config_root_opt) |
74 |
portdb = trees[settings["ROOT"]]["porttree"].dbapi |
75 |
|
76 |
ldpath_mtimes = mtimedb["ldpath"] |
77 |
@@ -4414,9 +4443,9 @@ |
78 |
nocolor() |
79 |
|
80 |
tmpcmdline = [] |
81 |
- if "--ignore-default-opts" not in sys.argv: |
82 |
+ if "--ignore-default-opts" not in earlyopts: |
83 |
tmpcmdline.extend(settings["EMERGE_DEFAULT_OPTS"].split()) |
84 |
- tmpcmdline.extend(sys.argv[1:]) |
85 |
+ tmpcmdline.extend(normalopts) |
86 |
myaction, myopts, myfiles = parse_opts(tmpcmdline) |
87 |
|
88 |
for myroot in trees: |
89 |
-- |
90 |
gentoo-portage-dev@g.o mailing list |