]> git.ipfire.org Git - pakfire.git/commitdiff
Add support for package compression (again).
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Aug 2011 15:25:33 +0000 (17:25 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Aug 2011 15:25:33 +0000 (17:25 +0200)
pakfire/compress.py
pakfire/packages/packager.py
po/pakfire.pot

index 57d0266c68e2f791fc5f4b67609c9227edad106e..a432e076d5ebf6427547450046d4b29e551b7e81 100644 (file)
@@ -25,6 +25,7 @@ import progressbar
 import zlib
 
 from constants import *
+from i18n import _
 
 PROGRESS_WIDGETS = [
        progressbar.Bar(left="[", right="]"),
@@ -112,3 +113,63 @@ def decompressobj(i, o, algo="xz", progress=None):
 
        return __compress_helper(i, o, comp.decompress, comp.flush, progress=progress)
 
+def compress_file(inputfile, outputfile, message="", algo="xz", progress=True):
+       """
+               Compress a file in place.
+       """
+       assert os.path.exists(inputfile)
+
+       # Get total size of the file for the progressbar.
+       total_size = os.path.getsize(inputfile)
+
+       # Open the input file for reading.
+       i = open(inputfile, "r")
+
+       # Open the output file for wrinting.
+       o = open(outputfile, "w")
+
+       if progress:
+               if not message:
+                       message = _("Compressing %s") % os.path.basename(filename)
+
+               progress = progressbar.ProgressBar(
+                       widgets = ["%-40s" % message, " ",] + PROGRESS_WIDGETS,
+                       maxval = total_size,
+               )
+
+               progress.start()
+
+       if algo == "xz":
+               compressor = lzma.LZMACompressor()
+       elif algo == "zlib":
+               comp = zlib.decompressobj(9)
+       else:
+               raise Exception, "Unknown compression choosen: %s" % algo
+
+       size = 0
+       while True:
+               buf = i.read(BUFFER_SIZE)
+               if not buf:
+                       break
+
+               # Update progressbar.
+               size += len(buf)
+               if progress:
+                       progress.update(size)
+
+               # Compress the bits in buf.
+               buf = compressor.compress(buf)
+
+               # Write the compressed output.
+               o.write(buf)
+
+       # Flush all buffers.
+       buf = compressor.flush()
+       o.write(buf)
+
+       # Close the progress bar.
+       if progress:
+               progress.finish()
+
+       i.close()
+       o.close()
index ba8017edb3abadf43d850bce47dbb241d386ebc5..c5a1fbee3850783bc7154bdc0f5df0cbdcebc8b1 100644 (file)
@@ -455,7 +455,17 @@ class BinaryPackager(Packager):
                return configsfile
 
        def compress_datafile(self, datafile, algo="xz"):
-               pass
+               outputfile = self.mktemp()
+
+               # Compress the datafile with the choosen algorithm.
+               pakfire.compress.compress_file(datafile, outputfile, algo=algo,
+                       progress=True, message=_("Compressing %s") % self.pkg.friendly_name)
+
+               # We do not need the uncompressed output anymore.
+               os.unlink(datafile)
+
+               # The outputfile becomes out new datafile.
+               return outputfile
 
        def run(self, resultdir):
                # Add all files to this package.
@@ -471,7 +481,7 @@ class BinaryPackager(Packager):
                metafile = self.create_metafile(datafile)
 
                # XXX make xz in variable
-               self.compress_datafile(datafile, algo="xz")
+               datafile = self.compress_datafile(datafile, algo="xz")
 
                # Add files to the tar archive in correct order.
                self.add(metafile, "info")
index 9d9b148e48f0c4fa43137bcd27bb7b971d1cefa1..c1e7940712ec0ab474fe70632b54b97df25a633e 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-08-28 21:19+0200\n"
+"POT-Creation-Date: 2011-08-29 17:25+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -82,22 +82,22 @@ msgid "Package information:"
 msgstr ""
 
 #. Copy the makefile and load source tarballs.
-#: ../pakfire/builder.py:307
+#: ../pakfire/builder.py:261
 msgid "Extracting"
 msgstr ""
 
-#: ../pakfire/builder.py:599
+#: ../pakfire/builder.py:551
 msgid "The build command failed. See logfile for details."
 msgstr ""
 
 #. Package the result.
 #. Make all these little package from the build environment.
-#: ../pakfire/builder.py:745
+#: ../pakfire/builder.py:697
 msgid "Creating packages:"
 msgstr ""
 
 #. Execute the buildscript of this stage.
-#: ../pakfire/builder.py:756
+#: ../pakfire/builder.py:708
 #, python-format
 msgid "Running stage %s:"
 msgstr ""
@@ -334,6 +334,11 @@ msgstr ""
 msgid "Do not verify build dependencies."
 msgstr ""
 
+#: ../pakfire/compress.py:133 ../pakfire/packages/packager.py:462
+#, python-format
+msgid "Compressing %s"
+msgstr ""
+
 #: ../pakfire/errors.py:30
 msgid "An unhandled error occured."
 msgstr ""
@@ -460,11 +465,11 @@ msgid "Package version is undefined."
 msgstr ""
 
 #. Load progressbar.
-#: ../pakfire/packages/packager.py:309
+#: ../pakfire/packages/packager.py:288
 msgid "Packaging"
 msgstr ""
 
-#: ../pakfire/packages/packager.py:590
+#: ../pakfire/packages/packager.py:579
 #, python-format
 msgid "Building source package %s:"
 msgstr ""