def Execute(self): utils.HighPrint(self.GetInteractiveName()) if len(self.__ValueName) == 0: self.__ValueName = input("Key=") self.__ValueData = input("Value=") if len(self.__ValueName) == 0 or len(self.__ValueData) == 0: utils.ErrorPrint("ERROR !! Invalid entries") return else: self.TryRead() else: pass if self.Exists(): utils.HighPrint("Value (" + self.envVarType + ") already exists and is set as: %s=%s" % (self.__ValueName, self.__existingValueData)) utils.HighPrint("Nevertheless, updating it to: %s=%s" % (self.__ValueName, self.__ValueData)) SetValueEx(self.key, self.__ValueName, 0, self.__TypeId, self.__ValueData) elif self.__TypeId: utils.HighPrint("Value (" + self.envVarType + ") does not exist. Setting %s=%s" % (self.__ValueName, self.__ValueData)) SetValueEx(self.key, self.__ValueName, 0, self.__TypeId, self.__ValueData) else: # Should never be here utils.ErrorPrint("ERROR! TypeId is not defined !!") win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')
def ReadIp(): result = None options = {} h = False if len(sys.argv) > 1: if "--help" in sys.argv or "--Help" in sys.argv or "--HELP" in sys.argv: utils.OkPrint("Usage:") utils.OkPrint( " tasker.py [--configfile=<config-file-name>] [--exec=<option>] [--wait=<True/False>]" ) h = True else: for i in range(1, len(sys.argv)): opts = sys.argv[i].split("=") if len(opts) == 2: #print(opts[0]+ "--" + opts[1]) options[opts[0][2:]] = opts[1] if not h: if "configfile" in options: cf = options["configfile"] else: cf = DEFAULT_CONFIG_FILE options["configfile"] = cf utils.HighPrint("Using the default configuration file \"" + cf + "\"\n") if (os.path.isfile(cf) == True): result = True else: utils.ErrorPrint("The configuration file " + cf + " is not found. I cannot continue.") return result, options
def DirectExecute(self, liExecOpts): idx = int(liExecOpts[0]) - 1 if idx < len(self.__workPackages): del liExecOpts[0] if len(liExecOpts) > 0: self.__workPackages[idx].DirectExecute(liExecOpts) else: self.__workPackages[idx].Interact() else: utils.ErrorPrint("Error!! Incorrect option. Nothing done.")
def UpdateValue(self, optionKey, subKey): if optionKey not in self.opt: utils.ErrorPrint("The key " + optionKey + " is not present. Nothing updated.") if subKey not in self.opt[optionKey]: utils.ErrorPrint("The subkey " + subKey + " is not present. Creating one.") self.opt[optionKey][subKey] = "" try: curOpt = self.opt[optionKey][subKey] utils.CustomPrint(utils.PrintStyle.BLUE, str(curOpt)) newVal = utils.GetNewOption() self.opt[optionKey][subKey] = newVal except: utils.ErrorPrint( "An error occured while processing your input. No changes are made to the options..." )
def DirectExecute(self, liExecOpts): idx = int(liExecOpts[0]) - 1 if idx < len(self.__tcTasks): del liExecOpts[0] if len(liExecOpts) > 0: self.__tcTasks[idx].DirectExecute(liExecOpts) else: self.__tcTasks[idx].Execute() else: utils.ErrorPrint("Error!! Incorrect option. Nothing done.")
def Execute(self): utils.HighPrint(self.GetInteractiveName()) if len(self.__valueToAppend) == 0: self.__valueToAppend = input( "Enter the Value to append to PATH:") if len(self.__valueToAppend) == 0: utils.ErrorPrint("ERROR !! Invalid entries") return else: pass self.CheckAndAppendData(self.__valueToAppend)
def CheckAndAppendData(self, s): if s not in self.ValueData: seq = ((self.ValueData), s) self.ValueData = ';'.join(seq) SetValueEx(self.key, self.ValueName, 0, self.TypeId, self.ValueData) win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment') else: utils.ErrorPrint( "The specified string is already part of \'PATH\'. Did nothing." )
def Update(self, key): curOpt = {} try: if key: curOpt = self.opt[key] except: pass # No options or invalid key try: utils.CustomPrint(utils.PrintStyle.BLUE, str(curOpt)) newOpt = utils.GetNewOption() newOpt = newOpt.replace('\'', '\"') self.opt[key] = json.loads(newOpt) except: utils.ErrorPrint( "An error occured while processing your input. No changes are made to the options..." )
def __init__(self, dictTask): self.__cmds = dictTask["AllCmds"] # Check if a 'Consts' dictionary is available consts = {} if 'Consts' in dictTask: consts = dictTask['Consts'] # Iterate through all the commands and try to replace the values using the consts dictionary # Note: If any of the mapping value is not present, the execution will stop here ignoreAllCmds = False for idx in range(len(self.__cmds)): try: self.__cmds[idx] = self.__cmds[idx].format(**consts) except: utils.ErrorPrint( "Error while parsing the config file. Irregular commands description for {}." .format(dictTask["Name"])) ignoreAllCmds = True if ignoreAllCmds: self.__cmds.clear() self.__name = dictTask["Name"]
def __init__(self, n, userVarTyp): if userVarTyp: self.regPath = r'Environment' rootRegistry = HKEY_CURRENT_USER self.envVarType = "User type" else: self.regPath = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment' rootRegistry = HKEY_LOCAL_MACHINE self.envVarType = "System type" try: self.reg = ConnectRegistry(None, rootRegistry) self.key = OpenKey( self.reg, self.regPath, 0, KEY_ALL_ACCESS) # Handle to the registry item self.__ValueName = n if len(n) != 0: self.TryRead() except: utils.ErrorPrint( "Problem opening/accessing the registry. Make sure you start the application with administrator rights" )
def DirectExecute(self, liExecOpts): if len(liExecOpts) > 0: utils.ErrorPrint("Incorrect option. Nothing done.") else: self.__singleTask.Execute()