-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_tarball.py
More file actions
executable file
·42 lines (34 loc) · 1.13 KB
/
make_tarball.py
File metadata and controls
executable file
·42 lines (34 loc) · 1.13 KB
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
#!/usr/bin/env python3
import argparse
import sys
import codecs
from collections import defaultdict as dd
import re
import os.path
from lputil import mkdir_p
import shutil
import tarfile
scriptdir = os.path.dirname(os.path.abspath(__file__))
def main():
parser = argparse.ArgumentParser(description="Add files and directories to a tarfile",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--outfile", "-o",
help='path to the tarfile')
parser.add_argument("--prefix", "-p",
help='prefix to add to each file')
parser.add_argument("--infiles", "-i", nargs='+',
help='files/directories to add to the tarfile')
try:
args = parser.parse_args()
except IOError as msg:
parser.error(str(msg))
ofh = tarfile.open(name=args.outfile, mode='w:gz')
for infile in args.infiles:
if args.prefix is None:
arcname = os.path.basename(infile)
else:
arcname = os.path.join(args.prefix, os.path.basename(infile))
ofh.add(infile, arcname=arcname)
ofh.close()
if __name__ == '__main__':
main()