| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import argparse |
| 4 |
import os |
| 5 |
import sys |
| 6 |
|
| 7 |
try: |
| 8 |
import lz4tools |
| 9 |
except ImportError: |
| 10 |
import __init__ as lz4tools |
| 11 |
|
| 12 |
|
| 13 |
def compFile(): |
| 14 |
return lz4tools.compressFileDefault(res.input, outname=res.output) |
| 15 |
|
| 16 |
|
| 17 |
def compDir(): |
| 18 |
return lz4tools.compressTarDefault(res.input, outname=res.output) |
| 19 |
|
| 20 |
|
| 21 |
def decompFile(): |
| 22 |
return lz4tools.decompressFileDefault(res.input, outname=res.output) |
| 23 |
|
| 24 |
|
| 25 |
def outErr(): |
| 26 |
return sys.stdout.write(''.join(['Please specify only ony of the ', |
| 27 |
'comp/decomp options'])) |
| 28 |
|
| 29 |
parser = argparse.ArgumentParser() |
| 30 |
|
| 31 |
parser.add_argument('-f', action='store_true', dest='file', default=False, |
| 32 |
help='Compress file. Default action if input is a file.') |
| 33 |
parser.add_argument('-t', action='store_true', dest='tar', default=False, |
| 34 |
help=''.join(['Compress directory to .tar.lz4. ', |
| 35 |
'Default action if input is a directory'])) |
| 36 |
parser.add_argument('-d', action='store_true', dest='decomp', default=False, |
| 37 |
help=''.join(['Decompress. Default action if the file ', |
| 38 |
'ends in .lz4.'])) |
| 39 |
parser.add_argument('input', action='store', help='The targeted input.') |
| 40 |
parser.add_argument('output', action='store', nargs='?', default=None, |
| 41 |
help='Optional output target.') |
| 42 |
if len(sys.argv) == 1: |
| 43 |
parser.print_help() |
| 44 |
sys.exit() |
| 45 |
res = parser.parse_args() |
| 46 |
if res.file: |
| 47 |
if res.tar or res.decomp: |
| 48 |
outErr() |
| 49 |
compFile() |
| 50 |
elif res.tar: |
| 51 |
if res.decomp: |
| 52 |
outErr() |
| 53 |
compDir() |
| 54 |
elif res.input.endswith('lz4'): |
| 55 |
decompFile() |
| 56 |
elif os.path.isfile(res.input): |
| 57 |
compFile() |
| 58 |
elif os.path.isdir(res.input): |
| 59 |
compDir() |
| 60 |
else: |
| 61 |
parser.print_help() |