File: __main__.py

package info (click to toggle)
lz4tools 1.3.1.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 380 kB
  • sloc: ansic: 3,988; python: 377; makefile: 8
file content (61 lines) | stat: -rwxr-xr-x 1,774 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python

import argparse
import os
import sys

try:
    import lz4tools
except ImportError:
    import __init__ as lz4tools


def compFile():
    return lz4tools.compressFileDefault(res.input, outname=res.output)


def compDir():
    return lz4tools.compressTarDefault(res.input, outname=res.output)


def decompFile():
    return lz4tools.decompressFileDefault(res.input, outname=res.output)


def outErr():
    return sys.stdout.write(''.join(['Please specify only ony of the ',
                                    'comp/decomp options']))

parser = argparse.ArgumentParser()

parser.add_argument('-f', action='store_true', dest='file',   default=False,
                    help='Compress file. Default action if input is a file.')
parser.add_argument('-t', action='store_true', dest='tar',    default=False,
                    help=''.join(['Compress directory to .tar.lz4. ',
                                  'Default action if input is a directory']))
parser.add_argument('-d', action='store_true', dest='decomp', default=False,
                    help=''.join(['Decompress. Default action if the file ',
                                  'ends in .lz4.']))
parser.add_argument('input', action='store', help='The targeted input.')
parser.add_argument('output', action='store', nargs='?', default=None,
                    help='Optional output target.')
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()
res = parser.parse_args()
if res.file:
    if res.tar or res.decomp:
        outErr()
    compFile()
elif res.tar:
    if res.decomp:
        outErr()
    compDir()
elif res.input.endswith('lz4'):
    decompFile()
elif os.path.isfile(res.input):
    compFile()
elif os.path.isdir(res.input):
    compDir()
else:
    parser.print_help()