def configure_dexbot(config, ctx): whiptail = get_whiptail('DEXBot configure') workers = config.get('workers', {}) if not workers: while True: txt = whiptail.prompt("Your name for the worker") config['workers'] = {txt: configure_worker(whiptail, {})} if not whiptail.confirm( "Set up another worker?\n(DEXBot can run multiple workers in one instance)" ): break setup_systemd(whiptail, config) else: bitshares_instance = ctx.bitshares action = whiptail.menu( "You have an existing configuration.\nSelect an action:", [('NEW', 'Create a new worker'), ('DEL', 'Delete a worker'), ('EDIT', 'Edit a worker'), ('CONF', 'Redo general config')]) if action == 'EDIT': worker_name = whiptail.menu("Select worker to edit", [(index, index) for index in workers]) config['workers'][worker_name] = configure_worker( whiptail, config['workers'][worker_name]) strategy = StrategyBase(worker_name, bitshares_instance=bitshares_instance, config=config) strategy.clear_all_worker_data() elif action == 'DEL': worker_name = whiptail.menu("Select worker to delete", [(index, index) for index in workers]) del config['workers'][worker_name] strategy = StrategyBase(worker_name, bitshares_instance=bitshares_instance, config=config) strategy.clear_all_worker_data() elif action == 'NEW': txt = whiptail.prompt("Your name for the new worker") config['workers'][txt] = configure_worker(whiptail, {}) elif action == 'CONF': choice = whiptail.node_radiolist( msg="Choose node", items=select_choice(config['node'][0], [(index, index) for index in config['node']])) # Move selected node as first item in the config file's node list config['node'].remove(choice) config['node'].insert(0, choice) setup_systemd(whiptail, config) whiptail.clear() return config
def configure_dexbot(config, ctx): """ Main `cli configure` entrypoint :param dexbot.config.Config config: dexbot config """ whiptail = get_whiptail('DEXBot configure') workers = config.get('workers', {}) bitshares_instance = ctx.bitshares validator = ConfigValidator(bitshares_instance) if not workers: while True: txt = whiptail.prompt("Your name for the worker") if len(txt) == 0: whiptail.alert("Worker name cannot be blank. ") else: config['workers'] = { txt: configure_worker(whiptail, {}, bitshares_instance) } if not whiptail.confirm( "Set up another worker?\n(DEXBot can run multiple workers in one instance)" ): break setup_systemd(whiptail, config) else: while True: action = whiptail.menu( "You have an existing configuration.\nSelect an action:", [('LIST', 'List your workers'), ('NEW', 'Create a new worker'), ('EDIT', 'Edit a worker'), ('DEL_WORKER', 'Delete a worker'), ('ADD', 'Add a bitshares account'), ('DEL_ACCOUNT', 'Delete a bitshares account'), ('SHOW', 'Show bitshares accounts'), ('NODES', 'Edit Node Selection'), ('ADD_NODE', 'Add Your Node'), ('HELP', 'Where to get help'), ('EXIT', 'Quit this application')]) my_workers = [(index, index) for index in workers] if action == 'EXIT': # Cancel will also exit the application. but this is a clearer label # Todo: modify cancel to be "Quit" or "Exit" for the whiptail menu item. break elif action == 'LIST': if len(my_workers): # List workers, then provide option to list config of workers worker_name = whiptail.menu( "List of Your Workers. Select to view Configuration.", my_workers) content = config['workers'][worker_name] text = '\n' for key, value in content.items(): text += '{}: {}\n'.format(key, value) whiptail.view_text(text, pager=False) else: whiptail.alert('No workers to view.') elif action == 'EDIT': if len(my_workers): worker_name = whiptail.menu("Select worker to edit", my_workers) config['workers'][worker_name] = configure_worker( whiptail, config['workers'][worker_name], bitshares_instance) else: whiptail.alert('No workers to edit.') elif action == 'DEL_WORKER': if len(my_workers): worker_name = whiptail.menu("Select worker to delete", my_workers) del config['workers'][worker_name] # Pass ctx.config which is a loaded config (see ui.py configfile()), while `config` in a Config() # instance, which is empty dict, but capable of returning keys via __getitem__(). We need to pass # loaded config into StrategyBase to avoid loading a default config and preserve `--configfile` # option strategy = StrategyBase( worker_name, bitshares_instance=bitshares_instance, config=ctx.config) strategy.clear_all_worker_data() else: whiptail.alert('No workers to delete.') elif action == 'NEW': worker_name = whiptail.prompt("Your name for the new worker. ") if not worker_name: whiptail.alert("Worker name cannot be blank. ") elif not validator.validate_worker_name(worker_name): whiptail.alert( 'Worker name needs to be unique. "{}" is already in use.' .format(worker_name)) else: config['workers'][worker_name] = configure_worker( whiptail, {}, bitshares_instance) elif action == 'ADD': add_account(whiptail, bitshares_instance) elif action == 'DEL_ACCOUNT': del_account(whiptail, bitshares_instance) elif action == 'SHOW': account_list = list_accounts(bitshares_instance) if account_list: action = whiptail.menu( "Bitshares Account List (Name - Type)", account_list) else: whiptail.alert( 'You do not have any bitshares accounts in the wallet') elif action == 'ADD_NODE': txt = whiptail.prompt( "Your name for the new node: e.g. wss://dexnode.net/ws") # Insert new node on top of the list config['node'].insert(0, txt) elif action == 'NODES': choice = whiptail.node_radiolist( msg="Choose your preferred node", items=select_choice(config['node'][0], [(index, index) for index in config['node']])) # Move selected node as first item in the config file's node list config['node'].remove(choice) config['node'].insert(0, choice) setup_systemd(whiptail, config) elif action == 'HELP': whiptail.alert( "Please see https://github.com/Codaone/DEXBot/wiki") whiptail.clear() return config
def remove_offline_worker(config, worker_name, bitshares_instance): # Initialize the base strategy to get control over the data strategy = StrategyBase(worker_name, config, bitshares_instance=bitshares_instance) strategy.clear_all_worker_data()