def draw_images_menu(self): menu_option = [img.tags for img in self.docker_client.images.list()] selection = SelectionMenu.get_selection( menu_option, title='Select an image to initialize container', subtitle='It is recommended to Save Image after running ' + 'install script') return self.docker_client.images.list()[selection]
def draw_options_menu(self): menu_option = [ 'Open Terminal -- opens a terminal window attached to container', 'Stop -- stops the container', 'Save Image -- commits container to image', 'Build Image -- runs docker build (caution)' ] selection = SelectionMenu.get_selection(menu_option) return selection
def prompt_device(cls): device_name = input("输入你的手机名字,空值是随机生成:") or choice( cls.random_device_list) carrier = cls.random_carrier_list[SelectionMenu.get_selection( cls.random_carrier_list, title="选择你的运营商:", exit_option=False)] android_version = input("输入你的系统版本号,空值是随机生成:") or choice( cls.random_android_version) os_name = f"{device_name}运营商:{carrier}\n{android_version}" device_id = input("输入手机的 IMEI,空值是随机生成:") or uuid4() return DeviceInfo(os_name, device_id)
def promptForRegion(regionData): regionNames = [region["data"]["name"] for region in regionData["regions"]] title = "Creating a new cluster. Select your Elastic Cloud region" selection = SelectionMenu.get_selection(regionNames, title=title) if selection > (len(regionNames) - 1): sys.exit("Canceled region selection") else: selectedRegion = regionData["regions"][selection] # print(selectedRegion) return selectedRegion["identifier"]
def build_menu(self): ''' Build a dynamic menu starting from the config read by a json converted to a dict ''' self.layouts = self.get_layout_list( self.raw_json['globals']['layout_home']) selection_menu = SelectionMenu.get_selection(self.layouts) self.logger.info("[Dyn_menu] Selected the %s option: " % self.layouts[int(selection_menu)]) return self.layouts[int(selection_menu)]
def pick_release(all_versions): releases = list(all_versions.keys()) if 'cursesmenu' in sys.modules: selection = SelectionMenu.get_selection( releases, title='Pick a release to verify') if selection < len(releases): version = releases[selection] else: sys.exit(0) else: print(' '.join(releases)) version = input('enter version to sanity check: ') return all_versions[version]
def __init__(self, stdscr): self.stdscr = stdscr self.docker_client = docker.from_env() # Check if docker server is running try: self.docker_client.info() except Exception: assert False, 'Is Docker server running?' # Attempt to load container, if can't then later ask user to select image self.container = None # If container is currently running if "RustyROS" in [ x.name for x in self.docker_client.containers.list() ]: self.container = self.docker_client.containers.get('RustyROS') # Check if container is stopped, but still exists else: try: self.container = self.docker_client.containers.get('RustyROS') self.container.start() except Exception: self.container = None # if no docker images are avaliable, go ahead and build one if not self.docker_client.images.list(): self.brand_new_docker_image() # attempt to find what kind of terminal emulator is being used self.terminal = None aval_term = self.find_avaliable_terminal() assert aval_term is not None, 'No terminal found' # Ask for a selection from user selection = SelectionMenu.get_selection( aval_term, title='Select a terminal') if selection > len(aval_term): return self.terminal = aval_term[selection] # run curses stuff self.draw()
def third_selection(res): for names in res.keys(): with open(f'{names}.txt', 'w') as text_file: print( f'Dear {names},\nThank you for your very kind donation of ${sum(res[names])}.\nIt will be put to very good use.\nSincerely,\n-The Team', file=text_file) if __name__ == "__main__": donors = { 'Batman': [100, 50, 30], 'Ironman': [70, 80], 'Hulk': [10], 'Spiderman': [40, 20], 'Superman': [40, 60, 10] } a_list = [ 'Send a Thank You', 'Create a Report', 'Send letters to everyone' ] selection_dict = { 0: first_selection, 1: second_selection, 2: third_selection } while True: selection = SelectionMenu.get_selection(a_list) if selection == 3: break selection_dict.get(selection)(donors)
required=True) args = parser.parse_args() ##################################################### ##################################################### print ("1. Loading Dataset") dataset = ds.PinterestDataset(args.dataset) dataset.init_from_file() cfg_folder = os.path.join(dataset.dnn_dir, "_configs") config_list = [f for f in os.listdir(cfg_folder) if os.path.isfile(os.path.join(cfg_folder, f))] selection = \ SelectionMenu.get_selection(config_list, title='DNN - Trainer', subtitle="Please select configuration file\ from list", exit_option=True) if selection == len(config_list): print ("No choice made. Exit...") exit() # Some General Config with open(os.path.join(cfg_folder, config_list[selection]), 'r') \ as outfile: config = json.load(outfile) print ("Selected Config File:", config_list[selection]) for key, val in config["meta"].iteritems(): print ('\t{0:<20} :: {1:<50}'.format(key, val))
return release['assets'] def gpg_sanity_check(): pass # main starts here for now signal.signal(signal.SIGINT, signal_handler) all_release_info = augur_app_all_releases() release_versions = all_release_versions(all_release_info) # promt for version if 'cursesmenu' in sys.modules: selection = SelectionMenu.get_selection(release_versions, title='Pick a release to verify') if selection < len(release_versions): version = release_versions[selection] else: sys.exit(0) else: print(' '.join(release_versions)) version = input('enter version to sanity check') file_extensions = ['dmg', 'deb', 'exe', 'snap'] assets = assets_for_version(all_release_info, version) headers['Accept'] = 'application/octet-stream' comparison = {} for asset in assets:
def brand_new_docker_image(self): if os.path.isfile('./.Dockerfile_old'): assert False, 'Previous build abruptly closed. "git log" and remove bad files, or git reset' self.stdscr.clear() # Check if user has an ssh directory ssh_dir = os.path.expanduser("~/.ssh") if os.path.isdir(ssh_dir): # Store all files in a list ssh_key_files = [ f for f in os.listdir(ssh_dir) if os.path.isfile(os.path.join(ssh_dir, f)) ] # Ask for a selection from user selection = SelectionMenu.get_selection( ssh_key_files, title='Select a ssh key (i.e. for github)?', subtitle='This will copy the selected ssh key to docker image') # Check if user did not select exit if (selection < len(ssh_key_files)): # Copy the ssh key to relative path for docker shutil.copy(ssh_dir + '/' + ssh_key_files[selection], '.') # Replace the template placeholder with correct key and location with open('./Dockerfile', 'r') as input_file, open( './.Dockerfile_tmp', 'w') as output_file: for line in input_file: if line.strip() == '# COPY ssh_github_key': output_file.write( 'COPY ' + ssh_key_files[selection] + ' /home/mil/.ssh/' + ssh_key_files[selection] + '\n') else: output_file.write(line) # Store the old Dockerfile shutil.copy('./Dockerfile', './.Dockerfile_old') # Replace the orignal Dockerfile with filled-template file os.rename('./.Dockerfile_tmp', './Dockerfile') self.stdscr.clear() height, width = self.stdscr.getmaxyx() text = "Building image..." [:width - 1] text1 = "To view build process:" [:width - 1] text2 = "docker ps" [:width - 1] text3 = "docker attach NAME" [:width - 1] # Find center of window x = int((width // 2) - (len(text) // 2) - len(text) % 2) y = int((height // 2) - 2) self.stdscr.addstr(y, x, text) self.stdscr.addstr(y + 1, x, text1) self.stdscr.addstr(y + 2, x, text2) self.stdscr.addstr(y + 3, x, text3) self.stdscr.refresh() # Assume dockerfile is in the same relative directory self.docker_client.images.build(path='./', tag='mil_image:latest') # If user made a selection for ssh key if os.path.isfile( './.Dockerfile_old') and selection < len(ssh_key_files): # Return back to the original Dockerfile os.rename('./.Dockerfile_old', './Dockerfile') # Delete the copy of ssh key os.remove(ssh_key_files[selection])
import lh3.api import os import sys import tempfile parser = argparse.ArgumentParser(description='Edit users') parser.add_argument('-u', '--username', help='user name') args = parser.parse_args() client = lh3.api.Client() users = client.all('users').get_list() if args.username: user = next(user for user in users if user['name'] == args.username) else: selection = SelectionMenu.get_selection([user['name'] for user in users]) user = users[selection] details = client.api().get('v1', '/users/{}'.format(user['id'])) print(details) _, temp = tempfile.mkstemp(suffix='.tmp') with open(temp, 'w') as f: f.write("name: {}\n".format(user['name'])) for k, v in details.items(): f.write("{}: {}\n".format(k, v)) f.write("password:\n") f.flush() EDITOR = os.environ.get('EDITOR', 'vim') call([EDITOR, temp])
import os import sys import tempfile parser = argparse.ArgumentParser(description='Edit a FAQ template') parser.add_argument('-f', '--faq', help='faq name') parser.add_argument('-t', '--template', help='template name') args = parser.parse_args() client = lh3.api.Client() faqs = client.all('faqs').get_list() if args.faq: faq = (faq for faq in faqs if faq['name'] == faq_name).next() else: selection = SelectionMenu.get_selection([f['name'] for f in faqs]) faq = faqs[selection] faq_id = faq['id'] templates = client.one( 'faqs', faq_id).all('templates').get_list(params={'format': 'json'}) if args.template: template_name = args.template if template_name.find('.html') == -1: template_name += '.html' template_name = unicode(template_name, 'utf-8') template = (template for template in templates if template['name'] == template_name).next() else: selection = SelectionMenu.get_selection([t['name'] for t in templates]) template = templates[selection]
# _menu["store-list"]=["SHA", "JEW", "INT"] # _menu["l3fwrules"] = ["l3fwrules_004", "l3fwrules_005", "l3fwrules_006", "l3fwrules_007"] _menu["main"] = [ "networks", "stores", "l3fwrules", "s2svpnrules", "vlans", "convert" ] _menu["networks"] = ["actions", "settings"] _menu["stores"] = ["actions", "settings"] _menu["l3fwrules"] = ["actions", "settings"] _menu["s2s"] = ["actions", "settings"] _menu["networks"] = ["actions", "settings"] _menu["store-list"] = ["SHA", "JEW", "INT"] _menu["l3fwrules"] = [ "l3fwrules_004", "l3fwrules_005", "l3fwrules_006", "l3fwrules_007" ] menu_in_use = _menu["main"] while True: selection = SelectionMenu.get_selection(menu_in_use) # print (selection) # time.sleep(3) if selection == len(menu_in_use): os._exit(0) item = menu_in_use[selection] curses.wrapper(draw, item) if menu_in_use is _menu["main"]: menu_in_use = _menu[item] else: menu_in_use = _menu["main"]