Addon Manager: Minor fixes and error tweaks

* Correct display of tags in list view
* Add error checking for branch name and url match
* Convert some messages to logs
This commit is contained in:
Chris Hennes
2022-02-23 17:05:08 -06:00
parent d88397f3d6
commit e7ca40623c
4 changed files with 42 additions and 9 deletions

View File

@@ -243,6 +243,28 @@ class AddonManagerRepo:
self.branch = "master"
self.extract_tags(self.metadata)
def verify_url_and_branch(self, url: str, branch: str) -> None:
"""Print diagnostic information for Addon Developers if their metadata is
inconsistent with the actual fetch location. Most often this is due to using
the wrong branch name."""
if self.url != url:
FreeCAD.Console.PrintWarning(
translate(
"AddonsInstaller",
"Addon Developer Warning: Repository URL set in package.xml file for addon {} ({}) does not match the URL it was fetched from ({})",
).format(self.display_name, self.url, url)
+ "\n"
)
if self.branch != branch:
FreeCAD.Console.PrintWarning(
translate(
"AddonsInstaller",
"Addon Developer Warning: Repository branch set in package.xml file for addon {} ({}) does not match the branch it was fetched from ({})",
).format(self.display_name, self.branch, branch)
+ "\n"
)
def extract_tags(self, metadata: FreeCAD.Metadata) -> None:
for new_tag in metadata.Tag:
self.tags.add(new_tag)
@@ -367,21 +389,28 @@ class AddonManagerRepo:
def is_disabled(self):
# Check for existence of disabling stopfile:
stopfile = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", self.name, "ADDON_DISABLED")
stopfile = os.path.join(
FreeCAD.getUserAppDataDir(), "Mod", self.name, "ADDON_DISABLED"
)
if os.path.exists(stopfile):
return True
else:
return False
def disable(self):
stopfile = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", self.name, "ADDON_DISABLED")
with open(stopfile,"w") as f:
f.write("The existence of this file prevents FreeCAD from loading this Addon. To re-enable, delete the file.")
stopfile = os.path.join(
FreeCAD.getUserAppDataDir(), "Mod", self.name, "ADDON_DISABLED"
)
with open(stopfile, "w") as f:
f.write(
"The existence of this file prevents FreeCAD from loading this Addon. To re-enable, delete the file."
)
def enable(self):
stopfile = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", self.name, "ADDON_DISABLED")
stopfile = os.path.join(
FreeCAD.getUserAppDataDir(), "Mod", self.name, "ADDON_DISABLED"
)
try:
os.unlink(stopfile)
except Exception:
pass

View File

@@ -158,7 +158,7 @@ class Macro(object):
# to apply some special handling to accepts numbers, and "__date__"
if key == "__version__":
if "__date__" in after_equals.lower():
FreeCAD.Console.PrintMessage(
FreeCAD.Console.PrintLog(
translate(
"AddonsInstaller",
"In macro {}, string literal not found for {} element. Guessing at intent and using string from date element.",
@@ -168,7 +168,7 @@ class Macro(object):
self.version = self.date
break
elif is_float(after_equals):
FreeCAD.Console.PrintMessage(
FreeCAD.Console.PrintLog(
translate(
"AddonsInstaller",
"In macro {}, string literal not found for {} element. Guessing at intent and using string representation of contents.",

View File

@@ -248,6 +248,8 @@ class UpdateWorker(QtCore.QThread):
repo.load_metadata_file(md_file)
repo.installed_version = repo.metadata.Version
repo.updated_timestamp = os.path.getmtime(md_file)
repo.verify_url_and_branch(addon["url"], addon["branch"])
self.addon_repo.emit(repo)
# querying official addons
@@ -288,6 +290,8 @@ class UpdateWorker(QtCore.QThread):
repo.load_metadata_file(md_file)
repo.installed_version = repo.metadata.Version
repo.updated_timestamp = os.path.getmtime(md_file)
repo.verify_url_and_branch(url, branch)
if name in py2only:
repo.python2 = True
if name in mod_reject_list:

View File

@@ -343,11 +343,11 @@ class PackageListItemDelegate(QStyledItemDelegate):
self.widget.ui.labelIcon.setPixmap(repo.icon.pixmap(QSize(16, 16)))
self.widget.ui.labelIcon.setText("")
self.widget.ui.labelTags.setText("")
if repo.metadata:
self.widget.ui.labelDescription.setText(repo.metadata.Description)
self.widget.ui.labelVersion.setText(f"<i>v{repo.metadata.Version}</i>")
if self.displayStyle == ListDisplayStyle.EXPANDED:
self.widget.ui.labelTags.setText("")
maintainers = repo.metadata.Maintainer
maintainers_string = ""
if len(maintainers) == 1: