mirror of
https://github.com/vladmandic/automatic
synced 2026-09-10 23:08:43 +02:00
cleanup extension installer
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
+11
-1
@@ -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 ''
|
||||
|
||||
+24
-13
@@ -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', '<br>')]
|
||||
|
||||
|
||||
def install_extension(extension_to_install, search_text, sort_column):
|
||||
|
||||
Reference in New Issue
Block a user