From 8945260a7e18466c78faa38f9df0fb2f873e849b Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Thu, 19 Sep 2024 00:15:43 +0200 Subject: [PATCH] Add two options to disable addons Addons can be disabled in two ways: * by adding a command line argument `--disable-addon ` * and by creating a `ALL_ADDONS_DISABLED` file in the mod root of the addons to disable --- src/App/Application.cpp | 11 +++++++++++ src/App/FreeCADInit.py | 28 ++++++++++++++++++++++++---- src/Gui/FreeCADGuiInit.py | 28 ++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 9384790627..bd7bd182c1 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -2250,6 +2250,7 @@ void parseProgramOptions(int ac, char ** av, const string& exe, variables_map& v ("run-open,r", value()->implicit_value(""),"Run a given test case (use 0 (zero) to run all tests). If no argument is provided then return list of all available tests. Keeps UI open after test(s) complete.") ("module-path,M", value< vector >()->composing(),"Additional module paths") ("python-path,P", value< vector >()->composing(),"Additional python paths") + ("disable-addon", value< vector >()->composing(),"Disable a given addon.") ("single-instance", "Allow to run a single instance of the application") ("safe-mode", "Force enable safe mode") ("pass", value< vector >()->multitoken(), "Ignores the following arguments and pass them through to be used by a script") @@ -2431,6 +2432,16 @@ void processProgramOptions(const variables_map& vm, std::map >(); + string temp; + for (const auto & It : Addons) { + temp += It + ";"; + } + temp.erase(temp.end()-1); + mConfig["DisabledAddons"] = temp; + } + if (vm.count("input-file")) { vector files(vm["input-file"].as< vector >()); int OpenFileCount=0; diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index 36e7c2a23a..b020f0fd31 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -106,6 +106,7 @@ def InitApplications(): MacroMod = os.path.realpath(MacroDir+"/Mod") SystemWideMacroDir = FreeCAD.getHomePath()+'Macro' SystemWideMacroDir = os.path.realpath(SystemWideMacroDir) + DisabledAddons = FreeCAD.ConfigGet("DisabledAddons").split(";") #print FreeCAD.getHomePath() if os.path.isdir(FreeCAD.getHomePath()+'src\\Tools'): @@ -218,11 +219,30 @@ def InitApplications(): except Exception as exc: Err(str(exc)) + def checkIfAddonIsDisabled(Dir): + Name = os.path.basename(Dir) + + if Name in DisabledAddons: + Msg(f'NOTICE: Addon "{Name}" disabled by presence of "--disable-addon {Name}" argument\n') + return True + + stopFileName = "ALL_ADDONS_DISABLED" + stopFile = os.path.join(Dir, os.path.pardir, stopFileName) + if os.path.exists(stopFile): + Msg(f'NOTICE: Addon "{Dir}" disabled by presence of {stopFileName} stopfile\n') + return True + + stopFileName = "ADDON_DISABLED" + stopFile = os.path.join(Dir, stopFileName) + if os.path.exists(stopFile): + Msg(f'NOTICE: Addon "{Dir}" disabled by presence of {stopFileName} stopfile\n') + return True + + return False + for Dir in ModDict.values(): - if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')): - stopFile = os.path.join(Dir, "ADDON_DISABLED") - if os.path.exists(stopFile): - Msg(f'NOTICE: Addon "{Dir}" disabled by presence of ADDON_DISABLED stopfile\n') + if Dir not in ['', 'CVS', '__init__.py']: + if checkIfAddonIsDisabled(Dir): continue sys.path.insert(0,Dir) PathExtension.append(Dir) diff --git a/src/Gui/FreeCADGuiInit.py b/src/Gui/FreeCADGuiInit.py index 06c5146cbc..97f4910d43 100644 --- a/src/Gui/FreeCADGuiInit.py +++ b/src/Gui/FreeCADGuiInit.py @@ -192,11 +192,31 @@ def InitApplications(): except Exception as exc: Err(str(exc)) + def checkIfAddonIsDisabled(Dir): + DisabledAddons = FreeCAD.ConfigGet("DisabledAddons").split(";") + Name = os.path.basename(Dir) + + if Name in DisabledAddons: + Msg(f'NOTICE: Addon "{Name}" disabled by presence of "--disable-addon {Name}" argument\n') + return True + + stopFileName = "ALL_ADDONS_DISABLED" + stopFile = os.path.join(Dir, os.path.pardir, stopFileName) + if os.path.exists(stopFile): + Msg(f'NOTICE: Addon "{Dir}" disabled by presence of {stopFileName} stopfile\n') + return True + + stopFileName = "ADDON_DISABLED" + stopFile = os.path.join(Dir, stopFileName) + if os.path.exists(stopFile): + Msg(f'NOTICE: Addon "{Dir}" disabled by presence of {stopFileName} stopfile\n') + return True + + return False + for Dir in ModDirs: - if (Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py'): - stopFile = os.path.join(Dir, "ADDON_DISABLED") - if os.path.exists(stopFile): - Msg(f'NOTICE: Addon "{Dir}" disabled by presence of ADDON_DISABLED stopfile\n') + if Dir not in ['', 'CVS', '__init__.py']: + if checkIfAddonIsDisabled(Dir): continue MetadataFile = os.path.join(Dir, "package.xml") if os.path.exists(MetadataFile):