Misc fixes for verbose repo output:
authorZac Medico <zmedico@gentoo.org>
Sat, 14 Jul 2007 03:36:17 +0000 (03:36 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 14 Jul 2007 03:36:17 +0000 (03:36 -0000)
- Support binary packages by using the 'repository' metadata that's stored in the package.
- Support PORTAGE_CONFIGROOT, showing repos from both configs if necessary.
- Dynamic allocation of repo indexes so only relevant repos are shown.

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

pym/emerge/__init__.py

index 6d27d23b0582610443e91c580555fecf1fb11d9d..8033c9e1ffce2efd4ed5ce9ec2522ceae1144629 100644 (file)
@@ -2651,12 +2651,41 @@ class depgraph(object):
                                        ret = '%s="%s" ' % (name, ret)
                                return ret
 
-               if verbosity == 3:
-                       # FIXME: account for the possibility of different overlays in
-                       # /etc/make.conf vs. ${PORTAGE_CONFIGROOT}/etc/make.conf
-                       overlays = self.settings["PORTDIR_OVERLAY"].split()
-                       overlays_real = [os.path.realpath(t) \
-                               for t in self.settings["PORTDIR_OVERLAY"].split()]
+               # Get repo data for verbose repo display.
+               repo_paths = set()
+               for root_config in self.roots.itervalues():
+                       portdir = root_config.settings.get("PORTDIR")
+                       if portdir:
+                               repo_paths.add(portdir)
+                       overlays = root_config.settings.get("PORTDIR_OVERLAY")
+                       if overlays:
+                               repo_paths.update(overlays.split())
+               repo_paths = list(repo_paths)
+               repo_paths.sort()
+               repo_paths_real = [ os.path.realpath(repo_path) \
+                       for repo_path in repo_paths ]
+               # Track which ones are show so the list can be pruned to save space.
+               shown_repos = {}
+               unknown_repo = False
+               def repo_str(portdb, repo_name):
+                       repo_path_real = portdb.getRepositoryPath(repo_name)
+                       real_index = -1
+                       if repo_path_real:
+                               try:
+                                       real_index = repo_paths_real.index(repo_path_real)
+                               except ValueError:
+                                       pass
+                       if real_index == -1:
+                               s = "?"
+                               unknown_repo = True
+                       else:
+                               repo_path = repo_paths[real_index]
+                               index = shown_repos.get(repo_path)
+                               if index is None:
+                                       index = len(shown_repos)
+                                       shown_repos[repo_path] = index
+                               s = str(index)
+                       return s
 
                tree_nodes = []
                display_list = []
@@ -2745,7 +2774,6 @@ class depgraph(object):
 
                from portage import flatten
                from portage.dep import use_reduce, paren_reduce
-               display_overlays=False
                # files to fetch list - avoids counting a same file twice
                # in size display (verbose mode)
                myfetchlist=[]
@@ -2796,6 +2824,20 @@ class depgraph(object):
                                        mydbapi = self.mydbapi[myroot] # contains cached metadata
                                metadata = dict(izip(self._mydbapi_keys,
                                        mydbapi.aux_get(pkg_key, self._mydbapi_keys)))
+                               ebuild_path = None
+                               repo_name = metadata["repository"]
+                               if pkg_type == "ebuild":
+                                       ebuild_path = portdb.findname(pkg_key)
+                                       if not ebuild_path: # shouldn't happen
+                                               raise portage.exception.PackageNotFound(pkg_key)
+                                       repo_path = os.path.sep.join(
+                                               ebuild_path.split(os.path.sep)[:-3])
+                                       for repo_name in portdb.getRepositories():
+                                               if portdb.getRepositoryPath(repo_name) == repo_path:
+                                                       repo_name = repo_name
+                                                       break
+                                               else:
+                                                       repo_name = None
                                if pkg_key not in self.useFlags[myroot]:
                                        """If this is a --resume then the USE flags need to be
                                        fetched from the appropriate locations here."""
@@ -2996,41 +3038,26 @@ class depgraph(object):
                                                verboseadd+=format_size(mysize)+" "
 
                                        # overlay verbose
-                                       # XXX: Invalid binaries have caused tracebacks here. 'if file_name'
-                                       # x = ['binary', '/', 'sys-apps/pcmcia-cs-3.2.7.2.6', 'merge']
-                                       file_name = portdb.findname(pkg_key)
-                                       if file_name: # It might not exist in the tree
-                                               newrepo = pkgsettings["PORTDIR"]
-                                               newrepoindex = "0"
-                                               if self.trees[x[1]]["vartree"].dbapi.cpv_exists(pkg):
-                                                       oldrepo = self.trees[x[1]]["vartree"].dbapi.aux_get(pkg, ["repository"])[0]
-                                               else:
-                                                       oldrepo = ""
-                                               if oldrepo != "":
-                                                       oldrepo = portdb.getRepositoryPath(oldrepo)
-                                               dir_name=os.path.abspath(os.path.dirname(file_name)+"/../..")
-                                               if (overlays_real.count(dir_name) > 0):
-                                                       newrepoindex = overlays_real.index(os.path.normpath(dir_name))
-                                                       newrepo = overlays_real[newrepoindex]
-                                                       newrepoindex += 1
-                                               
-                                               # assing lookup indexes
-                                               if not oldrepo:
-                                                       oldrepoindex = "?"
-                                               elif oldrepo == os.path.realpath(pkgsettings["PORTDIR"]):
-                                                       oldrepoindex = "0"
-                                               else:
-                                                       oldrepoindex = str(overlays_real.index(os.path.normpath(oldrepo)) + 1)
-                                               if oldrepoindex == newrepoindex \
-                                                               or not self.trees[x[1]]["vartree"].dbapi.cpv_exists(pkg):
-                                                       repoadd = newrepoindex
-                                               else:
-                                                       repoadd = "%s=>%s" % (oldrepoindex, newrepoindex)
-
-                                               verboseadd+=teal("[%s]" % repoadd)+" "
-                                               display_overlays=True
+                                       # assign index for a previous version in the same slot
+                                       has_previous = False
+                                       repo_name_prev = None
+                                       slot_atom = "%s:%s" % (portage.dep_getkey(pkg_key),
+                                               metadata["SLOT"])
+                                       slot_matches = vardb.match(slot_atom)
+                                       if slot_matches:
+                                               has_previous = True
+                                               repo_name_prev = vardb.aux_get(slot_matches[0],
+                                                       ["repository"])[0]
+
+                                       # now use the data to generate output
+                                       repoadd = None
+                                       if pkg_status == "nomerge" or not has_previous:
+                                               repoadd = repo_str(portdb, repo_name)
                                        else:
-                                               verboseadd += "[No ebuild?]"
+                                               repoadd = "%s=>%s" % (repo_str(portdb, repo_name_prev),
+                                                       repo_str(portdb, repo_name))
+                                       if repoadd:
+                                               verboseadd += teal("[%s]" % repoadd)
 
                                xs = list(portage.pkgsplit(x[2]))
                                if xs[2]=="r0":
@@ -3168,13 +3195,15 @@ class depgraph(object):
                if verbosity == 3:
                        print
                        print counters
-                       if overlays and display_overlays:
+                       if shown_repos or unknown_repo:
                                print "Portage tree and overlays:"
-                               y=0
-                               print " "+teal("[0]"), self.settings["PORTDIR"]
-                               for x in overlays:
-                                       y=y+1
-                                       print " "+teal("["+str(y)+"]"),x
+                       show_repo_paths = list(shown_repos)
+                       for repo_path, repo_index in shown_repos.iteritems():
+                               show_repo_paths[repo_index] = repo_path
+                       if show_repo_paths:
+                               for index, repo_path in enumerate(show_repo_paths):
+                                       print " "+teal("["+str(index)+"]"),repo_path
+                       if unknown_repo:
                                print " "+teal("[?]"), "indicates that the source repository could not be determined"
 
                if "--changelog" in self.myopts: