From 67f5a7fdda5561616c50a9d481a3c06be9aed9ef Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 18 Jul 2002 11:21:25 +0000 Subject: [PATCH] More fixes for creating/extracting directories. git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/Archive@1707 66de3db3-b00d-0410-b41b-f4738ad19bea --- box.py | 8 +++++--- formats.py | 35 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/box.py b/box.py index c7320f9..4f1d77a 100644 --- a/box.py +++ b/box.py @@ -53,6 +53,8 @@ class ArchiveBox(saving.SaveBox, saving.Saveable): self.operation.connect('changed', self.op_changed) self.save_area.entry.connect('changed', self.name_changed) + + self.save_area.set_type(data.default.type) def name_changed(self, entry): if self.updating: @@ -79,9 +81,9 @@ class ArchiveBox(saving.SaveBox, saving.Saveable): self.updating = 1 name = self.save_area.entry.get_text() - for op in self.ops: - if name.endswith('.' + op.extension): - name = name[:-len(op.extension)-1] + for op2 in self.ops: + if name.endswith('.' + op2.extension): + name = name[:-len(op2.extension)-1] break if op.add_extension: name += '.' + op.extension diff --git a/formats.py b/formats.py index 9ad0774..71a649b 100644 --- a/formats.py +++ b/formats.py @@ -1,5 +1,6 @@ -import os +import os, sys from support import pipe_through_command +import rox operations = [] class Operation: @@ -43,6 +44,7 @@ class Extract(Operation): type = 'inode/directory' def __init__(self, extension, command): + "If command has a %s then the source path is inserted, else uses stdin." Operation.__init__(self, extension) self.command = command @@ -64,18 +66,19 @@ class Extract(Operation): if not os.path.exists(path): os.mkdir(path) os.chdir(path) - pipe_through_command(self.command, data.source, None) - -class ExtractPath(Extract): - "Extract an archive (which must be a file) to a directory." - def save_to_file(self, data, path): - raise Exception('Not implemented yet') + command = self.command + if command.find('%s') != -1: + # TODO: Handle path being '-' + command = command % data.path + pipe_through_command(command, data.source, None) class Archive(Operation): "Create an archive from a directory." add_extension = 1 def __init__(self, extension, command, type): + assert command.find("'%s'") != -1 + Operation.__init__(self, extension) self.command = command self.type = type @@ -86,23 +89,27 @@ class Archive(Operation): def can_handle(self, data): return isinstance(data, DirData) + def save_to_stream(self, data, stream): + os.chdir(os.path.dirname(data.path)) + command = self.command % os.path.basename(data.path) + pipe_through_command(command, None, stream) + tgz = Extract('tgz', "gunzip -c - | tar xf -") tbz = Extract('tar.bz2', "bunzip2 -c - | tar xf -") -zip = Extract('zip', "unzip -") -jar = Extract('jar', "unzip -") +jar = Extract('jar', "unzip -q -") rar = Extract('rar', "rar x -") tar = Extract('tar', "tar xf -") rpm = Extract('rpm', "rpm2cpio - | cpio -id --quiet") cpio = Extract('cpio', "cpio -id --quiet") -deb = ExtractPath('deb', "ar x '%s'") +deb = Extract('deb', "ar x '%s'") +zip = Extract('zip', "unzip -q '%s'") make_tgz = Archive('tgz', "tar cf - '%s' | gzip", 'application/x-compressed-tar') Archive('tar.gz', "tar cf - '%s' | gzip", 'application/x-compressed-tar') Archive('tar.bz', "tar cf - '%s' | bzip2", 'application/x-bzip-compressed-tar') Archive('tar.bz2', "tar cf - '%s' | bzip2", 'application/x-bzip-compressed-tar') -Archive('zip', "zip -r - '%s'", 'application/zip'), -Archive('jar', "zip -r - '%s'", 'application/x-jar') -Archive('rar', "rar a - '%s'", 'application/x-rar'), +Archive('zip', "zip -qr - '%s'", 'application/zip'), +Archive('jar', "zip -qr - '%s'", 'application/x-jar') Archive('tar', "tar cf - '%s'", 'application/x-tar') # Note: these go afterwards so that .tar.gz matches before .gz @@ -205,4 +212,4 @@ class DirData: def __init__(self, path): self.path = path self.default = make_tgz - self.default_name = path + self.default.extension + self.default_name = path + '.' + self.default.extension -- 2.11.4.GIT