Use a local_config flag to replace PORTAGE_CALLER == repoman conditionals.
authorZac Medico <zmedico@gentoo.org>
Mon, 9 Oct 2006 07:14:19 +0000 (07:14 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 9 Oct 2006 07:14:19 +0000 (07:14 -0000)
svn path=/main/trunk/; revision=4631

bin/repoman
pym/portage.py

index 99cb05b1df2b69008a3126cf0ec32f7883ecce4b..91a1bd7410e4d5106743f0241d318fc35dd5a1af 100755 (executable)
@@ -11,7 +11,6 @@ import errno, os, shutil, sys
 if not hasattr(__builtins__, "set"):
        from sets import Set as set
 exename=os.path.basename(sys.argv[0])  
-os.environ["PORTAGE_CALLER"]="repoman"
 sys.path = ["/usr/lib/portage/pym"]+sys.path
 version="1.2"  
 
@@ -48,9 +47,11 @@ from stat import S_ISDIR, ST_CTIME, ST_GID, ST_MTIME
 
 # A sane umask is needed for files that portage creates.
 os.umask(022)
-trees = portage.create_trees()
-settings = trees["/"]["porttree"].settings
-if settings.get("NOCOLOR", None) in ("yes", "true") or \
+repoman_settings = portage.config(local_config=False,
+       config_incrementals=portage_const.INCREMENTALS)
+repoman_settings.lock()
+
+if repoman_settings.get("NOCOLOR", "").upper() in ("yes", "true") or \
        not sys.stdout.isatty():
        nocolor()
 
@@ -229,7 +230,6 @@ ven_string=ven_cat+'/'+ven_nam+'-'+ven_ver+ven_suf+ven_rev
 valid_ebuild_name_re=re.compile(ven_string+'$', re.I)
 valid_ebuild_filename_re=re.compile(ven_string+'\.ebuild$', re.I)
 
-repoman_settings = portage.config(clone=settings)
 verbose=0
 quiet=0
 
@@ -473,12 +473,16 @@ if quiet < 2:
        print "PORTDIR = \""+os.environ["PORTDIR"]+"\""
        print "PORTDIR_OVERLAY = \""+os.environ["PORTDIR_OVERLAY"]+"\""
 
-trees = portage.create_trees(trees=trees)
-settings = trees["/"]["porttree"].settings
+# Now that PORTDIR_OVERLAY is properly overridden, create the portdb.
+repoman_settings = portage.config(local_config=False,
+       config_incrementals=portage_const.INCREMENTALS)
+repoman_settings.lock()
+trees = portage.create_trees()
+trees["/"]["porttree"].settings = repoman_settings
 portdb = trees["/"]["porttree"].dbapi
+portdb.mysettings = repoman_settings
 # dep_zapdeps looks at the vardbapi, but it shouldn't for repoman.
-trees["/"]["vartree"].dbapi = portage.fakedbapi(settings=settings)
-repoman_settings = portage.config(clone=settings)
+trees["/"]["vartree"].dbapi = portage.fakedbapi(settings=repoman_settings)
 
 if not myreporoot:
        myreporoot = os.path.basename(portdir_overlay)
@@ -1131,7 +1135,8 @@ for x in scanlist:
                                else:
                                        dep_settings = portage.config(
                                                config_profile_path=profdir,
-                                               config_incrementals=portage_const.INCREMENTALS)
+                                               config_incrementals=portage_const.INCREMENTALS,
+                                               local_config=False)
                                        arch_caches[prof[0]] = dep_settings
                                        while True:
                                                try:
index bc70d5ec848252cb8f38a4ce12c161d4439963f8..6dd7ac3e1ed8db7ce9157cc30ae4ccb6c6e7fe1a 100644 (file)
@@ -828,7 +828,8 @@ def check_config_instance(test):
 
 class config:
        def __init__(self, clone=None, mycpv=None, config_profile_path=None,
-               config_incrementals=None, config_root="/", target_root="/"):
+               config_incrementals=None, config_root="/", target_root="/",
+               local_config=True):
 
                self.already_in_regenerate = 0
 
