def main(): account_input = Input('请输入你的学号:') password_input = Password('请输入你的密码:') slide = SlidePrompt([account_input, password_input]) res = slide.launch() account = res[0][1] password = res[1][1] student = Student(account, password) port_confirm_input = YesNo('是否自定义教务系统端口?') slide = SlidePrompt([port_confirm_input]) res = slide.launch() port_confirm = res[0][1] if port_confirm: port_input = Input('请输入你要自定义的端口:') slide = SlidePrompt([port_input]) res = slide.launch() student.urp.port = res[0][1] while True: choices_list = ['成绩导出', '一键评教', '退出'] choice_input = Bullet('请选择你要进行操作:', choices=choices_list, margin=1) slide = SlidePrompt([choice_input]) res = slide.launch() choice = res[0][1] if choice == choices_list[0]: student.export_grade() elif choice == choices_list[1]: student.judge_all() elif choice == choices_list[2]: exit_confirm_input = YesNo('确认退出?') slide = SlidePrompt([exit_confirm_input]) res = slide.launch() if res[0][1]: sys.exit()
def run_install(app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_metadata.json'): prompt_pkg_name = 'What package from PyPI would you like to install (single pkg)? ' prompt_dep_type = 'PROD or DEV dependency? ' cli = SlidePrompt( [ Input(prompt_pkg_name, word_color=colors.foreground["yellow"]), Bullet(prompt_dep_type, choices=["PROD", "DEV"], bullet=" >", margin=2, bullet_color=colors.bright(colors.foreground["cyan"]), background_on_switch=colors.background["black"], word_color=colors.foreground["white"], word_on_switch=colors.foreground["white"]), ] ) result = cli.launch() cli.summarize() pkg_name = '' dep_type = 'PROD' for result_item in result: key, value = result_item if key == prompt_pkg_name: pkg_name = value elif key == prompt_dep_type: dep_type = value if (len(pkg_name) < 1): sys.exit(Fore.RED + 'The PyPI package name to be installed should contain at least one character.') subprocess.call(f'source {app_path}/bin/install_pypi_pkg.sh "{pkg_name}" "{dep_type}" "{app_path}"', shell=True) sys.exit()
def run_reinstall(app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_metadata.json'): prompt_are_you_sure = 'Are you sure, you want to reinstall all dependencies? Are you sure, you are in an active virtualenv? ' cli = SlidePrompt( [ Bullet(prompt_are_you_sure, choices=['No', 'Yes'], bullet=" >", margin=2, bullet_color=colors.bright(colors.foreground["cyan"]), background_on_switch=colors.background["black"], word_color=colors.foreground["white"], word_on_switch=colors.foreground["white"]), ] ) result = cli.launch() cli.summarize() choice = 'No' for result_item in result: key, value = result_item if key == prompt_are_you_sure: choice = value if choice == 'Yes': subprocess.call(f'source {app_path}/bin/reinstall_reqs.sh "{app_path}"', shell=True) sys.exit()
def AddAdvice(): clear() Add = SlidePrompt([ Input("Marca del teléfono: ", default="", word_color=colors.foreground["yellow"]), Bullet("Sistema operativo:", choices=["Android", "IOS"], margin=2, background_on_switch=colors.background["white"], word_on_switch=colors.foreground["black"]), Numbers("RAM: ", word_color=colors.foreground["yellow"], type=int), Input("CPU: ", default="", word_color=colors.foreground["yellow"]), Numbers("Números de ventas en el año: ", word_color=colors.foreground["yellow"], type=int) ]) actualDevice = Add.launch() deviceDic = { 'brand': actualDevice[0][1], 'os': actualDevice[1][1], 'ram': actualDevice[2][1], 'cpu': actualDevice[3][1], 'sales': actualDevice[4][1] } devices.append(deviceDic)
def run_scaffold(jetzt_home=None, app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_metadata.json'): cli = SlidePrompt( [ Input("What is the name of your project? ", word_color=colors.foreground["yellow"]), Bullet("What kind of project would you like to scaffold? ", choices=["Python - [Blank]", "Python - Flask", "Python - Jupyter"], bullet=" >", margin=2, bullet_color=colors.bright(colors.foreground["cyan"]), # background_color=colors.background["black"], background_on_switch=colors.background["black"], word_color=colors.foreground["white"], word_on_switch=colors.foreground["white"]), ] ) result = cli.launch() cli.summarize() project_name = '' project_type = '' for result_item in result: key, value = result_item if key == 'What is the name of your project? ': project_name = value elif key == 'What kind of project would you like to scaffold? ': project_type = value # Make project_name safe project_name = "".join([c for c in project_name if c.isalpha() or c.isdigit() or c == '_' or c == '-']).rstrip() ''' There should be at least one character in the project (directory) name. ''' if (len(project_name) < 1): sys.exit(Fore.RED + 'The project_name should contain at least one character.') ''' Let's validate paths. ''' if os.path.exists(jetzt_home) and os.path.isdir(jetzt_home): os.chdir(jetzt_home) ''' Again, let's make sure we do not try to create a project dir, which already exists. ''' if os.path.exists(project_name): sys.exit(Fore.RED + 'The project directory already exists.') # Create project root os.mkdir(project_name) jetzt_metadata['project_name'] = project_name jetzt_metadata['project_type'] = project_type dump_jetzt_metadata(jetzt_metadata, f"{project_name}/{jetzt_metadata_file}") ''' Call a shell script to install packages etc. ''' subprocess.call(f'source {app_path}/bin/jetzt_scaffold.sh {jetzt_home} {project_name} "{project_type}" "{app_path}"', shell=True) print(Fore.GREEN + 'Scaffold complete.') print('To jump in the new environment, run:') print(Fore.GREEN + f'cd {jetzt_home}/{project_name} && source venv/bin/activate') sys.exit()
def get_string(prompt, default_string=" "): cli = SlidePrompt([ Input(prompt, default=default_string, word_color=colors.foreground["yellow"]), ]) result = cli.launch() for p, ans in result: if p == prompt: if ans == default_string: return False return ans
def select_bullet(prompt, choice_list): cli = SlidePrompt([ Bullet( prompt, choices=choice_list, bullet=" >", margin=2, ), ]) result = cli.launch() for p, ans in result: if p == prompt: return ans
def run_update(app_path=None, jetzt_metadata=None, jetzt_metadata_file='jetzt_metadata.json'): prompt_pkg_name = 'Which of these would you like to update? ' pkg_list = [] ''' Read existing metadata if available. ''' if os.path.exists(jetzt_metadata_file): with open(jetzt_metadata_file) as metadata_file: metadata = json.load(metadata_file) if 'pending_dependency_updates' in metadata: if 'dependencies' in metadata['pending_dependency_updates']: for key, value in metadata['pending_dependency_updates']['dependencies'].items(): pkg_list.append(f"[PROD] {value['package']}: {value['installed_version']} > {value['latest_version']}") if 'dev_dependencies' in metadata['pending_dependency_updates']: for key, value in metadata['pending_dependency_updates']['dev_dependencies'].items(): pkg_list.append(f"[DEV] {value['package']}: {value['installed_version']} > {value['latest_version']}") cli = SlidePrompt( [ Bullet(prompt_pkg_name, choices=pkg_list, bullet=" >", margin=2, bullet_color=colors.bright(colors.foreground["cyan"]), background_on_switch=colors.background["black"], word_color=colors.foreground["white"], word_on_switch=colors.foreground["white"]), ] ) result = cli.launch() cli.summarize() pkg_name = '' pkg_to_update = '' dep_type = '' for result_item in result: key, value = result_item if key == prompt_pkg_name: pkg_name = value match_object = re.match(r'^\[(?P<dep_type>\w+)\]\s+(?P<pkg_to_update>[\w\-]+):.*$', pkg_name) if match_object: dep_type = match_object.group('dep_type') pkg_to_update = match_object.group('pkg_to_update') subprocess.call(f'source {app_path}/bin/update_pypi_pkg.sh "{pkg_to_update}" "{dep_type}" "{app_path}" ', shell=True) sys.exit()
def menu_start(): #UI Colour assignment bright_cyan = colors.bright(colors.foreground["cyan"]) choices = is_users() menu = SlidePrompt([ Bullet("\nOparu v0.0.1", choices=choices, bullet="", indent=0, pad_right=8, shift=1, align=1, margin=2) ]) result = menu.launch() if result[0][1] == "Continue": continue_user() else: new_user()
margin = 2, bullet_color = colors.bright(colors.foreground["cyan"]), background_color = colors.background["black"], background_on_switch = colors.background["black"], word_color = colors.foreground["white"], word_on_switch = colors.foreground["white"] ), Check("What food do you like? ", choices = ["🍣 Sushi", "🍜 Ramen", "🌭 Hotdogs", "🍔 Hamburgers", "🍕 Pizza", "🍝 Spaghetti", "🍰 Cakes", "🍩 Donuts"], check = " √", margin = 2, check_color = colors.bright(colors.foreground["red"]), check_on_switch = colors.bright(colors.foreground["red"]), background_color = colors.background["black"], background_on_switch = colors.background["white"], word_color = colors.foreground["white"], word_on_switch = colors.foreground["black"] ), ] ) print('\n') result = cli.launch() cli.summarize()
import csv from tensorflow.keras.callbacks import TensorBoard from cliparser import n_split, epochs, model_nom, pathData, optimizer, dropout1, dropout2, batch_size, learningrate, momentum, nesterov, beta1, beta2, amsgrad, tflite import sklearn.metrics as metrics import pandas as pd import matplotlib.pyplot as plt import numpy as np import itertools # add prompt line for model noun to crush it if it's already existent or exit if not if model_nom + '.h5' in os.listdir('Models/'): cli = SlidePrompt([ YesNo("file already exist, do you want to overwrite it :", word_color=colors.foreground["yellow"]) ]) choice = cli.launch() if choice[0][1] == True: os.remove("Models/" + model_nom + ".h5") else: exit() # create a folder of logs including models in orther to visualize them with tensorboard tool tensorboard = TensorBoard(log_dir='logs/{}'.format(model_nom)) # create path data PATH = os.path.join(pathData) # define training and validation paths train_dir = os.path.join(PATH, 'train') validation_dir = os.path.join(PATH, 'validation')
def yes_no(prompt, default_yes=False): cli = SlidePrompt([YesNo(prompt, default="y" if default_yes else "n")]) result = cli.launch() for p, ans in result: if prompt in p: return ans