Skip to content

Instantly share code, notes, and snippets.

@asmeurer
Created May 20, 2014 18:53
Show Gist options
  • Save asmeurer/2432f6eae0689a60223e to your computer and use it in GitHub Desktop.
Save asmeurer/2432f6eae0689a60223e to your computer and use it in GitHub Desktop.
gohlke
def gohlke(src_path):
assert sys.platform == 'win32'
MAP = [
('PLATLIB/', 'Lib/site-packages/'),
('PURELIB/', 'Lib/site-packages/'),
('SCRIPTS/', 'Scripts/'),
('DATA/Lib/site-packages/', 'Lib/site-packages/'),
]
with open(join(WORK_DIR, "Gohlke.txt"), 'w') as fo:
fo.write("Source: %r" % src_path)
z = zipfile.ZipFile(src_path)
for src in z.namelist():
if src.endswith(('/', '\\')):
continue
for a, b in MAP:
if src.startswith(a):
dst = abspath(join(WORK_DIR, b + src[len(a):]))
break
else:
raise RuntimeError("Don't know how to handle file %s" % src)
dst_dir = dirname(dst)
#print 'file %r to %r' % (src, dst_dir)
if not isdir(dst_dir):
os.makedirs(dst_dir)
data = z.read(src)
with open(dst, 'wb') as fi:
fi.write(data)
z.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment