2008/9/9 Stefano Zacchiroli <[EMAIL PROTECTED]> > Unfortunately not, thus far I haven't been able to try out the solution > (4) mentioned in the bug log to, which looks like the most likely to be > successful. > > If you want to help, feel free to try it out and provide a patch. If you > can't do that, even only verifying whether all the methods of the > file-like interface we use are supported by tarfile would help. >
Done and attached :-) The biggest problem is that Tarfile's __init__ method doesn't actually allow for "r:bz2" opening (who knows why... and it's not recommended in general for use by the Python 2.5.1 docs I have locally), but if you call Tarfile.open() instead, then that does and it returns a new Tarfile object. Right now I'm just fixing the tgz() method so it does the right thing when it has a .bz2 instead, but you may wish to rename this method as well.... Tom Parker
diff --git a/debian_bundle/debfile.py b/debian_bundle/debfile.py index df0742e..5b5ff4f 100644 --- a/debian_bundle/debfile.py +++ b/debian_bundle/debfile.py @@ -24,8 +24,9 @@ from arfile import ArFile, ArError from changelog import Changelog from deb822 import Deb822 -DATA_PART = 'data.tar.gz' -CTRL_PART = 'control.tar.gz' +DATA_PART = 'data.tar' +CTRL_PART = 'control.tar' +ALLOWED_ENDINGS = [".gz", ".bz2"] INFO_PART = 'debian-binary' MAINT_SCRIPTS = ['preinst', 'postinst', 'prerm', 'postrm', 'config'] @@ -64,8 +65,15 @@ class DebPart(object): package.""" if self.__tgz is None: - gz = gzip.GzipFile(fileobj=self.__member, mode='r') - self.__tgz = tarfile.TarFile(fileobj=gz, mode='r') + if self.__member.name == "data.tar.gz": + gz = gzip.GzipFile(fileobj=self.__member, mode='r') + self.__tgz = tarfile.TarFile(fileobj=gz, mode='r') + elif self.__member.name == "data.tar.bz2": + # Tarfile's __init__ doesn't allow for r:bz2 modes, but the open() classmethod does... + self.__tgz = tarfile.open(fileobj=self.__member, mode='r:bz2') + else: + raise DebError("Unable to handle %s"%self.__member.name) + return self.__tgz @staticmethod @@ -192,16 +200,20 @@ class DebFile(ArFile): def __init__(self, filename=None, mode='r', fileobj=None): ArFile.__init__(self, filename, mode, fileobj) - required_names = set([INFO_PART, CTRL_PART, DATA_PART]) actual_names = set(self.getnames()) - if not (required_names <= actual_names): - raise DebError( - "the following required .deb members are missing: " \ - + string.join(required_names - actual_names)) - + if INFO_PART not in actual_names: + raise DebError("%s is missing from the .deb "%INFO_PART) self.__parts = {} - self.__parts[CTRL_PART] = DebControl(self.getmember(CTRL_PART)) - self.__parts[DATA_PART] = DebData(self.getmember(DATA_PART)) + for name in (CTRL_PART,DATA_PART): + for possible in actual_names: + if possible.find(name)==0 and possible[len(name):] in ALLOWED_ENDINGS: + self.__parts[name] = possible # temporary storage of correct name + break + else: + raise DebError("A %s* file is missing from the .deb "%name) + + self.__parts[CTRL_PART] = DebControl(self.getmember(self.__parts[CTRL_PART])) + self.__parts[DATA_PART] = DebData(self.getmember(self.__parts[DATA_PART])) self.__pkgname = None # updated lazily by __updatePkgName f = self.getmember(INFO_PART)