Add two options to disable addons

Addons can be disabled in two ways:
 * by adding a command line argument `--disable-addon <addon>`
 * and by creating a `ALL_ADDONS_DISABLED` file in the mod root of the addons to disable
This commit is contained in:
Benjamin Nauck
2024-09-19 00:15:43 +02:00
committed by Chris Hennes
parent 7c1a5ebd69
commit 8945260a7e
3 changed files with 59 additions and 8 deletions

View File

@@ -2250,6 +2250,7 @@ void parseProgramOptions(int ac, char ** av, const string& exe, variables_map& v
("run-open,r", value<string>()->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<string> >()->composing(),"Additional module paths")
("python-path,P", value< vector<string> >()->composing(),"Additional python paths")
("disable-addon", value< vector<string> >()->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<string> >()->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<std::string,std::st
Base::Interpreter().addPythonPath(It.c_str());
}
if (vm.count("disable-addon")) {
auto Addons = vm["disable-addon"].as< vector<string> >();
string temp;
for (const auto & It : Addons) {
temp += It + ";";
}
temp.erase(temp.end()-1);
mConfig["DisabledAddons"] = temp;
}
if (vm.count("input-file")) {
vector<string> files(vm["input-file"].as< vector<string> >());
int OpenFileCount=0;

View File

@@ -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)

View File

@@ -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):