self._pkg_paths = {}
self._all_directory = os.path.isdir(
os.path.join(self.pkgdir, "All"))
+ self._pkgindex = None
self._pkgindex_keys = set(["CPV", "SLOT", "MTIME", "SIZE"])
def move_ent(self, mylist):
dirs.sort()
dirs.insert(0, "All")
pkgfile = os.path.join(self.pkgdir, "Packages")
- metadata = {}
- header = {}
+ self._pkgindex = portage.getbinpkg.PackageIndex()
+ header = self._pkgindex.header
+ metadata = self._pkgindex.packages
try:
f = open(pkgfile)
except EnvironmentError:
pass
else:
try:
- header = portage.getbinpkg.readpkgindex(f)
- while True:
- d = portage.getbinpkg.readpkgindex(f)
- if not d:
- break
- mycpv = d.get("CPV")
- if not mycpv:
- continue
- d.setdefault("SLOT", "0")
- metadata[mycpv] = d
+ self._pkgindex.read(f)
finally:
f.close()
del f
stale = set(metadata).difference(cpv_all)
for cpv in stale:
del metadata[cpv]
- cpv_all.sort()
- import time
from portage.util import atomic_ofstream
- header["TIMESTAMP"] = str(long(time.time()))
- header["PACKAGES"] = str(len(cpv_all))
f = atomic_ofstream(pkgfile)
try:
- portage.getbinpkg.writepkgindex(f, header.iteritems())
- for cpv in cpv_all:
- d = metadata[cpv]
- if d["SLOT"] == "0":
- del d["SLOT"]
- portage.getbinpkg.writepkgindex(f, d.iteritems())
+ self._pkgindex.write(f)
finally:
f.close()
for k, v in items:
pkgfile.write("%s: %s\n" % (k, v))
pkgfile.write("\n")
+
+class PackageIndex(object):
+
+ def __init__(self):
+ self.header = {}
+ self.packages = {}
+
+ def read(self, pkgfile):
+ self.header.update(readpkgindex(pkgfile))
+ while True:
+ d = readpkgindex(pkgfile)
+ if not d:
+ break
+ mycpv = d.get("CPV")
+ if not mycpv:
+ continue
+ d.setdefault("SLOT", "0")
+ self.packages[mycpv] = d
+
+ def write(self, pkgfile):
+ cpv_all = self.packages.keys()
+ cpv_all.sort()
+ import time
+ self.header["TIMESTAMP"] = str(long(time.time()))
+ self.header["PACKAGES"] = str(len(cpv_all))
+ writepkgindex(pkgfile, self.header.iteritems())
+ for cpv in cpv_all:
+ metadata = self.packages[cpv]
+ if metadata["SLOT"] == "0":
+ metadata = metadata.copy()
+ del metadata["SLOT"]
+ writepkgindex(pkgfile, metadata.iteritems())