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 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 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()
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()