def check_all(ctx, apps_folder: Path, gentoo_overlay_repo: str, github_user: str, verbose: int, verbose_inf: bool, local: bool, ): not_root() tty, verbose = tv(ctx=ctx, verbose=verbose, verbose_inf=verbose_inf, ) ic(apps_folder) edit_configs = find_edit_configs(apps_folder=apps_folder, verbose=verbose, ) for edit_config_path in edit_configs: ic(edit_config_path) with chdir(edit_config_path.parent): remote = str(sh.git.remote('get-url', 'origin')).strip() app_name, app_user, app_module_name, app_path = parse_url(remote, apps_folder=apps_folder, verbose=verbose, ) if not remote.startswith('[email protected]:'): if app_user == github_user: ic('remote is to', github_user, 'but does not startwith [email protected]:', remote) raise ValueError(edit_config_path, remote) if not app_name == edit_config_path.parent.name: ic(app_name, 'is not', edit_config_path.parent.name) raise ValueError(edit_config_path, remote) del app_name, app_user, app_module_name, app_path
def list_all(ctx, apps_folder: Path, ls_remote: bool, verbose: int, verbose_inf: bool, ): tty, verbose = tv(ctx=ctx, verbose=verbose, verbose_inf=verbose_inf, ) apps_folder = Path(apps_folder) ic(apps_folder) edit_configs = find_edit_configs(apps_folder=apps_folder, verbose=verbose, ) for config in edit_configs: if verbose: ic(config) if ls_remote: project_dir = config.parent return_code = None if verbose: ic(project_dir) with chdir(project_dir): try: sh.git('ls-remote') return_code = 0 except sh.ErrorReturnCode_128: return_code = 128 print(return_code, config.parent.name) else: print(config.parent.name)
def write_sysfs_partition( ctx, devices: Tuple[Path, ...], filesystem: str, force: bool, exclusive: bool, raid: str, raid_group_size: int, pool_name: str, verbose: int, verbose_inf: bool, ): tty, verbose = tv( ctx=ctx, verbose=verbose, verbose_inf=verbose_inf, ) devices = tuple([Path(_device) for _device in devices]) ic('creating sysfs partition on:', devices) if filesystem == 'zfs': assert pool_name for device in devices: if not device.name.startswith('nvme'): assert not device.name[-1].isdigit() assert path_is_block_special(device) assert not block_special_path_is_mounted( device, verbose=verbose, ) if not force: warn( devices, verbose=verbose, ) if filesystem in ['ext4', 'fat32']: assert len(devices) == 1 if exclusive: #destroy_block_device_head_and_tail(device=device, force=True) #these are done in create_root_device #write_gpt(device) partition_number = '1' start = "0%" end = "100%" else: partition_number = '3' start = "100MiB" end = "100%" run_command("parted -a optimal " + devices[0].as_posix() + " --script -- mkpart primary " + filesystem + ' ' + start + ' ' + end, verbose=verbose) run_command( "parted " + devices[0].as_posix() + " --script -- name " + partition_number + " rootfs", verbose=verbose, ) time.sleep(1) sysfs_partition_path = add_partition_number_to_device( device=devices[0], partition_number=partition_number, verbose=verbose, ) if filesystem == 'ext4': ext4_command = sh.Command('mkfs.ext4') ext4_command(sysfs_partition_path.as_posix(), _out=sys.stdout, _err=sys.stderr) elif filesystem == 'fat32': mkfs_vfat_command = sh.Command('mkfs.vfat', sysfs_partition_path.as_posix()) mkfs_vfat_command(_out=sys.stdout, _err=sys.stderr) else: eprint("unknown filesystem:", filesystem) sys.exit(1) elif filesystem == 'zfs': assert exclusive assert False ctx.invoke( write_zfs_root_filesystem_on_devices, ctx=ctx, devices=devices, mount_point=None, force=True, raid=raid, raid_group_size=raid_group_size, pool_name=pool_name, verbose=verbose, ) else: eprint("unknown filesystem:", filesystem) sys.exit(1)
def new(ctx, language: str, repo_url: str, group: str, branch: str, rename: Optional[str], templates: Optional[tuple[Path]], apps_folder: str, gentoo_overlay_repo: str, github_user: str, license: str, owner: str, owner_email: str, description: str, local: bool, use_existing_repo: bool, verbose: int, verbose_inf: bool, hg: bool, ): not_root() tty, verbose = tv(ctx=ctx, verbose=verbose, verbose_inf=verbose_inf, ) apps_folder = Path(apps_folder) ic(apps_folder) if templates: templates = [t.resolve() for t in templates] if repo_url.endswith('.git'): repo_url = repo_url[:-4] assert '/' not in group assert ':' not in group assert group in portage_categories() assert repo_url.startswith('https://') template_repo_url: Optional[str] = None if not repo_url.startswith('https://github.com/{}/'.format(github_user)): template_repo_url = repo_url _app_name, _app_user, _app_module_name, _app_path = parse_url(repo_url, apps_folder=apps_folder, verbose=verbose, ) if rename: _app_name = rename repo_url = 'https://github.com/{github_user}/{app_name}'.format(github_user=github_user, app_name=_app_name) del _app_name, _app_user, _app_module_name, _app_path else: template_repo_url = None app_name, app_user, app_module_name, app_path = parse_url(repo_url, apps_folder=apps_folder, verbose=verbose, ) ic(app_name) ic(app_user) assert app_user == github_user assert '_' not in app_path.name if language == 'sh': language = 'bash' if language == 'python': ext = '.py' elif language == 'bash': ext = '.sh' elif language == 'zig': ext = '.zig' assert group == 'dev-zig' elif language == 'c': ext = '.c' else: raise ValueError('unsupported language: ' + language) if template_repo_url: clone_repo(repo_url=repo_url, template_repo_url=template_repo_url, apps_folder=apps_folder, hg=hg, branch=branch, app_path=app_path, app_group=group, local=local, verbose=verbose, ) if ((not app_path.exists()) or use_existing_repo): if not use_existing_repo: create_repo(hg=hg, app_path=app_path, app_module_name=app_module_name, verbose=verbose, ) else: assert app_path.is_dir() assert Path(app_path / Path('.git')).exists() with chdir(app_path): os.makedirs(app_module_name, exist_ok=True) if not template_repo_url: with chdir(app_path): if language == 'python': write_setup_py(use_existing_repo=use_existing_repo, app_module_name=app_module_name, app_name=app_name, owner=owner, owner_email=owner_email, description=description, license=license, repo_url=repo_url,) gitignore_template = generate_gitignore_template() if use_existing_repo: with open('.gitignore', 'a') as fh: fh.write(gitignore_template) else: with open('.gitignore', 'x') as fh: fh.write(gitignore_template) if not Path('url.sh').exists(): write_url_sh(repo_url, verbose=verbose,) if language == 'python': os.system("fastep") with chdir(app_path / app_module_name): app_template = generate_app_template(package_name=app_module_name, language=language, append_files=templates, verbose=ctx.obj['verbose'], ) with open(app_module_name + ext, 'x') as fh: fh.write(app_template) if language == 'python': init_template = generate_init_template(package_name=app_module_name) with open("__init__.py", 'x') as fh: fh.write(init_template) sh.touch('py.typed') with chdir(app_path): sh.git.add('--all') sh.git.commit('-m', 'autocomit') with chdir(app_path): with open(".edit_config", 'x') as fh: fh.write(generate_edit_config(package_name=app_name, package_group=group, local=local)) remote_add_origin(hg=hg, app_path=app_path, local=local, app_name=app_name, verbose=verbose, ) else: eprint("Not creating new app, {} already exists.".format(app_path)) ebuild_path = Path(gentoo_overlay_repo) / Path(group) / Path(app_name) if not ebuild_path.exists(): enable_python = False if Path(app_path / Path('setup.py')).exists(): enable_python = True os.makedirs(ebuild_path, exist_ok=False) ebuild_name = app_name + "-9999.ebuild" enable_dobin = False if language in ['bash']: enable_dobin = True with chdir(ebuild_path): with open(ebuild_name, 'w') as fh: fh.write(generate_ebuild_template(app_name=app_name, description=description, enable_python=enable_python, enable_dobin=enable_dobin, homepage=repo_url, app_path=app_path,)) sh.git.add(ebuild_name) sh.ebuild(ebuild_name, 'manifest') sh.git.add('*') os.system("git commit -m 'newapp {}'".format(app_name)) os.system("git push") os.system("sudo emaint sync -A") accept_keyword = "={}/{}-9999 **\n".format(group, app_name) accept_keywords = Path("/etc/portage/package.accept_keywords") / Path(group) / Path(app_name) accept_keywords.parent.mkdir(exist_ok=True) write_line_to_file(path=accept_keywords, line=accept_keyword, unique=True, make_new_if_necessary=True, verbose=verbose, ) sh.ln('-s', ebuild_path / ebuild_name, app_path / ebuild_name) sh.git.diff('--exit-code') # need to commit any pending ebuild changes here, but that's the wront git message, and it fails if it's unhanged sh.git.commit('-m', 'initial commit', _ok_code=[0, 1]) else: eprint('Not creating new ebuild, {} already exists.'.format(ebuild_path)) ic(app_path) ic(app_module_name) main_py_path = app_path / Path(app_module_name) / Path(app_module_name + ext) ic(main_py_path) os.system("edittool edit " + main_py_path.as_posix())
def rename(ctx, old_repo_url, new_repo_url, group, apps_folder, gentoo_overlay_repo, github_user, local, verbose: int, verbose_inf: bool, hg: bool, ): not_root() tty, verbose = tv(ctx=ctx, verbose=verbose, verbose_inf=verbose_inf, ) apps_folder = Path(apps_folder) ic(apps_folder) old_app_name, old_app_user, old_app_module_name, old_app_path = \ parse_url(old_repo_url, apps_folder=apps_folder, keep_underscore=True, verbose=verbose, ) new_app_name, new_app_user, new_app_module_name, new_app_path = \ parse_url(new_repo_url, apps_folder=apps_folder, verbose=verbose, ) assert old_app_user == new_app_user ic(old_app_name, new_app_name) ic(old_app_path, new_app_path) assert group in portage_categories() with chdir(old_app_path): old_setup_py = old_app_path / Path('setup.py') replace_match_pairs_in_file(path=old_setup_py, match_pairs=((old_app_name, new_app_name), (old_app_module_name, new_app_module_name),), verbose=verbose, ) sh.git.add(old_setup_py) del old_setup_py old_readme_md = old_app_path / Path('README.md') try: replace_match_pairs_in_file(path=old_readme_md, match_pairs=((old_app_name, new_app_name), (old_app_module_name, new_app_module_name),), verbose=verbose, ) except FileNotFoundError as e: ic(e) sh.touch('README.md') sh.git.add(old_readme_md) del old_readme_md old_url_sh = old_app_path / Path('url.sh') try: replace_text(path=old_url_sh, match=old_app_name, replacement=new_app_name, verbose=verbose, ) except Exception as e: write_url_sh(new_repo_url, verbose=verbose,) sh.git.add(old_url_sh) del old_url_sh old_edit_config = old_app_path / Path('.edit_config') replace_text(path=old_edit_config, match=old_app_name, replacement=new_app_name, verbose=verbose, ) #sh.git.add(old_edit_config) del old_edit_config enable_github_sh = old_app_path / Path('enable_github.sh') replace_text(path=enable_github_sh, match=old_app_name, replacement=new_app_name, verbose=verbose, ) #sh.git.add(enable_github_sh) del enable_github_sh old_app_py = old_app_path / old_app_module_name / Path(old_app_module_name + '.py') replace_match_pairs_in_file(path=old_app_py, match_pairs=((old_app_name, new_app_name), (old_app_module_name, new_app_module_name),), verbose=verbose, ) sh.git.add(old_app_py) #del old_app_py old_app_init_py = old_app_path / old_app_module_name / Path('__init__.py') replace_text(path=old_app_init_py, match=old_app_module_name, replacement=new_app_module_name, verbose=verbose, ) sh.git.add(old_app_init_py) del old_app_init_py # in old_app_path new_app_py = old_app_path / old_app_module_name / Path(new_app_module_name + '.py') if new_app_py.as_posix() != old_app_py.as_posix(): sh.git.mv(old_app_py, new_app_py) del old_app_py del new_app_py if new_app_module_name != old_app_module_name: sh.git.mv(old_app_module_name, new_app_module_name) #print(sh.ls()) sh.git.add(Path(new_app_module_name) / Path('__init__.py')) sh.git.add(Path(new_app_module_name) / Path('py.typed')) sh.git.add(Path(new_app_module_name) / Path(new_app_module_name + '.py')) old_ebuild_symlink = old_app_path / Path(old_app_name + '-9999.ebuild') if not old_ebuild_symlink.exists(): old_ebuild_folder = Path(gentoo_overlay_repo) / Path(group) / Path(old_app_name) sh.ln('-s', old_ebuild_folder / old_ebuild_symlink.name, old_ebuild_symlink.name, _ok_code=[0, 1]) del old_ebuild_folder old_ebuild_dir = old_ebuild_symlink.resolve().parent if old_ebuild_symlink.exists(): with chdir(old_ebuild_dir): # in ebuild folder old_ebuild_path = Path(old_app_name + '-9999.ebuild').resolve() replace_text(path=old_ebuild_path, match=old_app_module_name, replacement=new_app_module_name, verbose=verbose, ) sh.git.add(old_ebuild_path) new_ebuild_name = Path(new_app_name + '-9999.ebuild') sh.git.mv('-v', old_ebuild_path, new_ebuild_name, _out=sys.stdout, _err=sys.stderr,) sh.git.add(new_ebuild_name) sh.git.commit('-m', 'rename') del old_ebuild_path with chdir(old_ebuild_dir.parent): # in ebuild parent folder sh.busybox.mv('-v', old_app_name, new_app_name, _out=sys.stdout, _err=sys.stderr,) new_ebuild_path = Path(new_app_name / new_ebuild_name).resolve() sh.git.commit('-m', 'rename', _ok_code=[0, 1], _out=sys.stdout, _err=sys.stderr,) sh.git.push() with chdir(old_app_path): print(sh.ls()) sh.rm(old_ebuild_symlink.name) del old_ebuild_symlink new_ebuild_symlink_name = new_ebuild_name sh.ln('-s', new_ebuild_path, new_ebuild_symlink_name) del new_ebuild_symlink_name del new_ebuild_name sh.git.commit('-m', 'rename') sh.git.remote.rm('origin', _ok_code=[0, 2]) sh.git.push(_ok_code=[0, 128]) with chdir(apps_folder): sh.busybox.mv('-v', old_app_path, new_app_path, _out=sys.stdout, _err=sys.stderr,) replace_text(path=Path('/etc/portage/package.accept_keywords'), match='/' + old_app_module_name + '-', replacement='/' + new_app_module_name + '-', verbose=verbose, )