Make FindPortdir() fall back to have_profile_dir() checks if it can't match
authorZac Medico <zmedico@gentoo.org>
Tue, 11 Nov 2008 18:20:10 +0000 (18:20 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 11 Nov 2008 18:20:10 +0000 (18:20 -0000)
the current location with anything from PORTDIR_OVERLAY. Assume that an
overlay will contain at least a "repo_name" file while a master repo (portdir)
will contain at least a "profiles.desc" file.

svn path=/main/trunk/; revision=11855

pym/repoman/utilities.py

index 807ff1ba9557b30ca37b177493cf400dadd07996..cee52186efc74010c17afa53fd5048647aa66468 100644 (file)
@@ -95,11 +95,13 @@ def detect_vcs_conflicts(options, vcs):
                                sys.exit(retval)
 
 
-def have_profile_dir(path, maxdepth=3):
-       """ Try to figure out if 'path' has a /profiles dir in it by checking for a package.mask file
+def have_profile_dir(path, maxdepth=3, filename="profiles.desc"):
+       """ 
+       Try to figure out if 'path' has a profiles/
+       dir in it by checking for the given filename.
        """
        while path != "/" and maxdepth:
-               if os.path.exists(os.path.join(path, "profiles", "profiles.desc")):
+               if os.path.exists(os.path.join(path, "profiles", filename)):
                        return normalize_path(path)
                path = normalize_path(path + "/..")
                maxdepth -= 1
@@ -379,9 +381,21 @@ def FindPortdir(settings):
                        if have_profile_dir(location, subdir.count("/")):
                                portdir = portdir_overlay
                        break
-       
-       del p, s, path_ids
-       
+
+       # Couldn't match location with anything from PORTDIR_OVERLAY,
+       # so fall back to have_profile_dir() checks alone. Assume that
+       # an overlay will contain at least a "repo_name" file while a
+       # master repo (portdir) will contain at least a "profiles.desc"
+       # file.
+       if not portdir_overlay:
+               portdir_overlay = have_profile_dir(location, filename="repo_name")
+               if portdir_overlay:
+                       subdir = location[len(portdir_overlay):]
+                       if subdir and subdir[-1] != os.sep:
+                               subdir += os.sep
+                       if have_profile_dir(location, subdir.count(os.sep)):
+                               portdir = portdir_overlay
+
        if not portdir_overlay:
                if (settings["PORTDIR"] + os.path.sep).startswith(location):
                        portdir_overlay = settings["PORTDIR"]