-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_pbw.py
29 lines (24 loc) · 989 Bytes
/
extract_pbw.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
#!/usr/bin/env python
from zipfile import ZipFile
from glob import glob
import sys, logging, os.path, os
if __name__ == "__main__":
log = logging.getLogger()
logging.basicConfig(format='[%(levelname)-8s] %(message)s')
log.setLevel(logging.DEBUG)
if len(sys.argv) < 2:
log.error("Syntax: %s <one or more PBW files to unpack>" % sys.argv[0])
sys.exit(1)
for gl in sys.argv[1:]:
#Not sure if this is Windows-unique behavior.
for fn in glob(gl):
log.info("Opening %s" % fn)
basename = os.path.basename(fn)
dirname = basename[:basename.rindex(".")]
if os.path.exists(dirname):
log.warn("Skipping %s because %s exists" % (basename, dirname))
continue
log.info("Unpacking to %s" % dirname)
os.mkdir(dirname)
with ZipFile(fn, 'r') as zf:
zf.extractall(dirname)