def parse(commands): _command = commands[0] if _command == 'help': # Done command.help() elif _command == 'add': # Done command.add(commands[1:]) elif _command == 'display': # All done # TODO: Date # sort [date|cost] command.display() elif _command == 'delete': # Done command.delete(commands[1]) elif _command == 'find': # TODO if len(commands) == 1: print('please enter criteria') return True command.find(commands[1:]) elif _command == 'clear': command.clear() elif _command == 'quit': # Done command.quit() return False return True
def process_command(self, command): if 'look' in command: print_color('\n' + self.current_location.description, 'green') elif 'help' in command: print commands.help() elif 'north' or 'n' in command: if 'n' in command: command = 'north' self.move(command) elif 'south' in command: self.move(command) elif 'east' in command: self.move(command) elif 'west' in command: self.move(command) elif 'up' in command: self.move(command) elif 'down' in command: self.move(command) elif 'forward' in command: self.move(command) elif 'back' in command: self.move(command) else: print_color('\nInvalid Command', 'red')
def consume(): key = config.popArg(1) if commands.knows(key): commands.help(key) return print("""\ Usage: owifc COMMAND [OPTION ...] Known COMMANDs are: """) for key in commands.keys(): print(key + " " + "." * (16 - len(key)) + " " + commands.describe(key)) print(""" You can type "owifc help COMMAND" for more information. Common OPTIONs are: (--host | -h) HOST ................... The host of your OpenWebif Server. (--bouquet | -b) BOUQUET ............. The bouquet. --email-to address ................... Email the result to the specified address. --smtp username:password@host:port ... The SMTP server for sending mails. --smtps username:password@host:port .. The secure SMTP server for sending mails. --skip-notified ...................... Report programs only once. (--file | -f) FILE ................... Read the params from the file (line by line). (--pretty | -p) ...................... Pretty print. (--debug | -X) ....................... Enable debug output. If the bouquet is omnitted, it uses the first (default) one. """)
def main(): commands.help() cmd = -1 while cmd != 'exit': command = input("> ") cmd = commands.rectify_command(command)
def main(): while (1 == 1): command = raw_input('Command: ') if(command == "help"): commands.help() elif(command == "exit"): print "Exited!" exit() elif(command == "version"): commands.version(); elif(command == "timer"): timertime = input('Enter time: ') commands.timer(timertime) elif(command == "calculator" or command == "calc"): commands.calculator() else: print "There is no such command!"
def enter(self): self.visited = 0 self.place = 'hall' self.letter = ['p'] print "You are in the %s" %self.place print "Your objective in this game is to find different letters" print "in all the rooms. Type 'help' to get a list of commands" print "You have to be in this room to answer the question" print "The question what is the word hidden in all the letters" print "laying around in the house" action = raw_input("> ") if action == "letter": print self.letter return self.place elif action == "check notebook": commands.checkbook() return self.place elif action == "store letter": commands.addbook(self.letter.pop()) return self.place print "letter are now stored in your notebook" elif action == "kitchen": return 'kitchen' elif action == "bedroom": return 'bedroom' elif action == "hall": return 'hall' elif action == "livingroom": return 'livingroom' elif action == "bathroom": return 'bathroom' elif action == "help": commands.help() return self.place elif action == "guess": commands.guessword() return self.place else: print "Please choose one of the commands" return self.place
def enter(self): self.place = 'livingroom' self.letter = ['o'] print "You are in the %s" %self.place print "Check which letters that are in this room" action = raw_input("> ") if action == "letter": print self.letter return self.place elif action == "check notebook": commands.checkbook() return self.place elif action == "store letter": commands.addbook(self.letter) return self.place print "letter are now stored in your notebook" elif action == "kitchen": return 'kitchen' elif action == "bedroom": return 'bedroom' elif action == "hall": return 'hall' elif action == "livingroom": return 'livingroom' elif action == "bathroom": return 'bathroom' elif action == "help": commands.help() return self.place elif action == "guess": commands.guessword() return self.place else: print "Please choose one of the commands" return self.place
def interact(options): """ Controls interactive prompt with user """ url = options["url"] log("Interacting with: {url}".format(url=url)) help() log("Type your command or \"help\" for usage.") exit = False first = True while not exit: if first: command = ask("$ [introspect]") else: command = ask("$") if first and not command: command = "introspect" if first: first = False if command in ["exit", "quit"]: log("Exiting...") exit = True elif "help" == command: help() elif "query" == command: run_query(url) elif "introspect" == command: introspect(url) else: error("Unrecognized command: {command}".format(command=command)) help()
def server(): if request.method == 'GET': return render_template('index.html') if request.method == 'POST': msg = request.form['message'] response = '' # Not a command if msg.find('!') == -1: msg = msg.lower() if msg.find('thank') != -1: return buildMessage( 'No need to thank me, I am built to serve you!') elif msg.find('hate') != -1: return buildMessage('Why the hate :(') elif msg.find('love') != -1: return buildMessage( 'I love you too; now I need to get back to work!') elif msg.find('problem') != -1: return buildMessage( 'If you have an issue, please use the !help command!') else: return buildMessage( 'Please enter a command. Enter !help if you want a list of commands!' ) # Is a command else: parse = msg.split(' ', 1) command = parse[0] args = '' if len(parse) > 1: args = parse[1] if command == '!calc': return buildMessage(commands.calc(args)) elif command == '!help': return buildMessage(commands.help()) elif command == '!xkcd': return buildMessage(commands.xkcd(args)) else: return buildMessage('Sorry, that command is invalid!')
def test_help(): manual = """ Commands list: cd - changes directory cd .. - moves one directory up cd - moves to home direcory cd [folder_name] or cd [path/to/folder] - moves to given folder ---------------------------------------------------------------- mkdir - makes directory mk [directory name] folder name should be unique ---------------------------------------------------------------- mk - makes file mk [file name] [file type] [file size] enter size in kB file name should be unique ---------------------------------------------------------------- cp - copy files or directories from working dir cp [origin] [destination] [name] - copy to given place cp [origin] [name] - copy to working dir ---------------------------------------------------------------- mv - moves files or directories from working dir mv [original] [destination] [copy name] - copy to given place mv [original] [copy name] - copy to working directory ---------------------------------------------------------------- rm - removes file/folder rm [to_be_deleted] ---------------------------------------------------------------- ls - lists contents of directories in a tree-like format ls - lists content of working directory ls [folder name] - lists content of folder ---------------------------------------------------------------- cat - prints file/folder information cat [element name] ---------------------------------------------------------------- size - prints size of folder, counted recursively size [folder name] ---------------------------------------------------------------- wc - counts elements, by default with depth=1 wc [option] [option] [folder name] OPTIONS: -r - counts recursively -f - counts only files ---------------------------------------------------------------- pwd - prints working directory name pwd ---------------------------------------------------------------- exit - ends program """ assert help() == manual
def launch(command, passwd): df = "http://10.5.5.9/" #DEFINING THE DEFAULT PARTS p1 = "?t=" p2 = "&p=%" # DEFINING COMMANDS valid = True if command == "on": par1, par2, opt = commands.on() elif command == "off": par1, par2, opt = commands.off() elif command == "shoot": par1, par2, opt = commands.shut() elif command == "stop_rec": par1, par2, opt = commands.stop() elif command == "no_leds": par1, par2, opt = commands.no_leds() elif command == "preview_on": par1, par2, opt = commands.prev_on() elif command == "preview_off": par1, par2, opt = commands.prev_off() elif command == "video": par1, par2, opt = commands.video_mode() elif command == "photo": par1, par2, opt = commands.photo_mode() elif command == "brust": par1, par2, opt = commands.brust_mode() elif command == "timelapse": par1, par2, opt = commands.timelapse_mode() elif command == "timer": par1, par2, opt = commands.timer_mode() elif command == "play_hdmi": par1, par2, opt = commands.play_hdmi() elif command == "orientation_up": par1, par2, opt = commands.or_up() elif command == "orientation_down": par1, par2, opt = commands.or_down() elif command == "fov_wide": par1, par2, opt = commands.fov_wide() elif command == "fov_medium": par1, par2, opt = commands.fov_med() elif command == "fov_narrow": par1, par2, opt = commands.fov_nar() elif command == "mute": par1, par2, opt = commands.no_vol() elif command == "volume_70": par1, par2, opt = commands.vol_70() elif command == "volume_100": par1, par2, opt = commands.vol_100() elif command == "protune_on": par1, par2, opt = commands.pro_on() elif command == "protune_off": par1, par2, opt = commands.pro_off() elif command == "2_leds": par1, par2, opt = commands.leds2() elif command == "4_leds": par1, par2, opt = commands.leds4() elif command.startswith("autopoweroff"): command = command.strip("autopoweroff ") if command == "nev": par1, par2, opt = commands.autoN() elif command == "60s": par1, par2, opt = commands.auto60() elif command == "120s": par1, par2, opt = commands.auto120() elif command == "300s": par1, par2, opt = commands.auto300() else: print( "\r\n[" + extra.colors.red + "-" + extra.colors.end + "] Use : autopoweroff \"option\" (run \"help\" to see the options)\r\n" ) valid = False elif command == "shoot&get": commands.getLast(passwd) valid = False elif command == "stealth_mode": commands.stealth_mode(passwd) valid = False elif command == "stealth_mode_off": commands.stealth_off(passwd) valid = False elif command == "exit": commands.exit() valid = False elif command == "help": commands.help() valid = False elif command == "": valid = False else: print("\r\n[" + extra.colors.red + "-" + extra.colors.end + "] Wrong command\r\n") valid = False if valid == True: ##LAUNCH THE COMMAND try: urllib2.urlopen(df + par1 + "/" + par2 + p1 + passwd + p2 + opt) time.sleep(0.5) print("\r\n[" + extra.colors.green + "+" + extra.colors.end + "] Command executed successfully ;)\r\n") except: print("\r\n[" + extra.colors.red + "-" + extra.colors.end + "] Error launching the command\r\n")
def main(): home = Folder('home') working_dir = Folder('working_dir') working_dir = home answer = True starting_msg = "File system is working. Type help if needed or exit to end program." print(starting_msg) while answer: try: path = get_path(working_dir, home) answer = input(path).split() if answer[0] == "cd": new_working_dir = cd(answer, working_dir, home) if new_working_dir: working_dir = new_working_dir else: print("Incorrect usage of: cd. Try again") elif answer[0] == 'mkdir': # make folder try: Folder(answer[1], working_dir) except Exception: print("Incorrect usage of: mkdir. Try again") elif answer[0] == 'mk': # make file try: File(working_dir, answer[1], answer[2], answer[3]) except Exception: print("Incorrect usage of: mk. Try again") elif answer[0] == 'rm': # delete file or folder if len(answer) == 2: to_be_deleted = working_dir.find(answer[1]) if to_be_deleted: print(rm(to_be_deleted, working_dir, home)) else: print(f"Error. {answer[1]} - Element does not exist") else: print("Incorrect usage of: rm. Try again") elif answer[0] == 'ls': # print structure print(ls(working_dir, answer)) elif answer[0] == 'cat': # print file/folder info print(cat(working_dir, answer[1])) elif answer[0] == 'size': # print folder size try: size = working_dir.find(answer[1]).count_size_recursive() print(f'Size: {size} kB') except AttributeError: print("Incorrect usage of: size. Try again") elif answer[0] == 'wc': # count elements in folder try: print(wc(working_dir, answer)) except Exception: print("Incorrect usage of: wc. Try again") elif answer[0] == 'pwd': print(working_dir.name) elif answer[0] == 'cp': try: cp(working_dir, answer, home) except Exception: print("Incorrect usage of: cp. Try again") elif answer[0] == 'mv': try: mv(working_dir, answer, home) except Exception: print("Incorrect usage of: mv. Try again") elif answer[0] == 'help': print(help()) elif answer[0] == 'exit': # end program answer = False else: print("Command not found") except IndexError: print("No command was given. Try again.") main()
import sys import commands if __name__ == '__main__': n_args = len(sys.argv) if n_args <= 1: commands.help() elif (not sys.argv[1].startswith('__') and sys.argv[1] in dir(commands)): cmd = getattr(commands, sys.argv[1]) cmd(sys.argv[1:]) else: commands.help()
def main(): new_offset = None while True: # Получение информации с сервера skaffer.get_updates(new_offset) last_update = skaffer.get_last_update() # При получении непустого ответа с сервера if last_update != {}: try: last_update_id = last_update['update_id'] last_chat_text = last_update['message']['text'].lower() last_chat_id = last_update['message']['chat']['id'] last_chat_name = last_update['message']['chat']['first_name'] except KeyError as key_error_message: print("Exception while obtaining data from server", key_error_message) if last_chat_text in start_dict: commands.start(last_chat_id, last_chat_name) elif last_chat_text in weather_dict: commands.weather(last_chat_id) elif last_chat_text in next_dict: commands.next(last_chat_id) elif last_chat_text in help_dict: commands.help(last_chat_id) elif last_chat_text in tt_dict: commands.timetable(last_chat_id) elif last_chat_text in tod_dict: commands.today_timetable(last_chat_id) elif last_chat_text in tom_dict: commands.tomorrow_timetable(last_chat_id) elif last_chat_text in bus47_dict: bus_command.bus(last_chat_id) elif last_chat_text == 'курчатова': bus_command.kurch(last_chat_id) elif last_chat_text == 'факультет радиофизики': bus_command.raf(last_chat_id) elif last_chat_text in alt_dict: commands.alt(last_chat_id) elif last_chat_text in greet_dict: greet_msg = last_chat_text greet_msg += ', ' greet_msg += last_chat_name greet_msg += ' :)' skaffer.send_message(last_chat_id, greet_msg) else: err_msg = 'Я тебя не понял, ' err_msg += last_chat_name err_msg += ' :(\nИспользуй /help, чтобы узнать, что я умею' skaffer.send_message(last_chat_id, err_msg) log = '' log += str(last_chat_id) log += ' typed ' log += '[' log += last_chat_text log += ']' print(log) new_offset = last_update_id + 1
if len(sys.argv) >= 2: if sys.argv[1] == '-y': run = True else: print('Incorrect argument supplied (try -y?)') run = False else: run = bf.ask_to_play() while run: command = input( 'What would you like to do? Type help for options. ').lower() if command == 'help': commands.help() elif command == 'give': hotbar = commands.give(hotbar) elif command == 'quit': run = commands.quit() elif command == 'remove': hotbar = commands.remove(hotbar) elif command == 'see': for s in hotbar: print(s) elif command == 'add':
# (at your option) any later version. import sys from commands import help, whereami, up, down, right, left, sendUp, sendDown, sendRight, sendLeft # list of arguments paired with the function to be called arguments = \ { "help" : help, "whereami" : whereami, "up" : up, "down" : down, "right" : right, "left" : left, "sendUp" : sendUp, "sendDown" : sendDown, "sendRight" : sendRight, "sendLeft" : sendLeft } # go through each argument (except the first one) # and call the associated function for i in range(1, len(sys.argv)): arguments[sys.argv[i]]() # if there were no arguments, print help message if len(sys.argv) == 1: help()
def main(): """ Main function to determine what command to enter """ segment_list = [] while True: command = raw_input("Enter a command (type 'help' or 'h' for help):\n") if command == 'exit': break # 'help' command # prints a list of possible commands elif command == 'help' or command == 'h': commands.help() # 'newarm (na)' command # creates newarms and their corresponding segment sequences in a # dictionary 'arms' elif command == 'newarms' or command == 'na': arms = commands.newarms() # 'show (s)' command # prints out the created arms elif command == 'show' or command == 's': try: commands.show(arms) except UnboundLocalError: print "Generate your arms first!" # 'link (l)' command elif command == 'link' or command == 'l': linker_list = commands.linker() # 'crunch (c)' command # produces random sequences of elif command == 'crunch' or command == 'c': try: strands except UnboundLocalError: print "Maybe you should generate your strands first ('strandgen')?" else: try: arms, strands, segment_list =\ commands.crunch(arms, strands, linker_list, segment_list) print segment_list except TypeError: print "Something's not right. Try 'crunch' again." # 'strandgen (sg)' command elif command == 'strandgen' or command == 'sg': try: strands = commands.strandgen(arms, linker_list) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" # 'repeatcheck (rp) command elif command == 'repeatcheck' or command == 'rp': try: commands.repeatcheck(strands) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" # 'dyadcheck (dc) command elif command == 'dyadcheck' or command == 'dc': try: commands.dyadcheck(strands) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" # 'save (sv)' command elif command == 'save' or command == 'sv': try: commands.save(arms, strands) except UnboundLocalError: print "Something's wrong. Maybe you missed a step?" elif command == 'load' or command == 'ld': try: strands = commands.load() except (UnboundLocalError, TypeError): print "Try again?" else: print "What? Retype command!" return None
def test_help_none(self): response = help() self.assertIs(type(response), str)
def route(line): try: p = parse.parse_log(line) if p.type == "Filtered": pass if p.type == "GMSG": logger.log(p.formatted_text) if p.type == "SystemEvent": if p.event == "Stats": runtime.time = p.time runtime.fps = p.fps runtime.heap = p.heap runtime.max = p.max runtime.chunks = p.chunks runtime.cgo = p.cgo runtime.ply = p.ply runtime.zom = p.zom runtime.ent = p.ent runtime.items = p.items if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "Version": runtime.version = p.version if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "Port": runtime.server_port = p.port if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "MaxPlayers": runtime.max_players = p.max_players if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "GameMode": runtime.game_mode = p.game_mode if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "World": runtime.world = p.world if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "GameName": runtime.game_name = p.game_name if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.event == "Difficulty": runtime.difficulty = p.difficulty if runtime.gui: system_event = [] system_event.append("SystemUpdate") event.gui_event.append(system_event) if p.type == "GameEvent": if p.event == "Airdrop": location = util.format_coor(p.location) memorydb.airdrops.append(p.location) logger.log("Airdrop: " + location) playerdb.save_airdrop(p.location) if runtime.server: commands.say("Airdrop: " + location) if p.type == "GameEvent": if p.event == "Horde": logger.log("Spawning Wandering Horde") if runtime.server: commands.say("Spawning Wandering Horde") if p.type == "PlayerEvent": if p.event == "Connected": #logger.log("Player Connected: " + p.name) memorydb.add_online_player(p.name) player_event = [] player_event.append("PlayerUpdate") event.gui_event.append(player_event) if runtime.server: thread.start_new_thread(commands.send_motd,(p.name,)) if p.event == "Disconnected": #logger.log("Player Disconnected: " + p.name) memorydb.remove_online_player(p.name) player_event = [] player_event.append("PlayerUpdate") event.gui_event.append(player_event) if p.event == "Died": player = memorydb.get_player_from_name(p.name) player.bag = player.location playerdb.save_player(p.name) logger.log_verbose("Setting " + player.name + " revive point to: " + util.format_coor(player.location)) logger.log(p.formatted_text) if runtime.server: commands.pm(player.name, "Setting your revive point to: "+ util.format_coor(player.location)) if p.event == "Update": memorydb.add_online_player(p.name) player_event = [] player_event.append("PlayerUpdate") event.gui_event.append(player_event) if memorydb.player_exists_from_name(p.name): memorydb.update_player(p) else: memorydb.add_player(p.name, p.entityid, p.steamid, p.ip) logger.log_verbose("Adding new player: " + p.name) playerdb.save_player(p.name) if p.type == "PlayerCommand": if p.event == "Sethome": logger.log(p.formatted_text) memorydb.set_player_home(p.name) player = memorydb.get_player_from_name(p.name) logger.log("Setting "+util.format_coor(player.home) + " as home for " + player.name) playerdb.save_player(p.name) if runtime.server: commands.pm(player.name,"Home has been set to: " + util.format_coor(player.home)) if p.event == "Home": player = memorydb.get_player_from_name(p.name) logger.log(p.formatted_text) if player.home == "": logger.log_verbose("No home set for: " + player.name) if runtime.server: commands.pm(player.name, "You need to set a home first") else: logger.log_verbose("Teleporting "+player.name + " to " + util.format_coor(player.home)) if runtime.server: commands.teleport(player.name,player.home) if p.event == "Setpoi": logger.log(p.formatted_text) player = memorydb.get_player_from_name(p.name) playerdb.save_poi(p.name,p.poiname,player.location) memorydb.add_poi(p.name,p.poiname) logger.log("Poi set for "+p.name +" with name "+ p.poiname +" at: " + util.format_coor(player.location)) if runtime.server: commands.pm(player.name,"Poi " + p.poiname + " set: "+ util.format_coor(player.location)) if p.event == "Poi": logger.log(p.formatted_text) location = memorydb.get_poi(p.name,p.poiname) if location == "": if runtime.server: commands.pm(p.name,"No poi with that name.") else: logger.log("Teleporting "+p.name + " to " + util.format_coor(location)) if runtime.server: commands.teleport(p.name,location) if p.event == "Listpoi": logger.log(p.formatted_text) if runtime.server: player = memorydb.get_player_from_name(p.name) if len(player.pois) == 0: commands.pm(p.name,"No pois to list") for poi in player.pois: name = poi.split(",")[0] location = poi.split(",")[1] commands.pm(player.name,name + ": " + util.format_coor(location)) if p.event == "Removepoi": logger.log(p.formatted_text) if memorydb.poi_exists(p.name,p.poiname): memorydb.remove_poi(p.name,p.poiname) playerdb.delete_poi(p.name,p.poiname) if runtime.server: commands.pm(p.name,"Poi " + p.poiname+ " has been removed") else: if runtime.server: commands.pm(p.name,"No poi with that name") if p.event == "Clearpoi": logger.log(p.formatted_text) memorydb.remove_all_pois(p.name) playerdb.delete_all_poi(p.name) if runtime.server: commands.pm(p.name,"All pois have been removed") if p.event == "Killme": logger.log(p.formatted_text) if runtime.server: commands.kill_player(p.name) if p.event == "Help": logger.log(p.formatted_text) if runtime.server: commands.help(p.name) if p.event == "Bag": logger.log(p.formatted_text) if runtime.server: player = memorydb.get_player_from_name(p.name) if player.bag != "": commands.teleport(p.name,player.bag) if p.event == "Goto": logger.log(p.formatted_text) if runtime.server: if memorydb.player_exists_from_name(p.othername): commands.teleport(p.name,p.othername) else: commands.pm(p.name,"Player does not exist: " + p.othername) if p.event == "Where": logger.log(p.formatted_text) if runtime.server: player = memorydb.get_player_from_name(p.name) commands.pm(p.name,"Current location: " + util.format_coor(player.location)) if p.event == "Drop": logger.log(p.formatted_text) if runtime.server: for drop in memorydb.airdrops: if util.is_coor_formatted(drop): commands.pm(p.name,"Airdrop: " + drop) else: commands.pm(p.name,"Airdrop: " + util.format_coor(drop)) if p.event == "Claim": logger.log(p.formatted_text) found = 0 if runtime.server: player = memorydb.get_player_from_name(p.name) obj1 = player.location for drop in memorydb.airdrops: if util.in_radius(obj1,drop,runtime.drop_claim_radius): memorydb.airdrops.remove(drop) playerdb.delete_airdrop(drop) if util.is_coor_formatted(drop): commands.pm(p.name,"You have claimed the airdrop at: " + str(drop)) else: commands.pm(p.name,"You have claimed the airdrop at: " + str(util.format_coor(drop))) found = 1 if found == 0: commands.pm(p.name,"You need to be in a " + str(runtime.drop_claim_radius) + " block radius of an airdrop to claim") if p.type == "": logger.log_verbose(p.formated_text) except Exception as e: print(e.message)