summaryrefslogtreecommitdiffstats
path: root/a
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-01-02 16:27:11 +0100
committerFlorian Pritz <bluewind@xssn.at>2010-01-02 16:27:11 +0100
commit2771d2ba623891e54aae73098f08f085b6d971df (patch)
treef53766a2c36a7a0d60566beacb0d5e99a0101e70 /a
parentb535dcd7b6a3f0b456d8eb393feb855166d05324 (diff)
downloadbin-2771d2ba623891e54aae73098f08f085b6d971df.tar.gz
bin-2771d2ba623891e54aae73098f08f085b6d971df.tar.xz
a: fork bsdtar instead of using tarfile
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to 'a')
-rwxr-xr-xa46
1 files changed, 24 insertions, 22 deletions
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] <files>"
@@ -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)