def purge_db(): esse = essential() esse.db_purge() time.sleep(1) esse.db_fill_tables() print "Database purged"
def parse_com(com, module, current): global lastout if log_transcript: transcript.append(com) com = comparse(com, module, current) com = varparse(com) if not conditionparse(com): return module try: com[0] == "#" except: return module #not 100% sure this is where I want to put this #passes to launched module userHandler #We shall see if qu.comrunning and not com.strip().lower().split()[0] == "talos": try: handler = qu.handlers[qu.handler_count] except: print "Something went wrong" qu.comrunning = False return module if handler.writable(): outval = handler.parse_com(com) if not outval: del qu.handlers[qu.handler_count] qu.handler_count -= 1 qu.comrunning = False return module #DON'T ADD COMMANDS BEFORE THESE TWO #TALOS AND COMMENTS COME FIRST #talos #pass to high level interpreter from within module if com.strip().lower().split()[0] == "talos": com = " ".join(com.strip().lower().split()[1:]) #comments if com[0] == "#": return module #info if com.strip().lower() == "info": info() return module #silence if com.strip().lower() == "silence": print "silence (list/add/del)?" #silence list if com.strip().lower() == "silence list": silence_list() return module #silence add if " ".join(com.strip().lower().split()[0:2]) == "silence add": if len(com.strip().lower().split()) > 2: silence_add(" ".join(com.strip().lower().split()[2:])) else: print "Add what?" return module #silence del if " ".join(com.strip().lower().split()[0:2]) == "silence del": if len(com.strip().lower().split()) > 2: silence_del(" ".join(com.strip().lower().split()[2:])) else: print "Del what?" return module #update if com.strip().lower() == "update": update() return module #purposefail if com.strip().lower() == 'pureposefail' or com.strip().lower( ) == "purposefail": pureposefail() return module #kill thread if com.strip().lower() == "kill thread": print "Kill which thread?" return module #kill thread <num> if " ".join(com.strip().lower().split()[0:2]) == "kill thread" and len( com.strip().lower().split()) == 3: try: lltnum = int(com.strip().lower().split()[2]) print "Attempting to kill thread %s" % lltnum print "If it doesn't die it may not yet support being killed." print kill_thread(lltnum) except: print "Something went wrong. Did you enter a valid thread number?" return module #transcript without argument if com.strip().lower() == "transcript": print "Need to supply an output file" print "transcript <filename>" print "OR to just print" print "transcript !justprint!" return module #transcript if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "transcript": transcript_write(com.strip().lower().split()[1]) return module #del <var> if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "del": del_var(com.strip().lower().split()[1]) return module #copy if len(com.strip().lower().split()) == 3 and com.strip().lower().split( )[0] == "copy": copy_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module) return module #cat <var0> <var1> if len(shlex.split(com.strip().lower())) == 3 and shlex.split( com.strip().lower())[0] == "cat": lastout = cat( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2]) return module #inc if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "inc": inc(com.strip().lower().split()[1]) return module #dec if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "dec": dec(com.strip().lower().split()[1]) return module #clear if com == "clear": clear_c() return module #shell if len(shlex.split(com.strip())) > 1 and shlex.split( com.strip().lower())[0] == "shell": shell(shlex.split(com.strip())[1:]) return module #goto if len(shlex.split(com.strip().lower())) == 2 and shlex.split( com.strip().lower())[0] == "goto": return shlex.split(com.strip().lower())[1] + "|||" + module #wait if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "wait": try: wait(com.strip().lower().split()[1]) except: pass return module #echo vars_store if com.strip().lower() == "echo::vars_store": print vars_store return module #echo variables global if com.strip().lower() == "echo::variables": print variables return module #echo if len(shlex.split(com.strip().lower())) == 2 and ( shlex.split(com.strip().lower())[0] == "print" or shlex.split(com.strip().lower())[0] == "echo"): print shlex.split(com.strip().lower())[1] return module #help if com.strip().lower() == "help": print_help() return module #help module || help command if len(com.strip().lower().split()) > 1 and com.strip().lower().split( )[0] == "help": if not help_module(com.strip().lower().split()[1]): help_command(str(" ".join(com.strip().lower().split()[1:]))) return module #invoke if len(com.strip().lower().split()) >= 2 and com.strip().lower().split( )[0] == "invoke": targv = None if len(com.strip().lower().split()) > 2: targv = com.strip().lower().split()[2:] module = read_loop(filename=com.strip().lower().split()[1], doreturn=True, argv=targv) return module #list if com.strip().lower() == "list": print "list what?" return module #list modules if com.strip().lower() == "list modules": list_modules() return module #list variables if com.strip().lower() == "list variables": list_variables() return module #list commands if com.strip().lower() == "list commands": if module == "TALOS": print "no module loaded" return module else: list_commands(current) return module #list jobs if com.strip().lower() == "list jobs": if module == "TALOS": return module else: list_jobs(current) return module #list inst_vars if com.strip().lower() == "list inst_vars": list_variables(qu.variables) return module #module if com.strip().lower() == "module": print "need to specify module" return module #module <module> if "module" in com.strip().lower() and len( com.strip().lower().split()) == 2: return load_module(com.strip().lower().split()[1], module) #put if len(com.strip().lower().split()) < 3 and com.strip().lower().split( )[0] == "put": print "put what into what?" return module #put if len(shlex.split(com.strip().lower())) == 3 and shlex.split( com.strip().lower())[0] == "put": put_var( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module) return module #put <variable> <value> <required> if len(shlex.split(com.strip().lower())) == 4 and shlex.split( com.strip().lower())[0] == "put": put_var( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module, shlex.split(com.strip().lower())[3]) return module #put <variable> <value> <required> <description> if len(shlex.split(com.strip().lower())) > 4 and shlex.split( com.strip().lower())[0] == "put": put_var( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module, shlex.split(com.strip().lower())[3], " ".join(shlex.split(com.lower().strip())[4:])) return module #isset <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "isset": lastout = isset(com.strip().lower().split()[1], module) print lastout return module #length <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "length": lastout = length(_get_var(com.strip().lower().split()[1], module)) print lastout return module #pop if com.strip().lower() == "pop": print "pop what?" return module #pop <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "pop": lastout = pop_var(com.strip().lower().split()[1], None, module) return module #pop <variable> <output> if len(com.strip().lower().split()) == 3 and com.strip().lower().split( )[0] == "pop": pop_var( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module) return module #set if com.strip().lower() == "set": print "set what?" return module #set <variable> <value> if len(shlex.split(com.strip().lower())) == 3 and com.strip().lower( ).split()[0] == "set": set_var( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module) return module #set <variable> <value> <required> if len(shlex.split(com.strip().lower())) == 4 and com.strip().lower( ).split()[0] == "set": set_var( shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module, shlex.split(com.strip().lower())[3]) return module #set <variable> <value> <required> <description> if len(shlex.split(com.strip().lower())) > 4 and shlex.split( com.strip().lower())[0] == "set": set_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module, com.strip().lower().split()[3], " ".join(com.strip().lower().split()[4:])) return module #home if com.strip().lower() == "home": return 'TALOS' #exit if com.strip().lower() == "exit": exit(0) #more <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "more": more_variable(com.strip().split()[1]) return module #read notifications if com.strip().lower() == "read notifications": read_notifications() return module #read old if com.strip().lower() == "read old": read_old() return module #purge db if com.strip().lower() == "purge db": purge_db() return module #purge db admin if com.strip().lower() == "purge db admin": purge_db_admin() return module #purge log if com.strip().lower() == "purge log": purge_log("notify.log") return module #purge transcript if com.strip().lower() == "purge transcript": purge_transcript() return module #query if len(com.strip().lower().split()) > 1 and com.strip().lower().split( )[0] == "query": e = essential() e.db_exec(com.strip().lower().split()[1:]) return module ###parse commands if not isinstance(current, str): #print current.__file__ if len(com.strip().lower().split()) < 2: if com.strip().lower() in dir(current.commands): temp = com_exec_picker(com.strip().lower(), current) if temp is not None and "|||" in temp: new_mod = temp.split("|||")[0] temp = temp.split("|||")[1] module = load_module(new_mod, module) if module != module_history[-1] and module != "TALOS": current = imp.load_source('%s' % module, 'modules/%s' % (module)) mash_dictionaries(current) com_exec_picker("run", current) #print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower( ).split()[1] == "-j": if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec_background(com.strip().lower().split()[0], current) #print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower( ).split()[1] == '-d': print "Running in debug mode" if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec_picker(com.strip().lower().split()[0], current, True) #print temp return module print "No such command" return module
def parse_com(com, module, current): # help if com.strip().lower() == "help": print_help() return module # help module || help command if len(com.strip().lower().split()) > 1 and com.strip().lower().split()[0] == "help": if not help_module(com.strip().lower().split()[1]): help_command(str(com.strip().lower().split()[1:])) return module # list if com.strip().lower() == "list": print "list what?" return module # list modules if com.strip().lower() == "list modules": list_modules() return module # list variables if com.strip().lower() == "list variables": list_variables() return module # list commands if com.strip().lower() == "list commands": if module == "MAD": print "no module loaded" return module else: list_commands(current) return module # list jobs if com.strip().lower() == "list jobs": if module == "MAD": return module else: list_jobs(current) return module # module if com.strip().lower() == "module": print "need to specify module" return module # module <module> if "module" in com.strip().lower() and len(com.strip().lower().split()) == 2: return load_module(com.strip().lower().split()[1], module) # set if com.strip().lower() == "set": print "set what?" return module # set <variable> <value> if len(com.strip().lower().split()) == 3 and com.strip().lower().split()[0] == "set": set_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module) return module # set <variable> <value> <required> if len(com.strip().lower().split()) == 4 and com.strip().lower().split()[0] == "set": set_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module, com.strip().lower().split()[3]) return module # set <variable> <value> <required> <description> if len(com.strip().lower().split()) > 4 and com.strip().lower().split()[0] == "set": set_var( com.strip().lower().split()[1], com.strip().lower().split()[2], module, com.strip().lower().split()[3], " ".join(com.strip().lower().split()[4:]), ) return module # home if com.strip().lower() == "home": return "MAD" # exit if com.strip().lower() == "exit": exit(0) # more <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "more": more_variable(com.strip().split()[1]) return module # read notifications if com.strip().lower() == "read notifications": read_notifications() return module # read old if com.strip().lower() == "read old": read_old() return module # query if len(com.strip().lower().split()) > 1 and com.strip().lower().split()[0] == "query": e = essential() e.db_exec(com.strip().lower().split()[1]) return module ###parse commands if not isinstance(current, str): if len(com.strip().lower().split()) < 2: if com.strip().lower() in dir(current.commands): temp = com_exec(com.strip().lower(), current) print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower().split()[1] == "-j": print 0.1 if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec_background(com.strip().lower().split()[0], current) print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower().split()[1] == "-d": print "Running in debug mode" if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec(com.strip().lower().split()[0], current, True) print temp return module return module
def parse_com(com, module, current): global lastout if log_transcript: transcript.append(com) com = comparse(com, module, current) com = varparse(com) if not conditionparse(com): return module try: com[0] == "#" except: return module #not 100% sure this is where I want to put this #passes to launched module userHandler #We shall see if qu.comrunning and not com.strip().lower().split()[0] == "talos": try: handler = qu.handlers[qu.handler_count] except: print "Something went wrong" qu.comrunning = False return module if handler.writable(): outval = handler.parse_com(com) if not outval: del qu.handlers[qu.handler_count] qu.handler_count -= 1 qu.comrunning = False return module #DON'T ADD COMMANDS BEFORE THESE TWO #TALOS AND COMMENTS COME FIRST #talos #pass to high level interpreter from within module if com.strip().lower().split()[0] == "talos": com = " ".join(com.strip().lower().split()[1:]) #comments if com[0] == "#": return module #update if com.strip().lower() == "update": update() return module #transcript without argument if com.strip().lower() == "transcript": print "Need to supply an output file" print "transcript <filename>" print "OR to just print" print "transcript !justprint!" return module #transcript if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "transcript": transcript_write(com.strip().lower().split()[1]) return module #del <var> if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "del": del_var(com.strip().lower().split()[1]) return module #copy if len(com.strip().lower().split()) == 3 and com.strip().lower().split()[0] == "copy": copy_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module) return module #cat <var0> <var1> if len(shlex.split(com.strip().lower())) == 3 and shlex.split(com.strip().lower())[0] == "cat": lastout = cat(shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2]) return module #inc if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "inc": inc(com.strip().lower().split()[1]) return module #dec if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "dec": dec(com.strip().lower().split()[1]) return module #shell if len(shlex.split(com.strip())) > 1 and shlex.split(com.strip().lower())[0] == "shell": shell(shlex.split(com.strip())[1:]) return module #goto if len(shlex.split(com.strip().lower())) == 2 and shlex.split(com.strip().lower())[0] == "goto": return shlex.split(com.strip().lower())[1] + "|||" + module #wait if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "wait": try: wait(com.strip().lower().split()[1]) except: pass return module #echo vars_store if com.strip().lower() == "echo::vars_store": print vars_store return module #echo variables global if com.strip().lower() == "echo::variables": print variables return module #echo if len(shlex.split(com.strip().lower())) == 2 and (shlex.split(com.strip().lower())[0] == "print" or shlex.split(com.strip().lower())[0] == "echo"): print shlex.split(com.strip().lower())[1] return module #help if com.strip().lower() == "help": print_help() return module #help module || help command if len(com.strip().lower().split()) > 1 and com.strip().lower().split()[0] == "help": if not help_module(com.strip().lower().split()[1]): help_command(str(com.strip().lower().split()[1:])) return module #invoke if len(com.strip().lower().split()) >= 2 and com.strip().lower().split()[0] == "invoke": targv = None if len(com.strip().lower().split()) > 2: targv = com.strip().lower().split()[2:] module = read_loop(filename=com.strip().lower().split()[1], doreturn=True, argv=targv) return module #list if com.strip().lower() == "list": print "list what?" return module #list modules if com.strip().lower() == "list modules": list_modules() return module #list variables if com.strip().lower() == "list variables": list_variables() return module #list commands if com.strip().lower() == "list commands": if module == "TALOS": print "no module loaded" return module else: list_commands(current) return module #list jobs if com.strip().lower() == "list jobs": if module == "TALOS": return module else: list_jobs(current) return module #list inst_vars if com.strip().lower() == "list inst_vars": list_variables(qu.variables) return module #module if com.strip().lower() == "module": print "need to specify module" return module #module <module> if "module" in com.strip().lower() and len(com.strip().lower().split()) == 2: return load_module(com.strip().lower().split()[1], module) #put if len(com.strip().lower().split()) < 3 and com.strip().lower().split()[0] == "put": print "put what into what?" return module #put if len(shlex.split(com.strip().lower())) == 3 and shlex.split(com.strip().lower())[0] == "put": put_var(shlex.split(com.strip().lower())[1],shlex.split(com.strip().lower())[2], module ) return module #put <variable> <value> <required> if len(shlex.split(com.strip().lower())) == 4 and shlex.split(com.strip().lower())[0] == "put": put_var(shlex.split(com.strip().lower())[1],shlex.split(com.strip().lower())[2], module, shlex.split(com.strip().lower())[3] ) return module #put <variable> <value> <required> <description> if len(shlex.split(com.strip().lower())) > 4 and shlex.split(com.strip().lower())[0] == "put": put_var(shlex.split(com.strip().lower())[1],shlex.split(com.strip().lower())[2], module, shlex.split(com.strip().lower())[3], " ".join(shlex.split(com.lower().strip())[4:]) ) return module #isset <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "isset": lastout = isset(com.strip().lower().split()[1], module) print lastout return module #length <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "length": lastout = length(_get_var(com.strip().lower().split()[1], module)) print lastout return module #pop if com.strip().lower() == "pop": print "pop what?" return module #pop <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "pop": lastout = pop_var(com.strip().lower().split()[1], None, module) return module #pop <variable> <output> if len(com.strip().lower().split()) == 3 and com.strip().lower().split()[0] == "pop": pop_var(shlex.split(com.strip().lower())[1], shlex.split(com.strip().lower())[2], module) return module #set if com.strip().lower() == "set": print "set what?" return module #set <variable> <value> if len(shlex.split(com.strip().lower())) == 3 and com.strip().lower().split()[0] == "set": set_var(shlex.split(com.strip().lower())[1],shlex.split(com.strip().lower())[2], module) return module #set <variable> <value> <required> if len(shlex.split(com.strip().lower())) == 4 and com.strip().lower().split()[0] == "set": set_var(shlex.split(com.strip().lower())[1],shlex.split(com.strip().lower())[2], module, shlex.split(com.strip().lower())[3]) return module #set <variable> <value> <required> <description> if len(shlex.split(com.strip().lower())) > 4 and shlex.split(com.strip().lower())[0] == "set": set_var(com.strip().lower().split()[1],com.strip().lower().split()[2], module, com.strip().lower().split()[3], " ".join(com.strip().lower().split()[4:])) return module #home if com.strip().lower() == "home": return 'TALOS' #exit if com.strip().lower() == "exit": exit(0) #more <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split()[0] == "more": more_variable(com.strip().split()[1]) return module #read notifications if com.strip().lower() == "read notifications": read_notifications() return module #read old if com.strip().lower() == "read old": read_old() return module #purge log if com.strip().lower() == "purge log": purge_log("notify.log") return module #query if len(com.strip().lower().split()) > 1 and com.strip().lower().split()[0] == "query": e = essential() e.db_exec(com.strip().lower().split()[1]) return module ###parse commands if not isinstance(current, str): print current.__file__ if len(com.strip().lower().split()) < 2: if com.strip().lower() in dir(current.commands): temp = com_exec_picker(com.strip().lower(), current) if temp is not None and "|||" in temp: new_mod = temp.split("|||")[0] temp = temp.split("|||")[1] module = load_module(new_mod,module) if module != module_history[-1] and module != "TALOS": current = imp.load_source('%s' % module,'modules/%s' % (module)) mash_dictionaries(current) com_exec_picker("run",current) print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower().split()[1] == "-j": print 0.1 if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec_background(com.strip().lower().split()[0], current) print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower().split()[1] == '-d': print "Running in debug mode" if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec_picker(com.strip().lower().split()[0], current, True) print temp return module return module
def parse_com(com, module, current): #help if com.strip().lower() == "help": print_help() return module #help module || help command if len(com.strip().lower().split()) > 1 and com.strip().lower().split( )[0] == "help": if not help_module(com.strip().lower().split()[1]): help_command(str(com.strip().lower().split()[1:])) return module #list if com.strip().lower() == "list": print "list what?" return module #list modules if com.strip().lower() == "list modules": list_modules() return module #list variables if com.strip().lower() == "list variables": list_variables() return module #list commands if com.strip().lower() == "list commands": if module == "MAD": print "no module loaded" return module else: list_commands(current) return module #list jobs if com.strip().lower() == "list jobs": if module == "MAD": return module else: list_jobs(current) return module #module if com.strip().lower() == "module": print "need to specify module" return module #module <module> if "module" in com.strip().lower() and len( com.strip().lower().split()) == 2: return load_module(com.strip().lower().split()[1], module) #set if com.strip().lower() == "set": print "set what?" return module #set <variable> <value> if len(com.strip().lower().split()) == 3 and com.strip().lower().split( )[0] == "set": set_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module) return module #set <variable> <value> <required> if len(com.strip().lower().split()) == 4 and com.strip().lower().split( )[0] == "set": set_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module, com.strip().lower().split()[3]) return module #set <variable> <value> <required> <description> if len(com.strip().lower().split()) > 4 and com.strip().lower().split( )[0] == "set": set_var(com.strip().lower().split()[1], com.strip().lower().split()[2], module, com.strip().lower().split()[3], " ".join(com.strip().lower().split()[4:])) return module #home if com.strip().lower() == "home": return 'MAD' #exit if com.strip().lower() == "exit": exit(0) #more <variable> if len(com.strip().lower().split()) == 2 and com.strip().lower().split( )[0] == "more": more_variable(com.strip().split()[1]) return module #read notifications if com.strip().lower() == "read notifications": read_notifications() return module #read old if com.strip().lower() == "read old": read_old() return module #query if len(com.strip().lower().split()) > 1 and com.strip().lower().split( )[0] == "query": e = essential() e.db_exec(com.strip().lower().split()[1]) return module ###parse commands if not isinstance(current, str): if len(com.strip().lower().split()) < 2: if com.strip().lower() in dir(current.commands): temp = com_exec(com.strip().lower(), current) print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower( ).split()[1] == "-j": print 0.1 if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec_background(com.strip().lower().split()[0], current) print temp return module elif len(com.strip().lower().split()) == 2 and com.strip().lower( ).split()[1] == '-d': print "Running in debug mode" if com.strip().lower().split()[0] in dir(current.commands): temp = com_exec(com.strip().lower().split()[0], current, True) print temp return module return module