diff options
| author | Stefan Behnel <stefan_ml@behnel.de> | 2014-01-19 08:22:01 +0100 |
|---|---|---|
| committer | Stefan Behnel <stefan_ml@behnel.de> | 2014-01-19 08:22:01 +0100 |
| commit | 930371bd85dff98a2dda9aab5d4e2f7938248410 (patch) | |
| tree | fd8585059214afdfd70d213115be923d11d216f9 /buildlibxml.py | |
| parent | 3c5163cde3b311156ebf91043b4fc96ed7bf3dc7 (diff) | |
| download | python-lxml-930371bd85dff98a2dda9aab5d4e2f7938248410.tar.gz | |
auto-detect top-level directory of downloaded zip files in static MSWindows build
Diffstat (limited to 'buildlibxml.py')
| -rw-r--r-- | buildlibxml.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/buildlibxml.py b/buildlibxml.py index 81a5de0e..8b883652 100644 --- a/buildlibxml.py +++ b/buildlibxml.py @@ -49,18 +49,37 @@ def download_and_extract_zlatkovic_binaries(destdir): return libs + +def find_top_dir_of_zipfile(zipfile): + topdir = None + files = [f.filename for f in zipfile.filelist] + dirs = [d for d in files if d.endswith('/')] + if dirs: + dirs.sort(key=len) + topdir = dirs[0] + topdir = topdir[:topdir.index("/")+1] + for path in files: + if not path.startswith(topdir): + topdir = None + break + assert topdir, ( + "cannot determine single top-level directory in zip file %s" % + zipfile.filename) + return topdir.rstrip('/') + + def unpack_zipfile(zipfn, destdir): assert zipfn.endswith('.zip') import zipfile print('Unpacking %s into %s' % (os.path.basename(zipfn), destdir)) f = zipfile.ZipFile(zipfn) try: + extracted_dir = os.path.join(destdir, find_top_dir_of_zipfile(f)) f.extractall(path=destdir) finally: f.close() - edir = os.path.join(destdir, os.path.basename(zipfn)[:-len('.zip')]) - assert os.path.exists(edir), 'missing: %s' % edir - return edir + assert os.path.exists(extracted_dir), 'missing: %s' % extracted_dir + return extracted_dir def get_prebuilt_libxml2xslt(download_dir, static_include_dirs, static_library_dirs): assert sys.platform.startswith('win') |
