-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsplitarc.py
executable file
·51 lines (40 loc) · 1.26 KB
/
unsplitarc.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
#!/usr/bin/env python3
from __future__ import print_function
import os
import sys
from zipfile import ZipFile, BadZipFile
"""
Extract all files from a series of archives to the same directory,
MERGING and OVERWRITING anywhere the files from previous archives have
the same relative paths and names.
unsplitarc.py <source> <destination>
source This should be a directory containing zip files.
destination This can be any directory, but must exist already.
"""
def echo0(*args, **kwargs):
kwargs['file'] = sys.stderr
print(*args, **kwargs)
def usage():
print("Usage:")
print(__doc__)
def unsplit_arc(src, dst):
for sub in os.listdir(src):
sub_path = os.path.join(src, sub)
try:
with ZipFile(sub_path, 'r') as thisZip:
thisZip.extractall(dst)
except BadZipFile:
echo0("* ERROR: {} is a BadZipFile".format(sub_path))
def main():
if len(sys.argv) < 2:
usage()
echo0("You must specify a source and target directory.")
return 1
if len(sys.argv) < 3:
usage()
echo0("You must also specify a target directory.")
return 1
unsplit_arc(sys.argv[1], sys.argv[2])
return 0
if __name__ == "__main__":
sys.exit(main())