From ca7db287a69711f2adbd4159d6b81f7fbd458ce9 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 9 Feb 2025 16:29:04 -0500 Subject: [PATCH] cleanup extension installer Signed-off-by: Vladimir Mandic --- installer.py | 12 +++++++++++- modules/ui_extensions.py | 37 ++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/installer.py b/installer.py index fa651c872..e96a398a7 100644 --- a/installer.py +++ b/installer.py @@ -308,6 +308,16 @@ def uninstall(package, quiet = False): return res +def run(cmd: str, arg: str): + result = subprocess.run(f'"{cmd}" {arg}', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + txt = result.stdout.decode(encoding="utf8", errors="ignore") + if len(result.stderr) > 0: + txt += ('\n' if len(txt) > 0 else '') + result.stderr.decode(encoding="utf8", errors="ignore") + txt = txt.strip() + debug(f'Exec {cmd}: {txt}') + return txt + + @lru_cache() def pip(arg: str, ignore: bool = False, quiet: bool = True, uv = True): t_start = time.time() @@ -363,7 +373,7 @@ def install(package, friendly: str = None, ignore: bool = False, reinstall: bool # execute git command @lru_cache() -def git(arg: str, folder: str = None, ignore: bool = False, optional: bool = False): +def git(arg: str, folder: str = None, ignore: bool = False, optional: bool = False): # pylint: disable=unused-argument t_start = time.time() if args.skip_git: return '' diff --git a/modules/ui_extensions.py b/modules/ui_extensions.py index 8a97181ee..6df6de576 100644 --- a/modules/ui_extensions.py +++ b/modules/ui_extensions.py @@ -158,16 +158,26 @@ def install_extension_from_url(dirname, url, branch_name, search_text, sort_colu try: import git shutil.rmtree(tmpdir, True) - if not branch_name: # if no branch is specified, use the default branch - with git.Repo.clone_from(url, tmpdir, filter=['blob:none']) as repo: - repo.remote().fetch() - for submodule in repo.submodules: - submodule.update() - else: - with git.Repo.clone_from(url, tmpdir, filter=['blob:none'], branch=branch_name) as repo: - repo.remote().fetch() - for submodule in repo.submodules: - submodule.update() + args = { + 'url': url, + 'to_path': tmpdir, + 'allow_unsafe_protocols': True, + 'allow_unsafe_options': True, + 'filter': ['blob:none'], + } + if branch_name: + args['branch'] = branch_name + ssh = os.environ.get('GIT_SSH_COMMAND', None) + if ssh: + args['env'] = {'GIT_SSH_COMMAND':ssh} + shared.log.debug(f'GIT: {args}') + # from installer import run + # ssh_test = run('ssh', '-v -c chacha20-poly1305@openssh.com -T git@github.com') + # shared.log.debug('GIT SSH TEST', ssh_test) + with git.Repo.clone_from(**args) as repo: + repo.remote().fetch(verbose=True) + for submodule in repo.submodules: + submodule.update() try: os.rename(tmpdir, target_dir) except OSError as err: @@ -177,13 +187,14 @@ def install_extension_from_url(dirname, url, branch_name, search_text, sort_colu raise err from launch import run_extension_installer run_extension_installer(target_dir) + shutil.rmtree(tmpdir, True) extensions.list_extensions() return [create_html(search_text, sort_column), html.escape(f"Extension installed: {target_dir} | Restart required")] except Exception as e: - shared.log.error(f'Error installing extension: {url} {e}') - finally: + # errors.display(e, 'GIT') shutil.rmtree(tmpdir, True) - return [] + shared.log.error(f'Error installing extension: {url} {e}') + return ['', str(e).replace('\n', '
')] def install_extension(extension_to_install, search_text, sort_column):