emaint binhost: support compress-index
authorZac Medico <zmedico@gentoo.org>
Thu, 9 Aug 2012 20:34:44 +0000 (13:34 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 9 Aug 2012 20:34:44 +0000 (13:34 -0700)
pym/portage/dbapi/bintree.py
pym/portage/emaint/modules/binhost/binhost.py

index 8dd7aadd4faa708307b58bdc165f725fd0b13c01..6c01867b6b7093043c511626f39d0dbb365a552c 100644 (file)
@@ -813,9 +813,7 @@ class binarytree(object):
                                del pkgindex.packages[:]
                                pkgindex.packages.extend(iter(metadata.values()))
                                self._update_pkgindex_header(pkgindex.header)
-                               f = atomic_ofstream(self._pkgindex_file)
-                               pkgindex.write(f)
-                               f.close()
+                               self._pkgindex_write(pkgindex)
 
                if getbinpkgs and not self.settings["PORTAGE_BINHOST"]:
                        writemsg(_("!!! PORTAGE_BINHOST unset, but use is requested.\n"),
@@ -1187,28 +1185,34 @@ class binarytree(object):
                        pkgindex.packages.append(d)
 
                        self._update_pkgindex_header(pkgindex.header)
-                       contents = codecs.getwriter(_encodings['repo.content'])(io.BytesIO())
-                       pkgindex.write(contents)
-                       contents = contents.getvalue()
-                       atime = mtime = long(pkgindex.header["TIMESTAMP"])
-
-                       pkgindex_filename = os.path.join(self.pkgdir, "Packages")
-                       output_files = [(atomic_ofstream(pkgindex_filename, mode="wb"), pkgindex_filename, None)]
-                       if "compress-index" in self.settings.features:
-                               gz_fname = pkgindex_filename + ".gz"
-                               fileobj = atomic_ofstream(gz_fname, mode="wb")
-                               output_files.append((GzipFile(filename='', mode="wb", fileobj=fileobj, mtime=mtime), gz_fname, fileobj))
-                       for f, fname, f_close in output_files:
-                               f.write(contents)
-                               f.close()
-                               if f_close is not None:
-                                       f_close.close()
-                               # some seconds might have elapsed since TIMESTAMP
-                               os.utime(fname, (atime, mtime))
+                       self._pkgindex_write(pkgindex)
+
                finally:
                        if pkgindex_lock:
                                unlockfile(pkgindex_lock)
 
+       def _pkgindex_write(self, pkgindex):
+               contents = codecs.getwriter(_encodings['repo.content'])(io.BytesIO())
+               pkgindex.write(contents)
+               contents = contents.getvalue()
+               atime = mtime = long(pkgindex.header["TIMESTAMP"])
+               output_files = [(atomic_ofstream(self._pkgindex_file, mode="wb"),
+                       self._pkgindex_file, None)]
+
+               if "compress-index" in self.settings.features:
+                       gz_fname = self._pkgindex_file + ".gz"
+                       fileobj = atomic_ofstream(gz_fname, mode="wb")
+                       output_files.append((GzipFile(filename='', mode="wb",
+                               fileobj=fileobj, mtime=mtime), gz_fname, fileobj))
+
+               for f, fname, f_close in output_files:
+                       f.write(contents)
+                       f.close()
+                       if f_close is not None:
+                               f_close.close()
+                       # some seconds might have elapsed since TIMESTAMP
+                       os.utime(fname, (atime, mtime))
+
        def _pkgindex_entry(self, cpv):
                """
                Performs checksums and evaluates USE flag conditionals.
index b540d76860e974cfed688e1e97efd2a9e2aa7247..c297545ccebd7c2e203662c8c3e15de2eeefa1d8 100644 (file)
@@ -151,12 +151,8 @@ class BinhostHandler(object):
 
                                del pkgindex.packages[:]
                                pkgindex.packages.extend(metadata.values())
-                               from portage.util import atomic_ofstream
-                               f = atomic_ofstream(self._pkgindex_file)
-                               try:
-                                       self._pkgindex.write(f)
-                               finally:
-                                       f.close()
+                               bintree._pkgindex_write(self._pkgindex)
+
                        finally:
                                locks.unlockfile(pkgindex_lock)