From e7eb5a6afd7d531d97b45b3a2c1105f7529a337b Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 22 May 2009 00:20:16 +0200 Subject: options for a and multiple archiv types --- a | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) mode change 100644 => 100755 a diff --git a/a b/a old mode 100644 new mode 100755 index 6ec8e7d..8c139cc --- a/a +++ b/a @@ -1,6 +1,6 @@ #!/usr/bin/python #---------------------------------------------------- -# Version: 0.1.0 +# Version: 0.2.0 # Author: Florian "Bluewind" Pritz # # Copyright (C) 2009 Florian Pritz @@ -13,16 +13,41 @@ import sys import tarfile +from optparse import OptionParser def main(): + usage = "usage: %prog [options] " + p = OptionParser(usage) + p.add_option("-f", "--file", dest="tarname", default=False, + help="use .tar.gz instead of $1.tar.gz", metavar="") + 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: -- cgit v1.2.3-24-g4f1b