-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract.py
34 lines (26 loc) · 941 Bytes
/
extract.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
#!/bin/python
""" Extract files from most of common archive formats. """
import shutil
import argparse
import os
def main():
# Parse arguments
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("archive", type=str,
help='Archive file from which to extract.')
parser.add_argument("-d", "--dir-dest", type=str, default=".",
help='Direction into which extract all files.')
parser.add_argument("-k", "--keep", action='store_true',
help='Keep archive file after extraction.')
args = parser.parse_args()
extract(
archive=args.archive,
dir_dest=args.dir_dest,
keep=args.keep
)
def extract(archive, dir_dest, keep):
shutil.unpack_archive(archive, dir_dest)
if not keep:
os.remove(archive)
if __name__ == '__main__':
main()