Skip to content

Commit

Permalink
Merge pull request DLR-RM#1015 from common/extract_file_fix
Browse files Browse the repository at this point in the history
fix(run): Fixes usage of extract_file in run.py
  • Loading branch information
themasterlink authored and GitHub Enterprise committed Jul 23, 2021
2 parents e1a095f + 487dba7 commit d15dba7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 5 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import os
import tarfile
from os.path import join
import subprocess
import shutil
Expand Down Expand Up @@ -133,10 +134,11 @@ def __call__(self, block_num, block_size, total_size):

if platform == "linux" or platform == "linux2":
if version_info.major == 3:
SetupUtility.extract_file(file_tmp, blender_install_path)
SetupUtility.extract_file(blender_install_path, file_tmp, "TAR")
else:
with contextlib.closing(lzma.LZMAFile(file_tmp)) as xz:
SetupUtility.extract_file(xz, blender_install_path)
with tarfile.open(fileobj=xz) as f:
f.extractall(blender_install_path)
elif platform == "darwin":
if not os.path.exists(blender_install_path):
os.makedirs(blender_install_path)
Expand All @@ -152,7 +154,7 @@ def __call__(self, block_num, block_size, total_size):
subprocess.Popen(["rm {}".format(os.path.join(blender_install_path, blender_version + ".dmg"))], shell=True).wait()
# add Blender.app path to it
elif platform == "win32":
SetupUtility.upzip_file(file_tmp, blender_install_path)
SetupUtility.extract_file(file_tmp, blender_install_path)
# rename the blender folder to better fit our existing scheme
for folder in os.listdir(blender_install_path):
if os.path.isdir(os.path.join(blender_install_path, folder)) and folder.startswith("blender-" + major_version):
Expand Down
21 changes: 15 additions & 6 deletions src/utility/SetupUtility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import tarfile
from sys import platform
import subprocess
import importlib
Expand Down Expand Up @@ -196,15 +197,23 @@ def _ensure_pip(python_bin, packages_path, pre_python_package_path):
SetupUtility.installed_packages = dict(zip(installed_packages_name, installed_packages_versions))

@staticmethod
def extract_file(output_dir, file):
""" Extract all members from the archive to output_dir
def extract_file(output_dir, file, mode="ZIP"):
""" Extract all members from the archive into output_dir.
:param output_dir: the dir to zip file extract to
:param file: file to extract
:param output_dir: The output directory that should contain the extracted files.
:param file: The path to the archive which should be extracted.
:param mode: The type of the given file, has to be in ["TAR", "ZIP"]
"""
try:
with zipfile.ZipFile(file) as tar:
tar.extractall(str(output_dir))
if mode.lower() == "zip":
with zipfile.ZipFile(file) as tar:
tar.extractall(str(output_dir))
elif mode.lower() == "tar":
with tarfile.open(file) as tar:
tar.extractall(str(output_dir))
else:
raise Exception("No such mode: " + mode)

except (IOError, zipfile.BadZipfile) as e:
print('Bad zip file given as input. %s' % e)
raise e
Expand Down

0 comments on commit d15dba7

Please sign in to comment.