[gentoo-portage-dev] [PATCH] Allow non-default make.conf to set ROOT

2006-11-15 Thread Daniel Barkalow
If PORTAGE_CONFIGROOT is not /, this is likely to mean that we're not 
intended to be working on the live system (and, in fact, are probably 
making stuff that's incompatible with the live system). The user probably 
wants to use ROOT, but we ought to let the make.conf in the 
PORTAGE_CONFIGROOT set ROOT, so there's only one variable that the user 
needs to keep straight.

I could do a bit more extensive version to check the config file's ROOT 
(if present) for being a directory, like the environment variable is 
checked, and to make the environment variable override the config file, if 
either of those is worthwhile.

Signed-off-by: Daniel Barkalow [EMAIL PROTECTED]

Index: pym/portage.py
===
--- pym/portage.py  (revision 5054)
+++ pym/portage.py  (working copy)
@@ -1128,6 +1128,8 @@
noiselevel=-1)
sys.exit(1)
 
+   if config_root != / and ROOT in self.mygcfg:
+   target_root = self.mygcfg[ROOT]
 
self.configlist.append(self.mygcfg)
self.configdict[conf]=self.configlist[-1]
-- 
gentoo-portage-dev@gentoo.org mailing list



[gentoo-portage-dev] [PATCH] --config-root command-line option

2006-11-15 Thread Daniel Barkalow
Allow PORTAGE_CONFIGROOT to be set as a command-line option. It can be 
annoying to get environment variables to emerge, particularly when you 
need sudo and you only want the environment variable some of the time.

Also cleans up parsing of options which have to be parsed before the 
command line that includes EMERGE_DEFAULT_OPTS is assembled.

Signed-off-by: Daniel Barkalow [EMAIL PROTECTED]

Index: bin/emerge
===
--- bin/emerge  (revision 5054)
+++ bin/emerge  (working copy)
@@ -4193,6 +4193,26 @@
sys.stderr.write(!!! '%s' or '%s'\n\n % (action1, action2))
sys.exit(1)
 
+def parse_early_opts(cmdline):
+   early={}
+   normal=[]
+   for i in cmdline:
+   isearly = False
+   if i in [--ignore-default-opts]:
+   isearly = True
+   for opt in [--config-root]:
+   if i.startswith(opt + =):
+   isearly = True
+   if isearly:
+   if = in i:
+   idx = i.index(=)
+   early[i[:idx]] = i[idx+1:]
+   else:
+   early[i]=True
+   else:
+   normal.append(i)
+   return early, normal
+
 def parse_opts(tmpcmdline):
myaction=None
myopts = {}
@@ -4286,10 +4306,12 @@
sys.exit(9)
del myroot, mysettings
 
-def load_emerge_config(trees=None):
+def load_emerge_config(trees=None, config_root=None):
kwargs = {}
for k, envvar in ((config_root, PORTAGE_CONFIGROOT), 
(target_root, ROOT)):
kwargs[k] = os.environ.get(envvar, /)
+   if config_root:
+   kwargs[config_root] = config_root
trees = portage.create_trees(trees=trees, **kwargs)
 
settings = trees[/][vartree].settings
@@ -4389,12 +4411,19 @@
 def emerge_main():
# Portage needs to ensure a sane umask for the files it creates.
os.umask(022)
-   settings, trees, mtimedb = load_emerge_config()
+
+   earlyopts, normalopts = parse_early_opts(sys.argv[1:])
+
+   config_root_opt = None
+   if --config-root in earlyopts:
+   config_root_opt = earlyopts[--config-root]
+   
+   settings, trees, mtimedb = 
load_emerge_config(config_root=config_root_opt)
portdb = trees[settings[ROOT]][porttree].dbapi
if portage.global_updates(settings, trees, mtimedb[updates]):
mtimedb.commit()
# Reload the whole config from scratch.
-   settings, trees, mtimedb = load_emerge_config(trees=trees)
+   settings, trees, mtimedb = load_emerge_config(trees=trees, 
config_root=config_root_opt)
portdb = trees[settings[ROOT]][porttree].dbapi
 
ldpath_mtimes = mtimedb[ldpath]
@@ -4414,9 +4443,9 @@
nocolor()
 
tmpcmdline = []
-   if --ignore-default-opts not in sys.argv:
+   if --ignore-default-opts not in earlyopts:
tmpcmdline.extend(settings[EMERGE_DEFAULT_OPTS].split())
-   tmpcmdline.extend(sys.argv[1:])
+   tmpcmdline.extend(normalopts)
myaction, myopts, myfiles = parse_opts(tmpcmdline)
 
for myroot in trees:
-- 
gentoo-portage-dev@gentoo.org mailing list



Re: [gentoo-portage-dev] [PATCH] Allow non-default make.conf to set ROOT (take 2)

2006-11-15 Thread Daniel Barkalow
(Previous version left ROOT from .../etc/make.conf unnormalized)

If PORTAGE_CONFIGROOT is not /, this is likely to mean that we're not 
intended to be working on the live system (and, in fact, are probably 
making stuff that's incompatible with the live system). The user probably 
wants to use ROOT, but we ought to let the make.conf in the 
PORTAGE_CONFIGROOT set ROOT, so there's only one variable that the user 
needs to keep straight.

Also normalize and check ROOT after reading the config file and getting 
this option. 

Still doesn't let environment variable (or, in general, callers of 
create_trees) override the config file.

Signed-off-by: Daniel Barkalow [EMAIL PROTECTED]

Index: pym/portage.py
===
--- pym/portage.py  (revision 5054)
+++ pym/portage.py  (working copy)
@@ -833,6 +833,12 @@
if not test or (str(test.__class__) != 'portage.config'):
raise TypeError, Invalid type for config object: %s % 
test.__class__
 
+def check_var_directory(varname, var):
+   if not os.path.isdir(var):
+   writemsg(!!! Error: %s='%s' is not a directory. Please correct 
this.\n % (var, varname),
+   noiselevel=-1)
+   raise portage_exception.DirectoryNotFound(var)
+
 class config:
def __init__(self, clone=None, mycpv=None, config_profile_path=None,
config_incrementals=None, config_root=/, target_root=/,
@@ -929,12 +935,7 @@
target_root = \
normalize_path(target_root).rstrip(os.path.sep) 
+ os.path.sep
 
-   for k, v in ((PORTAGE_CONFIGROOT, config_root),
-   (ROOT, target_root)):
-   if not os.path.isdir(v):
-   writemsg(!!! Error: %s='%s' is not a 
directory. Please correct this.\n % (k, v),
-   noiselevel=-1)
-   raise 
portage_exception.DirectoryNotFound(v)
+   check_var_directory(PORTAGE_CONFIGROOT, config_root)
 
self.depcachedir = DEPCACHE_PATH
 
@@ -1128,7 +1129,9 @@
noiselevel=-1)
sys.exit(1)
 
-
+   if config_root != / and ROOT in self.mygcfg:
+   target_root = self.mygcfg[ROOT]
+   
self.configlist.append(self.mygcfg)
self.configdict[conf]=self.configlist[-1]
 
@@ -1179,6 +1182,12 @@
 
self[PORTAGE_CONFIGROOT] = config_root
self.backup_changes(PORTAGE_CONFIGROOT)
+
+   target_root = \
+   normalize_path(target_root).rstrip(os.path.sep) 
+ os.path.sep
+
+   check_var_directory(ROOT, target_root)
+
self[ROOT] = target_root
self.backup_changes(ROOT)
 

-- 
gentoo-portage-dev@gentoo.org mailing list