Merge pull request #9099 from wwmayer/more_robust_init

Core: make the init scripts more robust against invalid package.xml f…
This commit is contained in:
Chris Hennes
2023-03-28 16:36:41 -05:00
committed by GitHub
2 changed files with 65 additions and 51 deletions

View File

@@ -192,6 +192,32 @@ def InitApplications():
else:
Log('Init: Initializing ' + Dir + '(Init.py not found)... ignore\n')
def processMetadataFile(MetadataFile):
meta = FreeCAD.Metadata(MetadataFile)
if not meta.supportsCurrentFreeCAD():
Msg(f'NOTICE: {meta.Name} does not support this version of FreeCAD, so is being skipped\n')
return None
content = meta.Content
if "workbench" in content:
workbenches = content["workbench"]
for workbench in workbenches:
if not workbench.supportsCurrentFreeCAD():
Msg(f'NOTICE: {meta.Name} content item {workbench.Name} does not support this version of FreeCAD, so is being skipped\n')
return None
subdirectory = workbench.Name if not workbench.Subdirectory else workbench.Subdirectory
subdirectory = subdirectory.replace("/",os.path.sep)
subdirectory = os.path.join(Dir, subdirectory)
#classname = workbench.Classname
sys.path.insert(0,subdirectory)
PathExtension.append(subdirectory)
RunInitPy(subdirectory)
def tryProcessMetadataFile(MetadataFile):
try:
processMetadataFile(MetadataFile)
except Exception as exc:
Err(str(exc))
for Dir in ModDict.values():
if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')):
stopFile = os.path.join(Dir, "ADDON_DISABLED")
@@ -202,26 +228,7 @@ def InitApplications():
PathExtension.append(Dir)
MetadataFile = os.path.join(Dir, "package.xml")
if os.path.exists(MetadataFile):
meta = FreeCAD.Metadata(MetadataFile)
if not meta.supportsCurrentFreeCAD():
Msg(f'NOTICE: {meta.Name} does not support this version of FreeCAD, so is being skipped\n')
continue
content = meta.Content
if "workbench" in content:
workbenches = content["workbench"]
for workbench in workbenches:
if not workbench.supportsCurrentFreeCAD():
Msg(f'NOTICE: {meta.Name} content item {workbench.Name} does not support this version of FreeCAD, so is being skipped\n')
continue
subdirectory = workbench.Name if not workbench.Subdirectory else workbench.Subdirectory
subdirectory = subdirectory.replace("/",os.path.sep)
subdirectory = os.path.join(Dir, subdirectory)
#classname = workbench.Classname
sys.path.insert(0,subdirectory)
PathExtension.append(subdirectory)
RunInitPy(subdirectory)
else:
pass # The package content says there are no workbenches here, so just skip
tryProcessMetadataFile(MetadataFile)
else:
RunInitPy(Dir)

View File

@@ -149,6 +149,43 @@ def InitApplications():
Log('Init: Initializing ' + Dir + '(InitGui.py not found)... ignore\n')
return False
def processMetadataFile(Dir, MetadataFile):
meta = FreeCAD.Metadata(MetadataFile)
if not meta.supportsCurrentFreeCAD():
return None
content = meta.Content
if "workbench" in content:
FreeCAD.Gui.addIconPath(Dir)
workbenches = content["workbench"]
for workbench_metadata in workbenches:
if not workbench_metadata.supportsCurrentFreeCAD():
return None
subdirectory = workbench_metadata.Name\
if not workbench_metadata.Subdirectory\
else workbench_metadata.Subdirectory
subdirectory = subdirectory.replace("/",os.path.sep)
subdirectory = os.path.join(Dir, subdirectory)
ran_init = RunInitGuiPy(subdirectory)
if ran_init:
# Try to generate a new icon from the metadata-specified information
classname = workbench_metadata.Classname
if classname:
try:
wb_handle = FreeCAD.Gui.getWorkbench(classname)
except Exception:
Log(f"Failed to get handle to {classname} -- no icon\
can be generated,\n check classname in package.xml\n")
else:
GeneratePackageIcon(dir, subdirectory, workbench_metadata,
wb_handle)
def tryProcessMetadataFile(Dir, MetadataFile):
try:
processMetadataFile(Dir, MetadataFile)
except Exception as exc:
Err(str(exc))
for Dir in ModDirs:
if (Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py'):
stopFile = os.path.join(Dir, "ADDON_DISABLED")
@@ -157,37 +194,7 @@ def InitApplications():
continue
MetadataFile = os.path.join(Dir, "package.xml")
if os.path.exists(MetadataFile):
meta = FreeCAD.Metadata(MetadataFile)
if not meta.supportsCurrentFreeCAD():
continue
content = meta.Content
if "workbench" in content:
FreeCAD.Gui.addIconPath(Dir)
workbenches = content["workbench"]
for workbench_metadata in workbenches:
if not workbench_metadata.supportsCurrentFreeCAD():
continue
subdirectory = workbench_metadata.Name\
if not workbench_metadata.Subdirectory\
else workbench_metadata.Subdirectory
subdirectory = subdirectory.replace("/",os.path.sep)
subdirectory = os.path.join(Dir, subdirectory)
ran_init = RunInitGuiPy(subdirectory)
if ran_init:
# Try to generate a new icon from the metadata-specified information
classname = workbench_metadata.Classname
if classname:
try:
wb_handle = FreeCAD.Gui.getWorkbench(classname)
except Exception:
Log(f"Failed to get handle to {classname} -- no icon\
can be generated,\n check classname in package.xml\n")
else:
GeneratePackageIcon(dir, subdirectory, workbench_metadata,
wb_handle)
else:
continue # The package content says there are no workbenches here, so just skip
tryProcessMetadataFile(Dir, MetadataFile)
else:
RunInitGuiPy(Dir)
Log("All modules with GUIs using InitGui.py are now initialized\n")