@@ -853,11 +854,13 @@ class config:
                self.negVirtuals  = {}
 
                self.user_profile_dir = None
+               self.local_config = local_config
 
                if clone:
                        self.incrementals = copy.deepcopy(clone.incrementals)
                        self.profile_path = copy.deepcopy(clone.profile_path)
                        self.user_profile_dir = copy.deepcopy(clone.user_profile_dir)
+                       self.local_config = copy.deepcopy(clone.local_config)
 
                        self.module_priority = copy.deepcopy(clone.module_priority)
                        self.modules         = copy.deepcopy(clone.modules)
@@ -983,9 +986,7 @@ class config:
                                                                        (parentPath, parentsFile))
                                        self.profiles.append(currentPath)
                                addProfile(os.path.realpath(self.profile_path))
-                       if os.environ.has_key("PORTAGE_CALLER") and os.environ["PORTAGE_CALLER"] == "repoman":
-                               pass
-                       else:
+                       if local_config:
                                custom_prof = os.path.join(
                                        config_root, CUSTOM_PROFILE_PATH.lstrip(os.path.sep))
                                if os.path.exists(custom_prof):
@@ -1159,19 +1160,19 @@ class config:
                        pmask_locations = [os.path.join(self["PORTDIR"], "profiles")]
                        pmask_locations.extend(self.profiles)
 
-                       if os.environ.get("PORTAGE_CALLER","") != "repoman" or \
-                               os.environ.get("PORTDIR_OVERLAY","") != "":
-                               overlay_profiles = []
-                               for ov in self["PORTDIR_OVERLAY"].split():
-                                       ov = normalize_path(ov)
-                                       profiles_dir = os.path.join(ov, "profiles")
-                                       if os.path.isdir(profiles_dir):
-                                               overlay_profiles.append(profiles_dir)
-                               locations += overlay_profiles
-                               
-                               pmask_locations.extend(overlay_profiles)
+                       """ repoman controls PORTDIR_OVERLAY via the environment, so no
+                       special cases are needed here."""
+                       overlay_profiles = []
+                       for ov in self["PORTDIR_OVERLAY"].split():
+                               ov = normalize_path(ov)
+                               profiles_dir = os.path.join(ov, "profiles")
+                               if os.path.isdir(profiles_dir):
+                                       overlay_profiles.append(profiles_dir)
+                       locations += overlay_profiles
+                       
+                       pmask_locations.extend(overlay_profiles)
 
-                       if os.environ.get("PORTAGE_CALLER","") != "repoman":
+                       if local_config:
                                locations.append(abs_user_config)
                                pmask_locations.append(abs_user_config)
                                pusedict = grabdict_package(
@@ -1305,13 +1306,12 @@ class config:
 
                        if not portage_exec.sandbox_capable and \
                                ("sandbox" in self.features or "usersandbox" in self.features):
-                               if os.environ.get("PORTAGE_CALLER","") == "repoman" and \
-                                       self.profile_path is not None and \
-                                       os.path.realpath(self.profile_path) != \
+                               if self.profile_path is not None and \
+                                       os.path.realpath(self.profile_path) == \
                                        os.path.realpath(PROFILE_PATH):
-                                       # This profile does not belong to the user running repoman.
-                                       pass
-                               else:
+                                       """ Don't show this warning when running repoman and the
+                                       sandbox feature came from a profile that doesn't belong to
+                                       the user."""
                                        writemsg(colorize("BAD", "!!! Problem with sandbox" + \
                                                " binary. Disabling...\n\n"), noiselevel=-1)
                                if "sandbox" in self.features:
@@ -1749,7 +1749,7 @@ class config:
                        self.dirVirtuals + [self.negVirtuals], incremental=1)
 
                # Repoman does not use user or tree virtuals.
-               if os.environ.get("PORTAGE_CALLER","") != "repoman":
+               if self.local_config:
                        # XXX: vartree does not use virtuals, does user set matter?
                        temp_vartree = vartree(myroot, self.dirVirtuals,
                                categories=self.categories, settings=self)