Pass into the PackageIndex constructor a list of package
authorZac Medico <zmedico@gentoo.org>
Fri, 12 Oct 2007 01:03:34 +0000 (01:03 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 12 Oct 2007 01:03:34 +0000 (01:03 -0000)
metadata keys that inherit a default value from the header.

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

pym/portage/dbapi/bintree.py
pym/portage/getbinpkg.py

index 88ad066035d330584a24e901051d2fea56d10da6..2b23cc7633518db3de463c9a26427c939ab3c5d1 100644 (file)
@@ -159,6 +159,7 @@ class binarytree(object):
                                "SLOT"    : "0",
                                "USE"     : ""
                        }
+                       self._pkgindex_inherited_keys = ["CHOST"]
 
        def move_ent(self, mylist):
                if not self.populated:
@@ -367,8 +368,7 @@ class binarytree(object):
                                dirs.remove("All")
                        dirs.sort()
                        dirs.insert(0, "All")
-                       pkgindex = portage.getbinpkg.PackageIndex(
-                               default_pkg_data=self._pkgindex_default_pkg_data)
+                       pkgindex = self._new_pkgindex()
                        pf_index = None
                        try:
                                f = open(self._pkgindex_file)
@@ -381,8 +381,7 @@ class binarytree(object):
                                        f.close()
                                        del f
                        if not self._pkgindex_version_supported(pkgindex):
-                               pkgindex = portage.getbinpkg.PackageIndex(
-                                       default_pkg_data=self._pkgindex_default_pkg_data)
+                               pkgindex = self._new_pkgindex()
                        header = pkgindex.header
                        metadata = pkgindex.packages
                        update_pkgindex = False
@@ -565,8 +564,7 @@ class binarytree(object):
                        urldata = urlparse(base_url)
                        pkgindex_file = os.path.join(CACHE_PATH, "binhost",
                                urldata[1] + urldata[2], "Packages")
-                       pkgindex = portage.getbinpkg.PackageIndex(
-                               default_pkg_data=self._pkgindex_default_pkg_data)
+                       pkgindex = self._new_pkgindex()
                        try:
                                f = open(pkgindex_file)
                                try:
@@ -578,8 +576,7 @@ class binarytree(object):
                                        raise
                        local_timestamp = pkgindex.header.get("TIMESTAMP", None)
                        import urllib, urlparse
-                       rmt_idx = portage.getbinpkg.PackageIndex(
-                               default_pkg_data=self._pkgindex_default_pkg_data)
+                       rmt_idx = self._new_pkgindex()
                        try:
                                f = urllib.urlopen(urlparse.urljoin(base_url, "Packages"))
                                try:
@@ -722,8 +719,7 @@ class binarytree(object):
                        if self._all_directory and \
                                self.getname(cpv).split(os.path.sep)[-2] == "All":
                                self._create_symlink(cpv)
-                       pkgindex = portage.getbinpkg.PackageIndex(
-                               default_pkg_data=self._pkgindex_default_pkg_data)
+                       pkgindex = self._new_pkgindex()
                        try:
                                f = open(self._pkgindex_file)
                        except EnvironmentError:
@@ -735,8 +731,7 @@ class binarytree(object):
                                        f.close()
                                        del f
                        if not self._pkgindex_version_supported(pkgindex):
-                               pkgindex = portage.getbinpkg.PackageIndex(
-                                       default_pkg_data=self._pkgindex_default_pkg_data)
+                               pkgindex = self._new_pkgindex()
                        d = digests
                        d["CPV"] = cpv
                        d["SLOT"] = slot
@@ -769,6 +764,11 @@ class binarytree(object):
                        if pkgindex_lock:
                                unlockfile(pkgindex_lock)
 
+       def _new_pkgindex(self):
+               return portage.getbinpkg.PackageIndex(
+                       default_pkg_data=self._pkgindex_default_pkg_data,
+                       inherited_keys=self._pkgindex_inherited_keys)
+
        def _update_pkgindex_header(self, header):
                portdir = normalize_path(os.path.realpath(self.settings["PORTDIR"]))
                profiles_base = os.path.join(portdir, "profiles") + os.path.sep
index 108161c0265fcfb5cdfeb1a19750ba597fc8eff3..290bf76c59b78d4b43b55e52a69e1fbc77576e9a 100644 (file)
@@ -664,8 +664,9 @@ def writepkgindex(pkgfile, items):
 
 class PackageIndex(object):
 
-       def __init__(self, default_pkg_data=None):
+       def __init__(self, default_pkg_data=None, inherited_keys=None):
                self._default_pkg_data = default_pkg_data
+               self._inherited_keys = inherited_keys
                self.header = {}
                self.packages = {}
                self.modified = True
@@ -678,7 +679,6 @@ class PackageIndex(object):
                self.header.update(readpkgindex(pkgfile))
 
        def readBody(self, pkgfile):
-               header_chost = self.header.get("CHOST")
                while True:
                        d = readpkgindex(pkgfile)
                        if not d:
@@ -689,8 +689,11 @@ class PackageIndex(object):
                        if self._default_pkg_data:
                                for k, v in self._default_pkg_data.iteritems():
                                        d.setdefault(k, v)
-                       if header_chost:
-                               d.setdefault("CHOST", header_chost)
+                       if self._inherited_keys:
+                               for k in self._inherited_keys:
+                                       v = self.header.get(k)
+                                       if v is not None:
+                                               d.setdefault(k, v)
                        self.packages[mycpv] = d
 
        def write(self, pkgfile):
@@ -702,11 +705,13 @@ class PackageIndex(object):
                keys = self.header.keys()
                keys.sort()
                writepkgindex(pkgfile, [(k, self.header[k]) for k in keys])
-               header_chost = self.header.get("CHOST")
                for cpv in cpv_all:
                        metadata = self.packages[cpv].copy()
-                       if metadata.get("CHOST") == header_chost:
-                               del metadata["CHOST"]
+                       if self._inherited_keys:
+                               for k in self._inherited_keys:
+                                       v = self.header.get(k)
+                                       if v is not None and v == metadata.get(k):
+                                               del metadata[k]
                        if self._default_pkg_data:
                                for k, v in self._default_pkg_data.iteritems():
                                        if metadata.get(k) == v: