From ee43e3af3426dc46076bdaae6db74269fe0cb974 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Mon, 3 May 2021 12:48:14 +0200 Subject: [PATCH] generate zip doesn't need to run openpype --- igniter/bootstrap_repos.py | 10 +++++- openpype/cli.py | 11 ------- openpype/pype_commands.py | 23 ------------- tools/create_zip.ps1 | 37 ++++++--------------- tools/create_zip.py | 66 ++++++++++++++++++++++++++++++++++++++ tools/create_zip.sh | 4 ++- 6 files changed, 87 insertions(+), 64 deletions(-) create mode 100644 tools/create_zip.py diff --git a/igniter/bootstrap_repos.py b/igniter/bootstrap_repos.py index f4bb4d57d3..8fbb580e8f 100644 --- a/igniter/bootstrap_repos.py +++ b/igniter/bootstrap_repos.py @@ -473,7 +473,15 @@ class BootstrapRepos: """ # get filtered list of file in Pype repository - openpype_list = self._filter_dir(openpype_path, self.zip_filter) + # openpype_list = self._filter_dir(openpype_path, self.zip_filter) + openpype_list = [] + for f in self.openpype_filter: + if (openpype_path / f).is_dir(): + openpype_list += self._filter_dir( + openpype_path / f, self.zip_filter) + else: + openpype_list.append(openpype_path / f) + openpype_files = len(openpype_list) openpype_inc = 98.0 / float(openpype_files) diff --git a/openpype/cli.py b/openpype/cli.py index c6da88cbc1..9c49825721 100644 --- a/openpype/cli.py +++ b/openpype/cli.py @@ -224,17 +224,6 @@ def launch(app, project, asset, task, PypeCommands().run_application(app, project, asset, task, tools, arguments) -@main.command() -@click.option("-p", "--path", help="Path to zip file", default=None) -def generate_zip(path): - """Generate Pype zip from current sources. - - If PATH is not provided, it will create zip file in user data dir. - - """ - PypeCommands().generate_zip(path) - - @main.command( context_settings=dict( ignore_unknown_options=True, diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index a2d97429d3..981cca82dc 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -119,26 +119,3 @@ class PypeCommands: def validate_jsons(self): pass - @staticmethod - def generate_zip(out_path: str): - """Generate zip file from current sources. - - Args: - out_path (str): Path to generated zip file. - - """ - from igniter import bootstrap_repos - - # create zip file - bs = bootstrap_repos.BootstrapRepos() - if out_path: - out_path = Path(out_path) - bs.data_dir = out_path.parent - - print(f">>> Creating zip in {bs.data_dir} ...") - repo_file = bs.create_version_from_live_code() - if not repo_file: - print("!!! Error while creating zip file.") - exit(1) - - print(f">>> Created {repo_file}") diff --git a/tools/create_zip.ps1 b/tools/create_zip.ps1 index d18806c40b..05db640e5b 100644 --- a/tools/create_zip.ps1 +++ b/tools/create_zip.ps1 @@ -64,34 +64,15 @@ if (-not $openpype_version) { } Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Detecting host Python ... " -NoNewline -if (-not (Get-Command "python" -ErrorAction SilentlyContinue)) { - Write-Host "!!! Python not detected" -ForegroundColor red - Exit-WithCode 1 -} -$version_command = @' -import sys -print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1])) -'@ - -$p = & python -c $version_command -$env:PYTHON_VERSION = $p -$m = $p -match '(\d+)\.(\d+)' -if(-not $m) { - Write-Host "!!! Cannot determine version" -ForegroundColor red - Exit-WithCode 1 -} -# We are supporting python 3.6 and up -if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { - Write-Host "FAILED Version [ $p ] is old and unsupported" -ForegroundColor red - Exit-WithCode 1 -} -Write-Host "OK [ $p ]" -ForegroundColor green +Write-Host "Cleaning cache files ... " -NoNewline +Get-ChildItem $openpype_root -Filter "*.pyc" -Force -Recurse | Remove-Item -Force +Get-ChildItem $openpype_root -Filter "*.pyo" -Force -Recurse | Remove-Item -Force +Get-ChildItem $openpype_root -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse +Write-Host "OK" -ForegroundColor green Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Generating zip from current sources ..." -Write-Host "... " -NoNewline -ForegroundColor Magenta -Write-Host "arguments: " -NoNewline -ForegroundColor Gray -Write-Host $ARGS -ForegroundColor White -& poetry run python "$($openpype_root)\start.py" generate-zip $ARGS -Set-Location -Path $current_dir \ No newline at end of file +$env:PYTHONPATH="$($openpype_root);$($env:PYTHONPATH)" +$env:OPENPYPE_ROOT="$($openpype_root)" +& poetry run python "$($openpype_root)\tools\create_zip.py" $ARGS +Set-Location -Path $current_dir diff --git a/tools/create_zip.py b/tools/create_zip.py new file mode 100644 index 0000000000..32a4d27e8b --- /dev/null +++ b/tools/create_zip.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +"""Create OpenPype version from live sources.""" +from igniter import bootstrap_repos +import click +import enlighten +import blessed +from pathlib2 import Path + + +term = blessed.Terminal() +manager = enlighten.get_manager() +last_increment = 0 + + +@click.group(invoke_without_command=True) +@click.option("--path", required=False, + help="path where to put version", + type=click.Path(exists=True)) +def main(path): + # create zip file + + progress_bar = enlighten.Counter( + total=100, desc="OpenPype ZIP", units="%", color="green") + + def progress(inc: int): + """Progress handler.""" + global last_increment + progress_bar.update(incr=inc - last_increment) + last_increment = inc + + bs = bootstrap_repos.BootstrapRepos(progress_callback=progress) + if path: + out_path = Path(path) + bs.data_dir = out_path.parent + + _print(f"Creating zip in {bs.data_dir} ...") + repo_file = bs.create_version_from_live_code() + if not repo_file: + _print("Error while creating zip file.", 1) + exit(1) + + _print(f"Created {repo_file}") + + +def _print(msg: str, message_type: int = 0) -> None: + """Print message to console. + + Args: + msg (str): message to print + message_type (int): type of message (0 info, 1 error, 2 note) + + """ + if message_type == 0: + header = term.aquamarine3(">>> ") + elif message_type == 1: + header = term.orangered2("!!! ") + elif message_type == 2: + header = term.tan1("... ") + else: + header = term.darkolivegreen3("--- ") + + print("{}{}".format(header, msg)) + + +if __name__ == "__main__": + main() diff --git a/tools/create_zip.sh b/tools/create_zip.sh index 6e7f792f1d..f02eb9987c 100755 --- a/tools/create_zip.sh +++ b/tools/create_zip.sh @@ -123,7 +123,9 @@ main () { pushd "$openpype_root" > /dev/null || return > /dev/null echo -e "${BIGreen}>>>${RST} Generating zip from current sources ..." - poetry run python3 "$openpype_root/start.py" generate-zip "$@" + PYTHONPATH="$openpype_root:$PYTHONPATH" + OPENPYPE_ROOT="$openpype_root" + poetry run python3 "$openpype_root/tools/create_zip.py" "$@" } main "$@"