summaryrefslogtreecommitdiffstats
path: root/a
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2009-06-01 12:29:10 +0200
committerFlorian Pritz <f-p@gmx.at>2009-06-01 12:29:10 +0200
commit7e5113cfc7cf3ff51ffb8bb9191c8fb4a0251d9e (patch)
tree008902b20496f52286361b079c423fe817cff490 /a
parent5b7508b249db3624967da43c8fa575740babcecd (diff)
downloadbin-7e5113cfc7cf3ff51ffb8bb9191c8fb4a0251d9e.tar.gz
bin-7e5113cfc7cf3ff51ffb8bb9191c8fb4a0251d9e.tar.xz
add xz compression and file exists check
Diffstat (limited to 'a')
-rwxr-xr-xa19
1 files changed, 17 insertions, 2 deletions
diff --git a/a b/a
index e48ce2b..ccb8275 100755
--- a/a
+++ b/a
@@ -1,6 +1,6 @@
#!/usr/bin/python
#----------------------------------------------------
-# Version: 0.2.0
+# Version: 0.2.1
# Author: Florian "Bluewind" Pritz <f-p@gmx.at>
#
# Licensed under WTFPL v2
@@ -12,6 +12,7 @@
import sys
import tarfile
+import os
from optparse import OptionParser
def main():
@@ -19,10 +20,14 @@ def main():
p = OptionParser(usage)
p.add_option("-f", "--file", dest="tarname", default=False,
help="use <file>.tar.gz instead of $1.tar.gz", metavar="<file>")
+ p.add_option("--force", action="store_true", dest="force", default=False,
+ help="overwrite existing target files")
p.add_option("-b", "--bzip2", action="store_true", dest="bz2", default=False,
help="use bzip2 compression")
p.add_option("-u", "--uncompressed", action="store_true", dest="uncompressed", default=False,
help="don't use compression at all")
+ p.add_option("-x", "--xz", action="store_true", dest="xz", default=False,
+ help="use xz compression")
(options, args) = p.parse_args()
@@ -38,12 +43,15 @@ def main():
if options.bz2:
tarname += ".tar.bz2"
+ file_exists(tarname, options)
tar = tarfile.open(tarname, "w|bz2")
- elif options.uncompressed:
+ elif options.uncompressed or options.xz:
tarname += ".tar"
+ file_exists(tarname, options)
tar = tarfile.open(tarname, "w")
else:
tarname += ".tar.gz"
+ file_exists(tarname, options)
tar = tarfile.open(tarname, "w|gz")
for name in args:
@@ -52,6 +60,13 @@ def main():
except OSError:
sys.stderr.write("No such file or directory: '%s'\n" % name)
tar.close()
+ if options.xz:
+ os.system('xz '+tarname)
+
+def file_exists(filename, options):
+ if os.path.exists(filename) and not options.force:
+ sys.stderr.write('Target "'+filename+'" already exists. Use --force to overwrite.\n')
+ sys.exit(1)
if __name__ == '__main__':
main()