From 2771d2ba623891e54aae73098f08f085b6d971df Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 2 Jan 2010 16:27:11 +0100 Subject: a: fork bsdtar instead of using tarfile Signed-off-by: Florian Pritz --- a | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'a') diff --git a/a b/a index ccb8275..78fdae3 100755 --- a/a +++ b/a @@ -11,9 +11,9 @@ #---------------------------------------------------- import sys -import tarfile import os from optparse import OptionParser +from subprocess import Popen, PIPE def main(): usage = "usage: %prog [options] " @@ -39,32 +39,34 @@ def main(): if options.tarname: tarname = options.tarname else: - tarname = args[0] + tarname = args[0]+".tar" + tarcmd = ['bsdtar', '-c'] if options.bz2: - tarname += ".tar.bz2" - file_exists(tarname, options) - tar = tarfile.open(tarname, "w|bz2") - elif options.uncompressed or options.xz: - tarname += ".tar" - file_exists(tarname, options) - tar = tarfile.open(tarname, "w") + tarname += ".bz2" + tarcmd.extend(['-jf', tarname]) + elif options.uncompressed: + tarcmd.extend(['-f', tarname]) + elif options.xz: + tarname += ".xz" + tarcmd.extend(['-Jf', tarname]) else: - tarname += ".tar.gz" - file_exists(tarname, options) - tar = tarfile.open(tarname, "w|gz") + tarname += ".gz" + tarcmd.extend(['-zf', tarname]) - for name in args: - try: - tar.add(name) - except OSError: - sys.stderr.write("No such file or directory: '%s'\n" % name) - tar.close() - if options.xz: - os.system('xz '+tarname) + if not options.force: + file_exists(tarname) + Popen(merge([tarcmd, args]), stdout=PIPE).communicate()[0] -def file_exists(filename, options): - if os.path.exists(filename) and not options.force: +def merge(seq): + merged = [] + for s in seq: + for x in s: + merged.append(x) + return merged + +def file_exists(filename): + if os.path.exists(filename): sys.stderr.write('Target "'+filename+'" already exists. Use --force to overwrite.\n') sys.exit(1) -- cgit v1.2.3-24-g4f1b