Pass default package metadata values into the PackageIndex
authorZac Medico <zmedico@gentoo.org>
Fri, 12 Oct 2007 00:38:35 +0000 (00:38 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 12 Oct 2007 00:38:35 +0000 (00:38 -0000)
constructor for optional things like EAPI and SLOT.

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

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

index 629788544841eddfabf83039e8232209a5f9b63f..88ad066035d330584a24e901051d2fea56d10da6 100644 (file)
@@ -152,6 +152,13 @@ class binarytree(object):
                        self._pkgindex_header_keys = set(["ACCEPT_KEYWORDS", "CBUILD",
                                "CHOST", "CONFIG_PROTECT", "CONFIG_PROTECT_MASK", "FEATURES",
                                "GENTOO_MIRRORS", "INSTALL_MASK", "SYNC", "USE"])
+                       self._pkgindex_default_pkg_data = {
+                               "EAPI"    : "0",
+                               "IUSE"    : "",
+                               "PROVIDE" : "",
+                               "SLOT"    : "0",
+                               "USE"     : ""
+                       }
 
        def move_ent(self, mylist):
                if not self.populated:
@@ -360,7 +367,8 @@ class binarytree(object):
                                dirs.remove("All")
                        dirs.sort()
                        dirs.insert(0, "All")
-                       pkgindex = portage.getbinpkg.PackageIndex()
+                       pkgindex = portage.getbinpkg.PackageIndex(
+                               default_pkg_data=self._pkgindex_default_pkg_data)
                        pf_index = None
                        try:
                                f = open(self._pkgindex_file)
@@ -373,7 +381,8 @@ class binarytree(object):
                                        f.close()
                                        del f
                        if not self._pkgindex_version_supported(pkgindex):
-                               pkgindex = portage.getbinpkg.PackageIndex()
+                               pkgindex = portage.getbinpkg.PackageIndex(
+                                       default_pkg_data=self._pkgindex_default_pkg_data)
                        header = pkgindex.header
                        metadata = pkgindex.packages
                        update_pkgindex = False
@@ -556,7 +565,8 @@ class binarytree(object):
                        urldata = urlparse(base_url)
                        pkgindex_file = os.path.join(CACHE_PATH, "binhost",
                                urldata[1] + urldata[2], "Packages")
-                       pkgindex = portage.getbinpkg.PackageIndex()
+                       pkgindex = portage.getbinpkg.PackageIndex(
+                               default_pkg_data=self._pkgindex_default_pkg_data)
                        try:
                                f = open(pkgindex_file)
                                try:
@@ -568,7 +578,8 @@ class binarytree(object):
                                        raise
                        local_timestamp = pkgindex.header.get("TIMESTAMP", None)
                        import urllib, urlparse
-                       rmt_idx = portage.getbinpkg.PackageIndex()
+                       rmt_idx = portage.getbinpkg.PackageIndex(
+                               default_pkg_data=self._pkgindex_default_pkg_data)
                        try:
                                f = urllib.urlopen(urlparse.urljoin(base_url, "Packages"))
                                try:
@@ -711,7 +722,8 @@ 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()
+                       pkgindex = portage.getbinpkg.PackageIndex(
+                               default_pkg_data=self._pkgindex_default_pkg_data)
                        try:
                                f = open(self._pkgindex_file)
                        except EnvironmentError:
@@ -723,7 +735,8 @@ class binarytree(object):
                                        f.close()
                                        del f
                        if not self._pkgindex_version_supported(pkgindex):
-                               pkgindex = portage.getbinpkg.PackageIndex()
+                               pkgindex = portage.getbinpkg.PackageIndex(
+                                       default_pkg_data=self._pkgindex_default_pkg_data)
                        d = digests
                        d["CPV"] = cpv
                        d["SLOT"] = slot
index a248e378b7159b5b6608c32264664239a989d7ef..108161c0265fcfb5cdfeb1a19750ba597fc8eff3 100644 (file)
@@ -664,7 +664,8 @@ def writepkgindex(pkgfile, items):
 
 class PackageIndex(object):
 
-       def __init__(self):
+       def __init__(self, default_pkg_data=None):
+               self._default_pkg_data = default_pkg_data
                self.header = {}
                self.packages = {}
                self.modified = True
@@ -685,11 +686,9 @@ class PackageIndex(object):
                        mycpv = d.get("CPV")
                        if not mycpv:
                                continue
-                       d.setdefault("EAPI", "0")
-                       d.setdefault("IUSE", "")
-                       d.setdefault("PROVIDE", "")
-                       d.setdefault("SLOT", "0")
-                       d.setdefault("USE", "")
+                       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)
                        self.packages[mycpv] = d
@@ -708,10 +707,10 @@ class PackageIndex(object):
                        metadata = self.packages[cpv].copy()
                        if metadata.get("CHOST") == header_chost:
                                del metadata["CHOST"]
-                       if metadata.get("EAPI") == "0":
-                               del metadata["EAPI"]
-                       if metadata.get("SLOT") == "0":
-                               del metadata["SLOT"]
+                       if self._default_pkg_data:
+                               for k, v in self._default_pkg_data.iteritems():
+                                       if metadata.get(k) == v:
+                                               metadata.pop(k, None)
                        keys = metadata.keys()
                        keys.sort()
                        writepkgindex(pkgfile,