Merge the new repo display code from trunk r7257:7260.
authorZac Medico <zmedico@gentoo.org>
Sat, 14 Jul 2007 23:50:58 +0000 (23:50 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 14 Jul 2007 23:50:58 +0000 (23:50 -0000)
svn path=/main/branches/2.1.2/; revision=7261

bin/emerge
pym/portage.py

index 9b36d02131b018058beedc12772b384177cf6e1f..da52418f7d7bedb0336acfb4ce5da0ddf2c56925 100755 (executable)
@@ -844,7 +844,7 @@ class FakeVartree(portage.vartree):
                        if os.access(vdb_path, os.W_OK):
                                vdb_lock = portage_locks.lockdir(vdb_path)
                        mykeys = ["SLOT", "COUNTER", "PROVIDE", "USE", "IUSE",
-                               "RESTRICT", "DEPEND", "RDEPEND", "PDEPEND"]
+                               "RESTRICT", "DEPEND", "RDEPEND", "PDEPEND", "repository"]
                        real_dbapi = real_vartree.dbapi
                        slot_counters = {}
                        for cpv in real_dbapi.cpv_all():
@@ -1087,7 +1087,7 @@ class depgraph:
                self._reinstall_nodes = {}
                self.mydbapi = {}
                self._mydbapi_keys = ["SLOT", "DEPEND", "RDEPEND", "PDEPEND",
-                       "USE", "IUSE", "PROVIDE", "RESTRICT"]
+                       "USE", "IUSE", "PROVIDE", "RESTRICT", "repository"]
                self.useFlags = {}
                self.trees = {}
                self.roots = {}
@@ -2629,6 +2629,8 @@ class depgraph:
                        overlays_real = [os.path.realpath(t) \
                                for t in self.settings["PORTDIR_OVERLAY"].split()]
 
+               repo_display = RepoDisplay(self.roots)
+
                tree_nodes = []
                display_list = []
                mygraph = self._parent_child_digraph
@@ -2766,6 +2768,16 @@ class depgraph:
                                        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_real = os.path.dirname(os.path.dirname(
+                                               os.path.dirname(ebuild_path)))
+                               else:
+                                       repo_path_real = portdb.getRepositoryPath(repo_name)
                                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."""
@@ -2965,17 +2977,31 @@ class depgraph:
                                                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
-                                               dir_name=os.path.abspath(os.path.dirname(file_name)+"/../..")
-                                               if (overlays_real.count(dir_name)>0):
-                                                       verboseadd+=teal("["+str(overlays_real.index(
-                                                               os.path.normpath(dir_name))+1)+"]")+" "
-                                                       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_display.repoStr(repo_path_real)
                                        else:
-                                               verboseadd += "[No ebuild?]"
+                                               repo_path_prev = None
+                                               if repo_name_prev:
+                                                       repo_path_prev = portdb.getRepositoryPath(
+                                                               repo_name_prev)
+                                               repoadd = "%s=>%s" % (
+                                                       repo_display.repoStr(repo_path_prev),
+                                                       repo_display.repoStr(repo_path_real))
+                                       if repoadd:
+                                               verboseadd += teal("[%s]" % repoadd)
 
                                xs=portage.pkgsplit(x[2])
                                if xs[2]=="r0":
@@ -3113,12 +3139,7 @@ class depgraph:
                if verbosity == 3:
                        print
                        print counters
-                       if overlays and display_overlays:
-                               print "Portage overlays:"
-                               y=0
-                               for x in overlays:
-                                       y=y+1
-                                       print " "+teal("["+str(y)+"]"),x
+                       sys.stdout.write(str(repo_display))
 
                if "--changelog" in self.myopts:
                        print
@@ -3286,6 +3307,65 @@ class depgraph:
                                fakedb[myroot].aux_update(pkg_key, {"USE":pkgsettings["USE"]})
                        self.spinner.update()
 
+class RepoDisplay(object):
+       def __init__(self, roots):
+               self._shown_repos = {}
+               self._unknown_repo = False
+               repo_paths = set()
+               for root_config in 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)
+               self._repo_paths = repo_paths
+               self._repo_paths_real = [ os.path.realpath(repo_path) \
+                       for repo_path in repo_paths ]
+
+               # pre-allocate index for PORTDIR so that it always has index 0.
+               for root_config in roots.itervalues():
+                       portdb = root_config.trees["porttree"].dbapi
+                       portdir = portdb.porttree_root
+                       if portdir:
+                               self.repoStr(portdir)
+
+       def repoStr(self, repo_path_real):
+               real_index = -1
+               if repo_path_real:
+                       real_index = self._repo_paths_real.index(repo_path_real)
+               if real_index == -1:
+                       s = "?"
+                       self._unknown_repo = True
+               else:
+                       shown_repos = self._shown_repos
+                       repo_paths = self._repo_paths
+                       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
+
+       def __str__(self):
+               output = []
+               shown_repos = self._shown_repos
+               unknown_repo = self._unknown_repo
+               if shown_repos or self._unknown_repo:
+                       output.append("Portage tree and overlays:\n")
+               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):
+                               output.append(" "+teal("["+str(index)+"]")+" %s\n" % repo_path)
+               if unknown_repo:
+                       output.append(" "+teal("[?]") + \
+                               " indicates that the source repository could not be determined\n")
+               return "".join(output)
+
 class PackageCounters(object):
 
        def __init__(self):
index 92938eb363ef1eff29da45aa37d56f66950884eb..1b31173773f1577798260ef40209968cd9e5ed66 100644 (file)
@@ -5219,7 +5219,7 @@ class vardbapi(dbapi):
                        vartree = globals()["db"][root]["vartree"]
                self.vartree = vartree
                self._aux_cache_keys = set(["SLOT", "COUNTER", "PROVIDE", "USE",
-                       "IUSE", "DEPEND", "RDEPEND", "PDEPEND"])
+                       "IUSE", "DEPEND", "RDEPEND", "PDEPEND", "repository"])
                self._aux_cache = None
                self._aux_cache_version = "1"
                self._aux_cache_filename = os.path.join(self.root,