diff options
author | Martin Fischer <martin@push-f.com> | 2022-02-07 13:30:12 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-02-07 13:36:54 +0100 |
commit | 98e34170bb1e4129092f4b79d22ae435ce85be61 (patch) | |
tree | 3e2c43c0c8bfdd08c1039ed5c9db3a62e954221c | |
parent | 91c115af404abe9edf4e1e76b31a021c76d4660e (diff) |
support .zip archives
For some reason the numpy source dist uses .zip.
-rwxr-xr-x | pydoc.py | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -3,6 +3,7 @@ import json import shutil import tarfile import tempfile +import zipfile from pathlib import Path from typing import Dict, List @@ -86,13 +87,27 @@ if __name__ == '__main__': with open(archive_path, 'wb') as f: shutil.copyfileobj(r.raw, f) - tf = tarfile.open(archive_path) - for member in tf.getmembers(): - if '/' in member.name: - member.name = member.name.split('/', maxsplit=1)[1] - else: - member.name = '.' - tf.extractall(sources / sourceid) + if filename.endswith('.tar.gz'): + tf = tarfile.open(archive_path) + for member in tf.getmembers(): + # TODO: check that path is secure (doesn't start with /, doesn't contain ..) + if '/' in member.name: + member.name = member.name.split('/', maxsplit=1)[1] + else: + member.name = '.' + tf.extractall(sources / sourceid) + elif filename.endswith('.zip'): + with zipfile.ZipFile(archive_path) as zf: + for info in zf.infolist(): + # TODO: check that path is secure (doesn't start with /, doesn't contain ..) + if '/' in info.filename.rstrip('/'): + info.filename = info.filename.split('/', maxsplit=1)[1] + else: + info.filename = './' + zf.extract(info, sources / sourceid) + else: + print('[error] unknown source dist archive format', filename) + versions[package_name] = version with open('versions.json', 'w') as f: |