def getPluginMethod(self, pluginType, pluginName, pluginMethod): methods = self.getPlugin(pluginType, pluginName)["Method"] for method in methods: if pluginMethod == method["Name"]: return method Error.raiseException("Can't find {0}::{1}::{2}()".format( pluginType, pluginName, pluginMethod))
def promptForPassword(isNewFlag=False): if isNewFlag: p1 = Security.__showHiddenPrompt("Enter a new password") p2 = Security.__showHiddenPrompt("Enter a new password again") if p1 != p2: Error.raiseException("Mismatched passwords") return p1 return Security.__showHiddenPrompt("Enter your password")
def saveCfg(self, cfgPath=None): if cfgPath is not None: self.cfgPath = cfgPath if cfgPath is None and self.cfgPath is None: Error.raiseException("You must specify a path to save cfg file") if self.cfg is None: Error.raiseException("No cfg loaded or set") with open(self.cfgPath, "w") as fd: json.dump(self.cfg, fd)
def load(self, verifyFlag=True): __cfgPath = self.cfgPath if not os.path.isfile(__cfgPath): Error.raiseException("Can't find cfg file: {0}".format(__cfgPath)) with open(__cfgPath) as fd: self.cfg = json.loads(fd.read()) for name, value in self.cfg.items(): self.__dict__[name] = value if verifyFlag: self.verify() self.cfgPath = __cfgPath
def getPlugin(self, pluginType, pluginName): for plugin in self.cfg["Plugin"]: if plugin["Type"] == pluginType and plugin["Name"] == pluginName: return plugin Error.raiseException("Plugin {0}:{1} not found.".format( pluginType, pluginName))
def checkIfCfgLoaded(self): if self.cfg is None: Error.raiseException("Missing cfg file. Did you load it?")
def verify(self): for name, value in self.cfg.items(): if name == "ProjectID": if len(value) > 256 or Text.isNothing(value): Error.raiseException( "{0} can only be 256 characters or less: {1}".format( name, value)) if re.search(r'[^A-Za-z0-9_\-\\]', value): Error.raiseException( "{0} contains invalid characters: {1}".format( name, value)) if Text.isNothing(value): Error.raiseException("Missing '{0}' value in {1}".format( name, self.cfgPath)) pluginLookupMap = [] for plugin in self.cfg["Plugin"]: pluginMethods = self.getPluginMethods(plugin["Type"], plugin["Name"]) for pluginMethod in pluginMethods["Method"]: if not Framework.hasPluginClassMethod( plugin["Type"], plugin["Name"], pluginMethod["Name"]): Error.raiseException("Can't find {0}::{1}::{2}()".format( plugin["Type"], plugin["Name"], pluginMethod["Name"])) pluginLookupMap.append("{0}{1}{2}".format( plugin["Type"], plugin["Name"], pluginMethod["Name"])) if len(self.cfg["Workflow"]["Demo"]["Plugin"]) != len( self.cfg["Workflow"]["Demo"]["Method"]): Error.raiseException( "Mismatched number of demo plugins and methods") workflowPluginLookupMap = [] for workflowPluginType, workflowPluginCfg in self.cfg[ "Workflow"].items(): pluginType = self.pluginTypeAlias[workflowPluginType] if pluginType != "Demo": workflowPluginLookupMap.append("{0}{1}{2}".format( pluginType, workflowPluginCfg["Plugin"], workflowPluginCfg["Method"])) else: for i in range(0, len(workflowPluginCfg["Plugin"])): key = "{0}{1}{2}".format(pluginType, workflowPluginCfg["Plugin"][i], workflowPluginCfg["Method"][i]) if key not in pluginLookupMap: Error.raiseException( "Can't find workflow plugin {0}::{1}::{2}()". format(workflowPluginType, workflowPluginCfg["Plugin"][i], workflowPluginCfg["Method"][i]))
def raiseException(self, msg): Error.raiseException(msg)