#!/usr/bin/python #---------------------------------------------------- # Version: 0.2.0 # Author: Florian "Bluewind" Pritz # # Licensed under WTFPL v2 # (see COPYING for full license text) # #---------------------------------------------------- # got bored and a.sh has some problems with spaces #---------------------------------------------------- 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: p.print_help() sys.exit() if options.tarname: tarname = options.tarname else: tarname = args[0] 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") for name in args: try: tar.add(name) except OSError: sys.stderr.write("No such file or directory: '%s'\n" % name) tar.close() if __name__ == '__main__': main()