From e00ce2208fa0a22249033db538886c10fbbfbe31 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Mon, 22 May 2006 22:52:51 +0000 Subject: [PATCH] this commit adds nothing, just removes zipfileext and pylzma code. --- pisi/archive.py | 16 +-- pisi/cli/commands.py | 8 -- pisi/file.py | 10 +- pisi/lockeddbshelve.py | 9 -- pisi/zipfileext.py | 305 ----------------------------------------- 5 files changed, 9 insertions(+), 339 deletions(-) delete mode 100644 pisi/zipfileext.py diff --git a/pisi/archive.py b/pisi/archive.py index 85f9d058..8d361ac6 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -17,7 +17,7 @@ import os import stat import shutil import tarfile -import zipfileext +import zipfile import gettext __trans = gettext.translation('pisi', fallback=True) @@ -102,12 +102,11 @@ class ArchiveZip(ArchiveBase): zip archives.""" symmagic = 2716663808 #long of hex val '0xA1ED0000L' - comp_method = {'lzma': zipfileext.ZIP_LZMA_BOGUS, 'deflated': zipfileext.ZIP_DEFLATED} def __init__(self, file_path, arch_type = "zip", mode = 'r'): super(ArchiveZip, self).__init__(file_path, arch_type) - self.zip_obj = zipfileext.ZipFileExt(self.file_path, mode) + self.zip_obj = zipfile.ZipFile(self.file_path, mode) def close(self): """Close the zip archive.""" @@ -126,20 +125,13 @@ class ArchiveZip(ArchiveBase): else: if os.path.islink(file_name): dest = os.readlink(file_name) - attr = zipfileext.ZipInfo() + attr = zipfile.ZipInfo() attr.filename = file_name attr.create_system = 3 attr.external_attr = self.symmagic self.zip_obj.writestr(attr, dest) else: - method = ctx.get_option('compression_method') - if not method: - method = 'lzma' - if method == 'lzma': - self.zip_obj.write(file_name, arc_name, zipfileext.ZIP_LZMA_BOGUS, - dictionary = 26, fastBytes = 64) - else: - self.zip_obj.write(file_name, arc_name, self.comp_method[method]) + self.zip_obj.write(file_name, arc_name, zipfile.ZIP_DEFLATED) if not arc_name: zinfo = self.zip_obj.getinfo(file_name) diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 95e3bbb2..6a96650a 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -356,8 +356,6 @@ unpack, setup, build, install, package steps = ('unpack', 'setup', 'build', 'install', 'package') - compression_methods = ('deflated', 'lzma') - def options(self): buildno_opts(self) abandoned_files_opt(self) @@ -379,9 +377,6 @@ unpack, setup, build, install, package default=False, help=_("don't create a debug package with debug files")) self.parser.add_option("", "--no-install", action="store_true", default=False, help=_("don't install build dependencies, fail if a build dependency is present")) - self.parser.add_option("-C", "--compression-method", action="store", default='lzma', - help=_("package compression method")) - def run(self): if not self.args: @@ -399,9 +394,6 @@ unpack, setup, build, install, package else: self.init() - if ctx.get_option('compression_method') not in Build.compression_methods: - raise Error(_('compression_method must be one of %s ') % pisi.util.strlist(Build.compression_methods)) - if ctx.get_option('output_dir'): ctx.ui.info(_('Output directory: %s') % ctx.config.options.output_dir) else: diff --git a/pisi/file.py b/pisi/file.py index 7455148d..82d0c45c 100644 --- a/pisi/file.py +++ b/pisi/file.py @@ -55,7 +55,7 @@ class InvalidSignature(pisi.Error): class File: (read, write) = range(2) # modes - (bz2, lzma) = range(2) # compress enums + (bz2, zip) = range(2) # compress enums (detached, whatelse) = range(2) @@ -77,8 +77,8 @@ class File: open(localfile[:-4], "w").write(bz2.BZ2File(localfile).read()) localfile = localfile[:-4] - elif compress == File.lzma: - raise Error(_("lzma compression not supported yet")) + elif compress == File.zip: + raise Error(_("zip compression not supported yet")) return localfile @@ -172,8 +172,8 @@ class File: compressed_file = self.localfile + ".bz2" bz2.BZ2File(compressed_file, "w").write(open(self.localfile, "r").read()) - elif self.compress == File.lzma: - raise Error(_("lzma compression not supported yet")) + elif self.compress == File.zip: + raise Error(_("zip compression not supported yet")) if self.sha1sum: sha1 = pisi.util.sha1_file(self.localfile) diff --git a/pisi/lockeddbshelve.py b/pisi/lockeddbshelve.py index 589f6e21..fe80ec5a 100644 --- a/pisi/lockeddbshelve.py +++ b/pisi/lockeddbshelve.py @@ -108,15 +108,6 @@ def init_dbenv(write=False, writeversion=False): class LockedDBShelf(shelve.DBShelf): """A simple wrapper to implement locking for bsddb's dbshelf""" -# def decode(self, data): -# try: -# return cPickle.loads(pylzma.decompress(data)) -# except: -# raise shelve.CodingError() - -# def encode(self, obj): -# return pylzma.compress(cPickle.dumps(obj, 1), algorithm=0) - def __init__(self, dbname, mode=0644, filetype=db.DB_BTREE, dbenv = None): if dbenv == None: diff --git a/pisi/zipfileext.py b/pisi/zipfileext.py deleted file mode 100644 index 2ddc4e9c..00000000 --- a/pisi/zipfileext.py +++ /dev/null @@ -1,305 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2006, TUBITAK/UEKAE -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 2 of the License, or (at your option) -# any later version. -# -# Please read the COPYING file. -# -# Authors: Eray Ozkural -# Faik Uygur -# -# Extends zipfile module with lzma and bzip2 support - -# python standard library modules -import os -import struct -import time -import binascii - -from zipfile import * - -try: - import zlib -except ImportError: - zlib = None - -try: - import bzip2 -except ImportError: - bzip2 = None - -try: - import pylzma -except ImportError: - pylzma = None - -ZIP_BZIP2 = 12 -ZIP_LZMA_BOGUS = 255 - -compression_methods = [ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2, ZIP_LZMA_BOGUS] - -class FileEntry: - """File-like object used to access entries in a ZipFile""" - - def __init__(self, fp, length): - self.fp = fp - self.readBytes = 0 - self.returnedBytes = 0 - self.length = length - self.finished = 0 - -class LzmaFileEntry(FileEntry): - """File-like object used to read a LZMA entry in a ZipFile""" - - def __init__(self, fp, length): - FileEntry.__init__(self, fp, length) - self.decomp = pylzma.decompressobj() - self.buffer = "" - - def tell(self): - return self.returnedBytes - - def read(self, n=None): - if self.finished: - return "" - if n is None: - result = [self.buffer,] - result.append(self.decomp.decompress(self.fp.read(self.length - self.readBytes))) - result.append(self.decomp.flush()) - self.buffer = "" - self.finished = 1 - result = "".join(result) - self.returnedBytes += len(result) - return result - else: - while len(self.buffer) < n: - data = self.fp.read(min(n, 1024, self.length - self.readBytes)) - self.readBytes += len(data) - if not data: - result = self.buffer + self.decomp.decompress() + self.decomp.flush() - self.finished = 1 - self.buffer = "" - self.returnedBytes += len(result) - return result - else: - self.buffer += self.decomp.decompress(data) - result = self.buffer[:n] - self.buffer = self.buffer[n:] - self.returnedBytes += len(result) - return result - - def close(self): - self.finished = 1 - del self.fp - -class ZipFileEntry(FileEntry): - """File-like object used to read an uncompressed entry in a ZipFile""" - - def __init__(self, fp, length): - FileEntry.__init__(self, fp, length) - - def tell(self): - return self.readBytes - - def read(self, n=None): - if n is None: - n = self.length - self.readBytes - if n == 0 or self.finished: - return '' - - data = self.fp.read(n) - self.readBytes += len(data) - if self.readBytes == self.length or len(data) < n: - self.finished = 1 - return data - - def close(self): - self.finished = 1 - del self.fp - - -class DeflatedZipFileEntry(FileEntry): - """File-like object used to read a deflated entry in a ZipFile""" - - def __init__(self, fp, length): - FileEntry.__init__(self, fp, length) - self.decomp = zlib.decompressobj(-15) - self.buffer = "" - - def tell(self): - return self.returnedBytes - - def read(self, n=None): - if self.finished: - return "" - if n is None: - result = [self.buffer,] - result.append(self.decomp.decompress(self.fp.read(self.length - self.readBytes))) - result.append(self.decomp.decompress("Z")) - result.append(self.decomp.flush()) - self.buffer = "" - self.finished = 1 - result = "".join(result) - self.returnedBytes += len(result) - return result - else: - while len(self.buffer) < n: - data = self.fp.read(min(n, 1024, self.length - self.readBytes)) - self.readBytes += len(data) - if not data: - result = self.buffer + self.decomp.decompress("Z") + self.decomp.flush() - self.finished = 1 - self.buffer = "" - self.returnedBytes += len(result) - return result - else: - self.buffer += self.decomp.decompress(data) - result = self.buffer[:n] - self.buffer = self.buffer[n:] - self.returnedBytes += len(result) - return result - - def close(self): - self.finished = 1 - del self.fp - -class ZipFileExt(ZipFile): - - def _writecheck(self, zinfo): - """Check for errors before writing a file to the archive.""" - if zinfo.filename in self.NameToInfo: - if self.debug: # Warning for duplicate names - print "Duplicate name:", zinfo.filename - if self.mode not in ("w", "a"): - raise RuntimeError, 'write() requires mode "w" or "a"' - if not self.fp: - raise RuntimeError, \ - "Attempt to write ZIP archive that was already closed" - if zinfo.compress_type not in compression_methods: - raise RuntimeError, \ - "Compression method %s is not supported" % zinfo.compress_type - if zinfo.compress_type == ZIP_DEFLATED and not zlib: - raise RuntimeError, \ - "Compression requires the (missing) zlib module" - if zinfo.compress_type == ZIP_BZIP2 and not bzip2: - raise RuntimeError, \ - "Compression requires the (missing) bzip2 module" - if zinfo.compress_type == ZIP_LZMA_BOGUS and not pylzma: - raise RuntimeError, \ - "Compression requires the (missing) pylzma module" - - def write(self, filename, arcname=None, compress_type=None, **kwargs): - """Put the bytes from filename into the archive under the name - arcname.""" - st = os.stat(filename) - mtime = time.localtime(st.st_mtime) - date_time = mtime[0:6] - # Create ZipInfo instance to store file information - if arcname is None: - zinfo = ZipInfo(filename, date_time) - else: - zinfo = ZipInfo(arcname, date_time) - zinfo.external_attr = (st[0] & 0xFFFF) << 16L # Unix attributes - if compress_type is None: - zinfo.compress_type = self.compression - else: - zinfo.compress_type = compress_type - self._writecheck(zinfo) - fp = open(filename, "rb") - zinfo.flag_bits = 0x00 - zinfo.header_offset = self.fp.tell() # Start of header bytes - # Must overwrite CRC and sizes with correct data later - zinfo.CRC = CRC = 0 - zinfo.compress_size = compress_size = 0 - zinfo.file_size = file_size = 0 - self.fp.write(zinfo.FileHeader()) - zinfo.file_offset = self.fp.tell() # Start of file bytes - - # really compress - if zinfo.compress_type == ZIP_DEFLATED or zinfo.compress_type == ZIP_STORED: - if zinfo.compress_type == ZIP_DEFLATED: - cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, - zlib.DEFLATED, -15) - else: - cmpr = None - - while 1: - buf = fp.read(1024 * 8) - if not buf: - break - file_size = file_size + len(buf) - CRC = binascii.crc32(buf, CRC) - if cmpr: - buf = cmpr.compress(buf) - compress_size = compress_size + len(buf) - self.fp.write(buf) - fp.close() - if cmpr: - buf = cmpr.flush() - compress_size = compress_size + len(buf) - self.fp.write(buf) - zinfo.compress_size = compress_size - else: - zinfo.compress_size = file_size - - elif zinfo.compress_type == ZIP_LZMA_BOGUS: - # unfortunately pylzma.compressobj is not implemented yet. - # So in order to calculate the CRC, we are going to read - # all the file at once until it is implemented. - buf = fp.read() - file_size = len(buf) - CRC = binascii.crc32(buf, CRC) - compressed = pylzma.compress(buf, **kwargs) - self.fp.write(compressed) - zinfo.compress_size = len(compressed) - - zinfo.CRC = CRC - zinfo.file_size = file_size - # Seek backwards and write CRC and file sizes - position = self.fp.tell() # Preserve current position in file - self.fp.seek(zinfo.header_offset + 14, 0) - self.fp.write(struct.pack("