From deffdebf6f0f7b0ee39a0800493ad12f39d8985e Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Thu, 27 May 2021 09:30:09 +0200 Subject: [PATCH] add cerifi bundle by default if SLL_CERT_FILE is not set --- start.py | 89 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/start.py b/start.py index 660d0c9006..5eaac03a68 100644 --- a/start.py +++ b/start.py @@ -101,6 +101,28 @@ import site from pathlib import Path import platform +import blessed + + +term = blessed.Terminal() + + +def _print(message: str): + if message.startswith("!!! "): + print("{}{}".format(term.orangered2("!!! "), message[4:])) + if message.startswith(">>> "): + print("{}{}".format(term.aquamarine3(">>> "), message[4:])) + if message.startswith("--- "): + print("{}{}".format(term.darkolivegreen3("--- "), message[4:])) + if message.startswith(" "): + print("{}{}".format(term.darkseagreen3(" "), message[4:])) + if message.startswith("*** "): + print("{}{}".format(term.gold("*** "), message[4:])) + if message.startswith(" - "): + print("{}{}".format(term.wheat(" - "), message[4:])) + if message.startswith(" . "): + print("{}{}".format(term.tan(" . "), message[4:])) + # OPENPYPE_ROOT is variable pointing to build (or code) directory # WARNING `OPENPYPE_ROOT` must be defined before igniter import @@ -112,13 +134,8 @@ if not getattr(sys, 'frozen', False): else: OPENPYPE_ROOT = os.path.dirname(sys.executable) - # FIX #1469: Certificates from certifi are not available in some - # macos builds, so connection to ftrack/mongo will fail with - # unable to verify certificate issuer error. This will add certifi - # certificates so ssl can see them. - # WARNING: this can break stuff if custom certificates are used. In that - # case they need to be merged to certificate bundle and SSL_CERT_FILE - # should point to them. + if os.getenv("SSL_CERT_FILE"): + _print("--- your system is set to use custom CA certificate bundle.") if not os.getenv("SSL_CERT_FILE") and platform.system().lower() == "darwin": # noqa: E501 ssl_cert_file = Path(OPENPYPE_ROOT) / "dependencies" / "certifi" / "cacert.pem" # noqa: E501 os.environ["SSL_CERT_FILE"] = ssl_cert_file.as_posix() @@ -197,7 +214,7 @@ def run(arguments: list, env: dict = None) -> int: p = subprocess.Popen(interpreter, env=env) p.wait() - print(f">>> done [{p.returncode}]") + _print(f">>> done [{p.returncode}]") return p.returncode @@ -278,8 +295,8 @@ def _process_arguments() -> tuple: use_staging = False for arg in sys.argv: if arg == "--use-version": - print("!!! Please use option --use-version like:") - print(" --use-version=3.0.0") + _print("!!! Please use option --use-version like:") + _print(" --use-version=3.0.0") sys.exit(1) m = re.search(r"--use-version=(?P\d+\.\d+\.\d*.+?)", arg) @@ -336,12 +353,12 @@ def _determine_mongodb() -> str: if openpype_mongo: result, msg = validate_mongo_connection(openpype_mongo) if not result: - print(msg) + _print(msg) openpype_mongo = None if not openpype_mongo: - print("*** No DB connection string specified.") - print("--- launching setup UI ...") + _print("*** No DB connection string specified.") + _print("--- launching setup UI ...") result = igniter.open_dialog() if result == 0: @@ -366,7 +383,7 @@ def _initialize_environment(openpype_version: OpenPypeVersion) -> None: version_path.as_posix() ) # inject version to Python environment (sys.path, ...) - print(">>> Injecting OpenPype version to running environment ...") + _print(">>> Injecting OpenPype version to running environment ...") bootstrap.add_paths_from_directory(version_path) # Additional sys paths related to OPENPYPE_REPOS_ROOT directory @@ -435,7 +452,7 @@ def _find_frozen_openpype(use_version: str = None, openpype_versions = [] else: - print("!!! Warning: cannot determine current running version.") + _print("!!! Warning: cannot determine current running version.") if not os.getenv("OPENPYPE_TRYOUT"): try: @@ -443,8 +460,8 @@ def _find_frozen_openpype(use_version: str = None, openpype_version = openpype_versions[-1] except IndexError: # no OpenPype version found, run Igniter and ask for them. - print('*** No OpenPype versions found.') - print("--- launching setup UI ...") + _print('*** No OpenPype versions found.') + _print("--- launching setup UI ...") import igniter return_code = igniter.open_dialog() if return_code == 2: @@ -452,25 +469,25 @@ def _find_frozen_openpype(use_version: str = None, if return_code == 3: # run OpenPype after installation - print('>>> Finding OpenPype again ...') + _print('>>> Finding OpenPype again ...') openpype_versions = bootstrap.find_openpype( staging=use_staging) try: openpype_version = openpype_versions[-1] except IndexError: - print(("!!! Something is wrong and we didn't " + _print(("!!! Something is wrong and we didn't " "found it again.")) sys.exit(1) elif return_code != 2: - print(f" . finished ({return_code})") + _print(f" . finished ({return_code})") sys.exit(return_code) if not openpype_versions: # no openpype versions found anyway, lets use then the one # shipped with frozen OpenPype if not os.getenv("OPENPYPE_TRYOUT"): - print("*** Still no luck finding OpenPype.") - print(("*** We'll try to use the one coming " + _print("*** Still no luck finding OpenPype.") + _print(("*** We'll try to use the one coming " "with OpenPype installation.")) version_path = _bootstrap_from_code(use_version) openpype_version = OpenPypeVersion( @@ -485,12 +502,12 @@ def _find_frozen_openpype(use_version: str = None, if not version_path: if use_version is not None and openpype_version: - print(("!!! Specified version was not found, using " + _print(("!!! Specified version was not found, using " "latest available")) # specified version was not found so use latest detected. version_path = openpype_version.path - print(f">>> Using version [ {openpype_version} ]") - print(f" From {version_path}") + _print(f">>> Using version [ {openpype_version} ]") + _print(f" From {version_path}") # test if latest detected is installed (in user data dir) is_inside = False @@ -508,11 +525,11 @@ def _find_frozen_openpype(use_version: str = None, openpype_version, force=True) if openpype_version.path.is_file(): - print(">>> Extracting zip file ...") + _print(">>> Extracting zip file ...") try: version_path = bootstrap.extract_openpype(openpype_version) except OSError as e: - print("!!! failed: {}".format(str(e))) + _print("!!! failed: {}".format(str(e))) sys.exit(1) else: # cleanup zip after extraction @@ -538,7 +555,7 @@ def _bootstrap_from_code(use_version): # set root if getattr(sys, 'frozen', False): local_version = bootstrap.get_version(Path(OPENPYPE_ROOT)) - print(f" - running version: {local_version}") + _print(f" - running version: {local_version}") assert local_version else: # get current version of OpenPype @@ -632,7 +649,7 @@ def boot(): openpype_mongo = _determine_mongodb() except RuntimeError as e: # without mongodb url we are done for. - print(f"!!! {e}") + _print(f"!!! {e}") sys.exit(1) os.environ["OPENPYPE_MONGO"] = openpype_mongo @@ -642,7 +659,7 @@ def boot(): # find its versions there and bootstrap them. openpype_path = get_openpype_path_from_db(openpype_mongo) if not openpype_path: - print("*** Cannot get OpenPype path from database.") + _print("*** Cannot get OpenPype path from database.") if not os.getenv("OPENPYPE_PATH") and openpype_path: os.environ["OPENPYPE_PATH"] = openpype_path @@ -658,7 +675,7 @@ def boot(): version_path = _find_frozen_openpype(use_version, use_staging) except RuntimeError as e: # no version to run - print(f"!!! {e}") + _print(f"!!! {e}") sys.exit(1) else: version_path = _bootstrap_from_code(use_version) @@ -683,13 +700,13 @@ def boot(): except KeyError: pass - print(">>> loading environments ...") + _print(">>> loading environments ...") # Avalon environments must be set before avalon module is imported - print(" - for Avalon ...") + _print(" - for Avalon ...") set_avalon_environments() - print(" - global OpenPype ...") + _print(" - global OpenPype ...") set_openpype_global_environments() - print(" - for modules ...") + _print(" - for modules ...") set_modules_environments() from openpype import cli @@ -719,7 +736,7 @@ def boot(): cli.main(obj={}, prog_name="openpype") except Exception: # noqa exc_info = sys.exc_info() - print("!!! OpenPype crashed:") + _print("!!! OpenPype crashed:") traceback.print_exception(*exc_info) sys.exit(1)