import zlib
from constants import *
+from i18n import _
PROGRESS_WIDGETS = [
progressbar.Bar(left="[", right="]"),
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()
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.
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")
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"
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 ""
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 ""
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 ""