summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2009-05-22 00:20:16 +0200
committerFlorian Pritz <f-p@gmx.at>2009-05-22 00:20:16 +0200
commite7eb5a6afd7d531d97b45b3a2c1105f7529a337b (patch)
tree03edc32f60d9d48b19c934c441ef125ff29ab4f7
parent2a41845a52cb2763160ba415b163d493d278c5cf (diff)
downloadbin-e7eb5a6afd7d531d97b45b3a2c1105f7529a337b.tar.gz
bin-e7eb5a6afd7d531d97b45b3a2c1105f7529a337b.tar.xz
options for a and multiple archiv types
-rwxr-xr-x[-rw-r--r--]a37
1 files changed, 31 insertions, 6 deletions
diff --git a/a b/a
index 6ec8e7d..8c139cc 100644..100755
--- a/a
+++ b/a
@@ -1,6 +1,6 @@
#!/usr/bin/python
#----------------------------------------------------
-# Version: 0.1.0
+# Version: 0.2.0
# Author: Florian "Bluewind" Pritz <f-p@gmx.at>
#
# Copyright (C) 2009 Florian Pritz
@@ -13,16 +13,41 @@
import sys
import tarfile
+from optparse import OptionParser
def main():
+ usage = "usage: %prog [options] <files>"
+ 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("-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")
+
+ (options, args) = p.parse_args()
+
+
if len(sys.argv) == 1:
- sys.stderr.write("No files specified!\n")
- sys.exit(1)
+ p.print_help()
+ sys.exit()
+
+ if options.tarname:
+ tarname = options.tarname
+ else:
+ tarname = args[0]
- tarname = sys.argv[1] + ".tar.gz"
+ if options.bz2:
+ tarname += ".tar.bz2"
+ tar = tarfile.open(tarname, "w|bz2")
+ elif options.uncompressed:
+ tarname += ".tar"
+ tar = tarfile.open(tarname, "w")
+ else:
+ tarname += ".tar.gz"
+ tar = tarfile.open(tarname, "w|gz")
- tar = tarfile.open(tarname, "w|gz")
- for name in sys.argv[1:]:
+ for name in args:
try:
tar.add(name)
except OSError: