Merge branch 'check_before_install_packages' into 3.4

This commit is contained in:
Diego Prado Gesto 2018-07-04 17:20:03 +02:00
commit ed882b917e

View File

@ -308,43 +308,47 @@ class CuraPackageManager(QObject):
package_id = package_info["package_id"]
Logger.log("i", "Installing package [%s] from file [%s]", package_id, filename)
# remove it first and then install
# Load the cached package file and extract all contents to a temporary directory
if not os.path.exists(filename):
Logger.log("w", "Package [%s] file '%s' is missing, cannot install this package", package_id, filename)
return
try:
with zipfile.ZipFile(filename, "r") as archive:
temp_dir = tempfile.TemporaryDirectory()
archive.extractall(temp_dir.name)
except Exception:
Logger.logException("e", "Failed to install package from file [%s]", filename)
return
from cura.CuraApplication import CuraApplication
installation_dirs_dict = {
"materials": Resources.getStoragePath(CuraApplication.ResourceTypes.MaterialInstanceContainer),
"qualities": Resources.getStoragePath(CuraApplication.ResourceTypes.QualityInstanceContainer),
"plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)),
}
# Remove it first and then install
try:
self._purgePackage(package_id)
except:
Logger.log("e", "There was an error deleting the package {package} during updating.".format(package = package_id))
return
if not os.path.exists(filename):
Logger.log("w", "Package [%s] file '%s' is missing, cannot install this package", package_id, filename)
return
# Copy the folders there
for sub_dir_name, installation_root_dir in installation_dirs_dict.items():
src_dir_path = os.path.join(temp_dir.name, "files", sub_dir_name)
dst_dir_path = os.path.join(installation_root_dir, package_id)
# Install the package
with zipfile.ZipFile(filename, "r") as archive:
if not os.path.exists(src_dir_path):
continue
self.__installPackageFiles(package_id, src_dir_path, dst_dir_path)
temp_dir = tempfile.TemporaryDirectory()
archive.extractall(temp_dir.name)
# Remove the file
try:
os.remove(filename)
except Exception:
Logger.log("w", "Tried to delete file [%s], but it failed", filename)
from cura.CuraApplication import CuraApplication
installation_dirs_dict = {
"materials": Resources.getStoragePath(CuraApplication.ResourceTypes.MaterialInstanceContainer),
"qualities": Resources.getStoragePath(CuraApplication.ResourceTypes.QualityInstanceContainer),
"plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)),
}
for sub_dir_name, installation_root_dir in installation_dirs_dict.items():
src_dir_path = os.path.join(temp_dir.name, "files", sub_dir_name)
dst_dir_path = os.path.join(installation_root_dir, package_id)
if not os.path.exists(src_dir_path):
continue
self.__installPackageFiles(package_id, src_dir_path, dst_dir_path)
# Remove the file
try:
os.remove(filename)
except Exception:
Logger.log("w", "Tried to delete file [%s], but it failed", filename)
# Move the info to the installed list of packages only when it succeeds
self._installed_package_dict[package_id] = self._to_install_package_dict[package_id]