def start_cli(topo, control_client): print('starting cli') cmd = cli.CLI() cmd.set_topo(topo) cmd.set_control_client(control_client) cmd.cmdloop()
def cli_validate(encrypt_argv=['-m', otp.securegen(100)], decrypt_argv=['-m', '{}'], execute_args={}, include_key=True): """ Calls main() with encrypt and decrypt arguments. decrypt_argv supports inserting encrypted_msg by setting -m to {} """ encrypt_args = new_argv([*encrypt_argv, '-oj', output_file]) result = execute(execute_args) encrypted_msg = result['MESSAGE'] errors = result['ERRORS'] key = result['KEY'] e_args = array_to_dict(encrypt_args[1:]) msg = e_args.get('-m') # If no msg and have a message file then load message file if not msg and e_args.get('-f'): args = {'encoding':execute_args.get('encoding', 'utf-8'), 'file_arg':'message_file', 'message_file': e_args.get('-f')} msg = cli.CLI(args).get_message_from_file() assert len(key) == len(encrypted_msg) assert len(encrypted_msg) == len(msg) assert len(errors) == 0 decrypt_argv = [ i.format(encrypted_msg) if '{}' else i for i in decrypt_argv ] key_args = ['-k', key] if not include_key: key_args = [] decrypt_args = new_argv(['-d', *decrypt_argv, *key_args, '-oj', output_file]) decrypt_result = execute(execute_args) assert msg == decrypt_result['MESSAGE'] assert len(decrypt_result['ERRORS']) == 0 assert decrypt_result['KEY'] == key
def __init__(self, args=None): """ Get the options from cli. """ self.cli = cli.CLI() self.args = self.cli.parse_arguments(args) self.lexer = lexer.Lexer()
def start_cli(ctrl): print('starting cli') cmd = cli.CLI() cmd.set_controller(ctrl) cmd.cmdloop() ctrl.teardown()
def __init__(self, args=None): """ Get the options from cli or another source (in the future), and instantiate a ShapeGrid object. """ self.cli = cli.CLI() self.args = self.cli.parse_arguments(args) self.grid = hexagon.HexagonGrid()
def __init__(self, name): self.name = name self.links = {} self.cli = cli.CLI() self.cli.add_func(self.disp_links, 'links') self.running = True self.init_cli() self.selector = selectors.DefaultSelector()
def test_encrypt_input_file(cleanup_test_file, cleanup_test_file_key, cleanup_test_encrypted_file, cleanup_output_file): for charset in util.charset_options.keys(): args = {'encoding':util.charset_get_encoding(charset), 'file_arg':'message_file', 'message_file':test_file} cli.CLI(args).store_message_file(test_file, otp.securegen(100, charset=util.charset_options[charset])) cli_validate( decrypt_argv=['-f', test_encrypted_file, '-kf', test_file_key, '--charset', charset], encrypt_argv=['-f', test_file, '-ok', test_file_key, '-o', test_encrypted_file, '--charset', charset], execute_args = {'encoding': util.charset_get_encoding(charset)}, include_key = False )
def main(): os.system('clear') slot_machine = machine.Machine(50, 1) cli.game_intro() cli.print_help() slot_machine.print_balance() while True: if slot_machine.balance > 0: cli.CLI(slot_machine) else: slot_machine.is_broke()
def main(): os.system('clear') slotMachine = machine.Machine(50, 1) cli.gameIntro() cli.printHelp() slotMachine.printBalance() while True: if slotMachine.balance > 0: cli.CLI(slotMachine) else: slotMachine.isBroke()
def __init__(self): view = None if len(sys.argv) > 1: if sys.argv[1] == "-g": # load graphic mode view = Pygame.Pygame() else: print("unknown argument") exit() else: view = cli.CLI() # load CLI mode if view is not None: self.start(view)
def __init__(self, view=None, env_config=EnvConfig(), config_filename=(res.DEFAULT_CONFIG_FILENAME + res.EXTENSIONS[0]), config_file_override=None): """ Init method for environment base creates all common objects for a given environment within the CloudFormation template including a network, s3 bucket and requisite policies to allow ELB Access log aggregation and CloudTrail log storage. :param view: View object to use. :param create_missing_files: Specifies policy to use when local files are missing. When disabled missing files will cause an IOException :param config_filename: The name of the config file to load by default. Note: User can still override this value from the CLI with '--config-file'. :param config: Override loading config values from file by providing config setting directly to the constructor """ self.config_filename = config_filename self.env_config = env_config self.config_file_override = config_file_override self.config = {} self.globals = {} self.template_args = {} self.template = None self.deploy_parameter_bindings = [] self.ignore_outputs = ['templateValidationHash', 'dateGenerated'] self.stack_outputs = {} self._config_handlers = [] self.stack_monitor = None self._ami_cache = None self.cfn_connection = None self.sts_credentials = None self.boto_session = None # self.env_config = env_config for config_handler in env_config.config_handlers: self._add_config_handler(config_handler) self.add_config_hook() # Load the user interface self.view = view if view else cli.CLI() # The view may override the config file location (i.e. command line arguments) if hasattr( self.view, 'config_filename') and self.view.config_filename is not None: self.config_filename = self.view.config_filename # Allow the view to execute the user's requested action self.view.process_request(self)
def __init__(self, config, test=False): self.rdfstore = rdf.RDFStore(config['path']['rdf_file'], config['rdf']['namespace']) self.notesstore = notes.NotesStore(config['path']['notes_dir']) self.googlestore = google_contacts.GoogleStore(self, config['google']['credentials_file'], config['google']['token_file']) self.cli = cli.CLI(self) self.editor = Editor(config['editor']) self.last_keypress = None self.contact_list = self.get_all_contacts() self.filter_string = '' self.frame = tui.ContactFrame(config, self) self.frame.init_contact_list(self.contact_list) if not test: loop = tui.ContactLoop(self.frame, config)
def importCLI(parent): """ Import a CLI instance to main CLI """ httpsrccli = cli.CLI(parent) return httpsrccli
dstJID=db.getJID(exten) if dstJID !="": print "XMPP" ami.sendXMPPMessage("xmpp:%s" % dstJID,"Call from %s" %callerid) if chanType == "PJSIP/2000": # process when channel is PJSIP/2000 playback_id = str(uuid.uuid4()) playback = channel.playWithId(playbackId=playback_id,media='sound:poc/support_team') playback.on_event('PlaybackFinished', playback_finished) if len(sys.argv)>1 and sys.argv[1]=='-c': cmd=cli.CLI() cmd.cmdloop() print "queue_ari started at %s" % time.strftime("%c") print "Asterisk ARI - connecting" client = ari.connect('http://%s:8088' % cfg.ari_host, cfg.ari_user, cfg.ari_pwd) client.on_channel_event('StasisStart', stasis_start_cb) print "Database - connecting" if cfg.db_type=='pgsql': db=dbpgsql.DBPgsql(cfg) print "Processing queues configurations" queues=queues.Queues(cfg,db)
return executor if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( 'topology_file', help='file containing the virtual network topology specification') args = parser.parse_args() # Parse topology spec topology = core.NetTopology(args.topology_file) # Build driver driver = cli.CLI() for node in topology.get_nodes(): driver.add_cli(node.get_name(), node.get_cli()) # Graceful shutdown driver.add_func(stop_network(topology.get_nodes()), ['q', 'quit']) # Activate virtual network node_threads = [Thread(target=node.run) for node in topology.get_nodes()] for t in node_threads: t.start() # Run driver driver.run() # Driver is done, wait for threads
#!/usr/bin/env python import sys sys.path.append('../') import cli # the action of the program def main(context): print "Hello, friend!" if __name__ == "__main__": APP = cli.CLI("greet") APP.version = "0.1" APP.usage = "fight the loneliness!" APP.action = main APP.run(sys.argv)
def importCLI(parent): """ Import a CLI instance to main CLI """ filecli = cli.CLI(parent) return filecli
self.pages[0].show() def handleArgs(): if sys.argv[1] == "-help": print("{} Commands:".format(TITLE)) print("-help: Shows this message.") print("-gui: Launches the gui version of {}.".format(TITLE)) print("-version: Shows the current version of {}.".format(TITLE)) # print("-update: Attempts to update {}.".format(TITLE)) elif sys.argv[1] == "-gui": root = tk.Tk() app = Application(root) app.pack() root.mainloop() elif sys.argv[1] == "-version": print("{}".format(VERSION)) else: print("Unknown argument {}.".format(sys.argv[1])) if __name__ == "__main__": if len(sys.argv) == 2: handleArgs() elif len(sys.argv) == 1: cl = cli.CLI() cl.runCLI() else: print("Too many arguments. Try running with -help.") else: pass
def importCLI(parent): """ Import a CLI instance to main CLI """ streamercli = cli.CLI(parent) return streamercli
def importCLI(parent): """ Import a CLI instance to main CLI """ netcli = cli.CLI(parent) return netcli
import cli if __name__ == '__main__': cli.CLI()
#!/usr/bin/env python3 import cli def greet(name=None, age=0): print("Hello, %s. You are %s years old." % (name, age)) def hi(): print("Hi") if __name__ == '__main__': runner = cli.CLI() # Commands can be specified with multiple names aliases = ['greet', 'g'] # Specify Args for greet function (see argparse.ArgumentParser.add_argument) name_arg = ('name', {'type':str}) age_arg = ('age', {'type':int, 'nargs': '?'}) # Add function to CLI runner.add_func(greet, aliases, name_arg, age_arg) # External CLI extern = cli.CLI() extern.add_func(hi, 'hi') # Add extern CLI to runner runner.add_cli('other', extern) # Loop from stdin (optionally takes any input stream)
# The present script is used to run properly the program. # It creates the objects for the three main classes (CLI, DataHandler and MethodHandler) and initializes # the cmdloop in which user's commands are processed. import cli import data_handler as dh import method_handler as mh import sys sys.stdout.write( 'Welcome to FinData: a simple CLI for retrieving financial data from finnhub ' + '(v. 1.0 - 14 feb 2021)' + '\n') token = 'c0f7i1748v6snrib4ca0' dataHandler = dh.DataHandler(token) dataHandler.load_db() methodHandler = mh.MethodHandler(dataHandler, token) cli_app = cli.CLI(methodHandler) cli_app.cmdloop()
def test_file_message_passing(cleanup_test_file): messages = [otp.utf_chars[-1], otp.securegen(256, charset=otp.utf_chars)] for message in messages: args = {'encoding':'utf-16', 'file_arg':'message_file', 'message_file':test_file} cli.CLI(args).store_message_file(test_file, message) assert message == cli.CLI(args).get_message_from_file()
def execute(args): main(sys.argv[1:], no_exit=True) result = cli.CLI(args={**output_file_arg(),**args}).get_message_from_file(file_arg='output_json', mode='r') return result