From 6c3786713e4b74d1abadbdc74d955ae2171aa520 Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Tue, 29 Aug 2017 00:05:41 -0700 Subject: Split code for installing zipped and unzipped packages into separate functions --- release/scripts/modules/bpkg/actions.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'release') diff --git a/release/scripts/modules/bpkg/actions.py b/release/scripts/modules/bpkg/actions.py index bc625f0aab2..5352725cdeb 100644 --- a/release/scripts/modules/bpkg/actions.py +++ b/release/scripts/modules/bpkg/actions.py @@ -86,13 +86,10 @@ def install(src_file: Path, dest_dir: Path): # TODO: check to make sure addon/package isn't already installed elsewhere - # The following is adapted from `addon_install` in bl_operators/wm.py - - # check to see if the file is in compressed format (.zip) - if zipfile.is_zipfile(str(src_file)): - log.debug("Package is zipfile") + def install_zip(src_zip, dest_dir): + """Extract src_zip to dest_dir""" try: - file_to_extract = zipfile.ZipFile(str(src_file), 'r') + file_to_extract = zipfile.ZipFile(str(src_zip), 'r') except Exception as err: raise exceptions.InstallException("Failed to read zip file: %s" % err) from err @@ -122,8 +119,8 @@ def install(src_file: Path, dest_dir: Path): for backup in backups: backup.remove() - else: - log.debug("Package is pyfile") + def install_py(src_file, dest_dir): + """Move src_file to dest_dir)""" dest_file = (dest_dir / src_file.name) backup = None @@ -139,4 +136,9 @@ def install(src_file: Path, dest_dir: Path): if backup: backup.remove() + if zipfile.is_zipfile(str(src_file)): + install_zip(src_file, dest_dir) + else: + install_py(src_file, dest_dir) + log.debug("Installation succeeded") -- cgit v1.2.3