Add bindbapi.getfetchsizes() like pordbapi has.
authorZac Medico <zmedico@gentoo.org>
Wed, 19 Oct 2011 21:19:09 +0000 (14:19 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 19 Oct 2011 21:19:09 +0000 (14:19 -0700)
pym/portage/dbapi/bintree.py

index 62fc6235410d4448e42829cf043082bd4b1656b9..5c091bd45139fe89884eae0b96211d3a94a86f2c 100644 (file)
@@ -177,6 +177,34 @@ class bindbapi(fakedbapi):
                        self.bintree.populate()
                return fakedbapi.cpv_all(self)
 
+       def getfetchsizes(self, pkg):
+               """
+               This will raise MissingSignature if SIZE signature is not available,
+               or InvalidSignature if SIZE signature is invalid.
+               """
+
+               if not self.bintree.populated:
+                       self.bintree.populate()
+
+               pkg = getattr(pkg, 'cpv', pkg)
+
+               filesdict = {}
+               if not self.bintree.isremote(pkg):
+                       pass
+               else:
+                       metadata = self.bintree._remotepkgs[pkg]
+                       try:
+                               size = int(metadata["SIZE"])
+                       except KeyError:
+                               raise portage.exception.MissingSignature("SIZE")
+                       except ValueError:
+                               raise portage.exception.InvalidSignature(
+                                       "SIZE: %s" % metadata["SIZE"])
+                       else:
+                               filesdict[os.path.basename(self.bintree.getname(pkg))] = size
+
+               return filesdict
+
 def _pkgindex_cpv_map_latest_build(pkgindex):
        """
        Given a PackageIndex instance, create a dict of cpv -> metadata map.