-
Notifications
You must be signed in to change notification settings - Fork 67
/
file_utils.py
executable file
·64 lines (53 loc) · 2.35 KB
/
file_utils.py
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
62
63
64
#!/usr/bin/env python
"""
Utilities for dealing with files.
"""
__author__ = "[email protected]"
__commands__ = []
import argparse
import logging
import util.cmd
import util.file
log = logging.getLogger(__name__)
# ==============================
# *** merge_tarballs ***
# ==============================
def merge_tarballs(out_tarball, in_tarballs, threads=None, extract_to_disk_path=None, pipe_hint_in=None, pipe_hint_out=None):
''' Merges separate tarballs into one tarball
data can be piped in and/or out
'''
util.file.repack_tarballs(out_tarball, in_tarballs, threads=threads, extract_to_disk_path=extract_to_disk_path, pipe_hint_in=pipe_hint_in, pipe_hint_out=pipe_hint_out)
return 0
def parser_merge_tarballs(parser=argparse.ArgumentParser()):
parser.add_argument(
'out_tarball',
help='''output tarball (*.tar.gz|*.tar.lz4|*.tar.bz2|-);
compression is inferred by the file extension.
Note: if "-" is used, output will be written to stdout and
--pipeOutHint must be provided to indicate compression type
when compression type is not gzip (gzip is used by default).
''')
parser.add_argument(
'in_tarballs', nargs='+',
help=('input tarballs (*.tar.gz|*.tar.lz4|*.tar.bz2)')
)
parser.add_argument('--extractToDiskPath',
dest="extract_to_disk_path",
help='If specified, the tar contents will also be extracted to a local directory.')
parser.add_argument('--pipeInHint',
dest="pipe_hint_in",
default="gz",
help='If specified, the compression type used is used for piped input.')
parser.add_argument('--pipeOutHint',
dest="pipe_hint_out",
default="gz",
help='If specified, the compression type used is used for piped output.')
util.cmd.common_args(parser, (('threads', None), ('loglevel', None), ('version', None), ('tmp_dir', None)))
util.cmd.attach_main(parser, merge_tarballs, split_args=True)
return parser
__commands__.append(('merge_tarballs', parser_merge_tarballs))
# =======================
def full_parser():
return util.cmd.make_parser(__commands__, __doc__)
if __name__ == '__main__':
util.cmd.main_argparse(__commands__, __doc__)