Merge pull request #9627 from chennes/addonManagerMiscBugs
Addon Manager: Minor error handling cleanup
This commit is contained in:
@@ -128,9 +128,7 @@ class AddonInstaller(QtCore.QObject):
|
||||
self.git_manager = initialize_git()
|
||||
|
||||
if allow_list is not None:
|
||||
AddonInstaller.allowed_packages = set(
|
||||
allow_list if allow_list is not None else []
|
||||
)
|
||||
AddonInstaller.allowed_packages = set(allow_list if allow_list is not None else [])
|
||||
elif not AddonInstaller.allowed_packages:
|
||||
AddonInstaller._load_local_allowed_packages_list()
|
||||
AddonInstaller._update_allowed_packages_list()
|
||||
@@ -160,6 +158,9 @@ class AddonInstaller(QtCore.QObject):
|
||||
self.addon_to_install.enable_workbench()
|
||||
except utils.ProcessInterrupted:
|
||||
pass
|
||||
except Exception as e:
|
||||
FreeCAD.Console.PrintLog(e + "\n")
|
||||
success = False
|
||||
if success:
|
||||
if (
|
||||
hasattr(self.addon_to_install, "contains_workbench")
|
||||
@@ -175,9 +176,7 @@ class AddonInstaller(QtCore.QObject):
|
||||
def _load_local_allowed_packages_list(cls) -> None:
|
||||
"""Read in the local allow-list, in case the remote one is unavailable."""
|
||||
cls.allowed_packages.clear()
|
||||
allow_file = os.path.join(
|
||||
os.path.dirname(__file__), "ALLOWED_PYTHON_PACKAGES.txt"
|
||||
)
|
||||
allow_file = os.path.join(os.path.dirname(__file__), "ALLOWED_PYTHON_PACKAGES.txt")
|
||||
if os.path.exists(allow_file):
|
||||
with open(allow_file, encoding="utf8") as f:
|
||||
lines = f.readlines()
|
||||
@@ -271,9 +270,7 @@ class AddonInstaller(QtCore.QObject):
|
||||
if addon_url.startswith("file://"):
|
||||
addon_url = addon_url[len("file://") :] # Strip off the file:// part
|
||||
name = self.addon_to_install.name
|
||||
shutil.copytree(
|
||||
addon_url, os.path.join(self.installation_path, name), dirs_exist_ok=True
|
||||
)
|
||||
shutil.copytree(addon_url, os.path.join(self.installation_path, name), dirs_exist_ok=True)
|
||||
self._finalize_successful_installation()
|
||||
return True
|
||||
|
||||
@@ -326,9 +323,7 @@ class AddonInstaller(QtCore.QObject):
|
||||
GUI thread."""
|
||||
NetworkManager.AM_NETWORK_MANAGER.progress_made.connect(self._update_zip_status)
|
||||
NetworkManager.AM_NETWORK_MANAGER.progress_complete.connect(self._finish_zip)
|
||||
self.zip_download_index = (
|
||||
NetworkManager.AM_NETWORK_MANAGER.submit_monitored_get(zip_url)
|
||||
)
|
||||
self.zip_download_index = NetworkManager.AM_NETWORK_MANAGER.submit_monitored_get(zip_url)
|
||||
while self.zip_download_index is not None:
|
||||
if QtCore.QThread.currentThread().isInterruptionRequested():
|
||||
break
|
||||
@@ -350,9 +345,9 @@ class AddonInstaller(QtCore.QObject):
|
||||
if response_code != 200:
|
||||
self.failure.emit(
|
||||
self.addon_to_install,
|
||||
translate(
|
||||
"AddonsInstaller", "Received {} response code from server"
|
||||
).format(response_code),
|
||||
translate("AddonsInstaller", "Received {} response code from server").format(
|
||||
response_code
|
||||
),
|
||||
)
|
||||
return
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
|
||||
@@ -411,9 +406,7 @@ class AddonInstaller(QtCore.QObject):
|
||||
|
||||
if hasattr(self.addon_to_install, "metadata") and os.path.isfile(package_xml):
|
||||
self.addon_to_install.load_metadata_file(package_xml)
|
||||
self.addon_to_install.installed_version = (
|
||||
self.addon_to_install.metadata.version
|
||||
)
|
||||
self.addon_to_install.installed_version = self.addon_to_install.metadata.version
|
||||
self.addon_to_install.updated_timestamp = os.path.getmtime(package_xml)
|
||||
|
||||
def _install_macros(self):
|
||||
@@ -462,11 +455,7 @@ class AddonInstaller(QtCore.QObject):
|
||||
"""Make sure the object has the necessary attributes (name, url, and branch) to be
|
||||
installed."""
|
||||
|
||||
if (
|
||||
not hasattr(addon, "name")
|
||||
or not hasattr(addon, "url")
|
||||
or not hasattr(addon, "branch")
|
||||
):
|
||||
if not hasattr(addon, "name") or not hasattr(addon, "url") or not hasattr(addon, "branch"):
|
||||
raise RuntimeError(
|
||||
"Provided object does not provide a name, url, and/or branch attribute"
|
||||
)
|
||||
@@ -505,9 +494,7 @@ class MacroInstaller(QtCore.QObject):
|
||||
temp_install_succeeded, error_list = macro.install(temp_dir)
|
||||
if not temp_install_succeeded:
|
||||
FreeCAD.Console.PrintError(
|
||||
translate("AddonsInstaller", "Failed to install macro {}").format(
|
||||
macro.name
|
||||
)
|
||||
translate("AddonsInstaller", "Failed to install macro {}").format(macro.name)
|
||||
+ "\n"
|
||||
)
|
||||
for e in error_list:
|
||||
@@ -536,6 +523,4 @@ class MacroInstaller(QtCore.QObject):
|
||||
or not hasattr(addon.macro, "install")
|
||||
or not callable(addon.macro.install)
|
||||
):
|
||||
raise RuntimeError(
|
||||
"Provided object does not provide a macro with an install method"
|
||||
)
|
||||
raise RuntimeError("Provided object does not provide a macro with an install method")
|
||||
|
||||
@@ -149,9 +149,7 @@ def restart_freecad():
|
||||
|
||||
args = QtWidgets.QApplication.arguments()[1:]
|
||||
if fci.FreeCADGui.getMainWindow().close():
|
||||
QtCore.QProcess.startDetached(
|
||||
QtWidgets.QApplication.applicationFilePath(), args
|
||||
)
|
||||
QtCore.QProcess.startDetached(QtWidgets.QApplication.applicationFilePath(), args)
|
||||
|
||||
|
||||
def get_zip_url(repo):
|
||||
@@ -237,9 +235,7 @@ def get_readme_html_url(repo):
|
||||
return f"{repo.url}/blob/{repo.branch}/README.md"
|
||||
if parsed_url.netloc in ["gitlab.com", "salsa.debian.org", "framagit.org"]:
|
||||
return f"{repo.url}/-/blob/{repo.branch}/README.md"
|
||||
fci.Console.PrintLog(
|
||||
"Unrecognized git repo location '' -- guessing it is a GitLab instance..."
|
||||
)
|
||||
fci.Console.PrintLog("Unrecognized git repo location '' -- guessing it is a GitLab instance...")
|
||||
return f"{repo.url}/-/blob/{repo.branch}/README.md"
|
||||
|
||||
|
||||
@@ -324,9 +320,7 @@ def update_macro_installation_details(repo) -> None:
|
||||
fci.Console.PrintLog("Requested macro details for non-macro object\n")
|
||||
return
|
||||
test_file_one = os.path.join(fci.DataPaths().macro_dir, repo.macro.filename)
|
||||
test_file_two = os.path.join(
|
||||
fci.DataPaths().macro_dir, "Macro_" + repo.macro.filename
|
||||
)
|
||||
test_file_two = os.path.join(fci.DataPaths().macro_dir, "Macro_" + repo.macro.filename)
|
||||
if os.path.exists(test_file_one):
|
||||
repo.updated_timestamp = os.path.getmtime(test_file_one)
|
||||
repo.installed_version = get_macro_version_from_file(test_file_one)
|
||||
@@ -442,7 +436,7 @@ def run_interruptable_subprocess(args) -> subprocess.CompletedProcess:
|
||||
return_code = None
|
||||
while return_code is None:
|
||||
try:
|
||||
stdout, stderr = p.communicate(timeout=0.1)
|
||||
stdout, stderr = p.communicate(timeout=10)
|
||||
return_code = p.returncode
|
||||
except subprocess.TimeoutExpired:
|
||||
if QtCore.QThread.currentThread().isInterruptionRequested():
|
||||
|
||||
Reference in New Issue
Block a user