def remove_offline_worker(config, worker_name): # Initialize the base strategy to get control over the data bitshares_instance = BitShares(config['node']) strategy = BaseStrategy(worker_name, config, bitshares_instance=bitshares_instance) strategy.purge()
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", [(i, i) for i in workers]) config['workers'][worker_name] = configure_worker( whiptail, config['workers'][worker_name]) strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance) strategy.purge() elif action == 'DEL': worker_name = whiptail.menu("Select worker to delete", [(i, i) for i in workers]) del config['workers'][worker_name] strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance) strategy.purge() 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], [(i, i) for i 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): d = get_whiptail() workers = config.get('workers', {}) if not workers: while True: txt = d.prompt("Your name for the worker") config['workers'] = {txt: configure_worker(d, {})} if not d.confirm( "Set up another worker?\n(DEXBot can run multiple workers in one instance)" ): break setup_systemd(d, config) else: action = d.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 = d.menu("Select worker to edit", [(i, i) for i in workers]) config['workers'][worker_name] = configure_worker( d, config['workers'][worker_name]) bitshares_instance = BitShares(config['node']) strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance) strategy.purge() elif action == 'DEL': worker_name = d.menu("Select worker to delete", [(i, i) for i in workers]) del config['workers'][worker_name] bitshares_instance = BitShares(config['node']) strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance) strategy.purge() elif action == 'NEW': txt = d.prompt("Your name for the new worker") config['workers'][txt] = configure_worker(d, {}) elif action == 'CONF': config['node'] = d.prompt("BitShares node to use", default=config['node']) setup_systemd(d, config) d.clear() return config
def remove_offline_worker(config, worker_name): # Initialize the base strategy to get control over the data strategy = BaseStrategy(worker_name, config) strategy.purge()
def remove_offline_bot(config, bot_name): # Initialize the base strategy to get control over the data strategy = BaseStrategy(config, bot_name) strategy.purge()
def configure_dexbot(config, shell=False): global bitshares_instance d = get_whiptail() workers = config.get('workers', {}) if len(workers) == 0: d.view_text("""Welcome to the DEXBot text-based configuration. You will be asked to set up at least one bot, this will then run in the background. You can use the arrow keys or TAB to move between buttons, and RETURN to select, the mouse does not work. Use Space to select an item in a list. Selecting Cancel will exit the program. """) while True: txt = d.prompt("Your name for the new worker") config['workers'] = {txt: configure_worker(d, {})} if not d.confirm("Set up another worker?\n(DEXBot can run multiple workers in one instance)"): break setup_systemd(d, config, shell) add_key(d, bitshares_instance) return True else: menu = [('NEW', 'Create a new bot'), ('DEL', 'Delete a bot'), ('EDIT', 'Edit a bot'), ('REPORT', 'Configure reporting'), ('NODE', 'Set the BitShares node'), ('KEY', 'Add a private key'), ('WIPE', 'Wipe all private keys'), ('LOG', 'Show the DEXBot event log'), ('SHELL', 'Escape to the Linux command shell')] if shell: menu.extend([('PASSWD', 'Set the account password'), ('LOGOUT', 'Logout of the server')]) else: menu.append(('QUIT', 'Quit without saving')) action = d.menu("Select an action:", menu) if action == 'EDIT': worker_name = d.menu("Select worker to edit", [(i, i) for i in workers]) config['workers'][worker_name] = configure_worker(d, config['workers'][worker_name]) strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance) if not bitshares_instance: bitshares_instance = BitShares(config['node']) unlock_wallet(d, bitshares_instance) strategy.purge() return True elif action == 'DEL': worker_name = d.menu("Select worker to delete", [(i, i) for i in workers]) del config['workers'][worker_name] if not bitshares_instance: bitshares_instance = BitShares(config['node']) unlock_wallet(d, bitshares_instance) strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance) strategy.purge() return True elif action == 'NEW': txt = d.prompt("Your name for the new worker") config['workers'][txt] = configure_worker(d, {}) return True elif action == 'REPORT': setup_reporter(d, config) return True elif action == 'NODE': config['node'] = d.prompt( "BitShares node to use", default=config['node']) return True elif action == 'KEY': add_key(d, bitshares_instance) return False elif action == 'WIPE': if not bitshares_instance: bitshares_instance = BitShares() if bitshares_instance.wallet.created(): if d.confirm("Really wipe your wallet of keys?", default='no'): unlock_wallet(d, bitshares_instance) bitshares_instance.wallet.wipe(True) else: d.alert("No wallet to wipe") return False elif action == 'LOG': os.system("journalctl --user-unit=dexbot -n 1000 -e") return False elif action == 'LOGOUT': sys.exit() elif action == 'PASSWD': os.system("passwd") return False elif action == 'SHELL': os.system("/bin/bash") return False elif action == 'QUIT': return False else: d.prompt("Unknown command {}".format(action)) return False