Commit d331535c by Jan Škoda Committed by GitHub

Fix downloading packages from Simplepypi (#1851)

* fix downloading packages from simplepypi

* unused code removed

* remove unused imports
parent 4687ef89
...@@ -3,8 +3,6 @@ import os ...@@ -3,8 +3,6 @@ import os
import tarfile import tarfile
import zipfile import zipfile
from bz2 import BZ2File
from gzip import GzipFile
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import Union from typing import Union
...@@ -114,27 +112,21 @@ class Inspector: ...@@ -114,27 +112,21 @@ class Inspector:
# Still not dependencies found # Still not dependencies found
# So, we unpack and introspect # So, we unpack and introspect
suffix = file_path.suffix suffix = file_path.suffix
gz = None
if suffix == ".zip": if suffix == ".zip":
tar = zipfile.ZipFile(str(file_path)) tar = zipfile.ZipFile(str(file_path))
else: else:
if suffix == ".bz2": if suffix == ".bz2":
gz = BZ2File(str(file_path))
suffixes = file_path.suffixes suffixes = file_path.suffixes
if len(suffixes) > 1 and suffixes[-2] == ".tar": if len(suffixes) > 1 and suffixes[-2] == ".tar":
suffix = ".tar.bz2" suffix = ".tar.bz2"
else: else:
gz = GzipFile(str(file_path))
suffix = ".tar.gz" suffix = ".tar.gz"
tar = tarfile.TarFile(str(file_path), fileobj=gz) tar = tarfile.open(str(file_path))
try: try:
tar.extractall(os.path.join(str(file_path.parent), "unpacked")) tar.extractall(os.path.join(str(file_path.parent), "unpacked"))
finally: finally:
if gz:
gz.close()
tar.close() tar.close()
unpacked = file_path.parent / "unpacked" unpacked = file_path.parent / "unpacked"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment