def default(self, line): '''Custom input handling''' if (line == "cheese"): print "Crackers" elif line == "load": self.programs = tmdata.loadConfig(os.path.realpath("./config.xml")) print("\n---Programs Loaded---\n") elif line == "sched": if not self.programs: print("Load config first!") return elif line.startswith("sched"): sc = line.split() if len(sc) == 1: for program in self.programs: program.runAndMonitor() print("\n---Monitoring " + str(len(self.programs)) + " programs---\n") else: for program in self.programs: if program.progname == sc[1]: program.runAndMonitor() # print("\n---Monitoring " + str(len(self.programs)) # + " programs---\n") # self.testsched() else: print("Unknown command")
def main(): """""" progs = None if not os.path.exists("./config.xml"): print("\n./config.xml not found!") return elif os.path.getsize("./config.xml") == 0: print("\n./config.xml is empty!") return progs = tmdata.loadConfig("./config.xml") if not progs: print("No Progs!") return for p in progs: for k, v in vars(p).iteritems(): if k == "exitcodes" and type(v) is list: print(k) for i in v: print("\tcode =>" + str(i)) elif k == "envvars": # and type(v) is dict: print(k) for dk, dv in v.iteritems(): print("\t" + dk + " => " + dv) else: print(k + " => " + str(v))
def main(): """""" tm = Taskmaster() if str(platform.system()) != "Windows": os.system("clear") else: os.system("cls") tm.programs = tmdata.loadConfig(os.path.realpath("./config.xml")) if (len(tm.programs) > 0): print("\n---Programs Loaded---\n") autolaunchPrograms(tm) tm.cmdloop()
def main(): """ NOTE: Nothing printed here will be visible as cmdloop clears the screen """ tm = Taskmaster() clearLog() log("TaskMaster started", "./tmlog.txt", False) os.system("clear") log("Loading config file", "./tmlog.txt", False) tm.programs = tmdata.loadConfig("./config.xml") log( str(len(tm.programs)) + " programs loaded from config", "./tmlog.txt", False) autolaunchPrograms(tm) tm.cmdloop()
def main(): """""" log("TaskMaster started", "./tmlog.txt", False) tm = Taskmaster() print("Loading programs") if str(platform.system()) != "Windows": os.system("clear") else: os.system("cls") log("Loading config file", "./tmlog.txt", False) tm.programs = tmdata.loadConfig(os.path.realpath("./config.xml")) log( str(len(tm.programs)) + " programs loaded from config", "./tmlog.txt", False) autolaunchPrograms(tm) tm.monitor = True log("Monitoring processes", "./tmlog.txt", False) tm.monitorProcesses() signal.signal(signal.SIGINT, tm.handleSigint) #!# tm.cmdloop()
def reloadConfig(self): """""" cnt = 0 rmcnt = 0 chcnt = 0 chprogs = list() allnewprogs = list() toremove = list() allconfig = tmdata.loadConfig("./config.xml") newprogs = tmdata.loadNewPrograms("./config.xml", self.programs) stopstring = "stop" startstring = "start" # removes all programs from 'self.programs' that are no longer present # in the config file for prog in self.programs: if (tmdata.programExists(prog, "./config.xml") == False): rmcnt += 1 toremove.append(prog) # this loop checks if a program's variables have changed, and if so, # adds a new Program with changed variables to 'chprogs' for prog in self.programs: chprog = tmfuncs.programChanged(allconfig, prog) if not (chprog == None): chcnt += 1 toremove.append(prog) chprogs.append(chprog) # ensure some sort of change ocurred if (rmcnt == 0 and chcnt == 0 and len(newprogs) == 0): print("No changes to config.") return # log the change\s if (len(newprogs) > 0): log( str(len(newprogs)) + " new programs added to config", "./tmlog.txt", True) if (chcnt > 0): log( str(chcnt) + " programs changed in config", "./tmlog.txt", True) if (rmcnt > 0): log( str(rmcnt) + " programs removed from config", "./tmlog.txt", True) # stop programs in 'self.programs' that exist in 'toremove' for prog in self.programs: for rprog in toremove: # if (rprog == prog): if (rprog.progname == prog.progname): if (prog.hasActiveProcesses() == True): cnt += 1 stopstring += " " + prog.progname # stop runnuing processes # print("Reloading config file...") log("Reloading config file...", "./tmlog.txt", True) if (cnt > 0): self.default(stopstring) self.waitForPrograms() cnt = 0 # remove programs in 'self.programs' that exist in 'toremove' for rprog in toremove: for prog in self.programs: if (prog.progname == rprog.progname): self.programs.remove(prog) # adds all changed programs to 'allnewprogs' for prog in chprogs: allnewprogs.append(prog) # adds all new programs to 'allnewprogs' for prog in newprogs: allnewprogs.append(prog) # adds programs from 'allnewprogs' to 'self.programs' and starts them # if applicable for prog in allnewprogs: self.programs.append(prog) if (prog.autolaunch == True): startstring += " " + prog.progname cnt += 1 if (cnt > 0): self.default(startstring) self.waitForPrograms()