mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
work on handling environment
This commit is contained in:
parent
dcc073ff85
commit
5cda507ed1
1 changed files with 78 additions and 1 deletions
79
pype.py
79
pype.py
|
|
@ -21,6 +21,7 @@ import sys
|
|||
import os
|
||||
import re
|
||||
import traceback
|
||||
import platform
|
||||
|
||||
|
||||
# find Pype installation.
|
||||
|
|
@ -50,17 +51,21 @@ def boot():
|
|||
if use_version in pype_versions.keys():
|
||||
# use specified
|
||||
bootstrap.add_paths_from_archive(pype_versions[use_version])
|
||||
os.environ["PYPE_ROOT"] = pype_versions[use_version]
|
||||
else:
|
||||
if use_version is not None:
|
||||
print(("!!! Specified version was not found, using "
|
||||
"latest available"))
|
||||
# use latest
|
||||
bootstrap.add_paths_from_archive(list(pype_versions.values())[-1])
|
||||
os.environ["PYPE_ROOT"] = list(pype_versions.values())[-1]
|
||||
use_version = list(pype_versions.keys())[-1]
|
||||
else:
|
||||
# run throught repos and add them to sys.path and PYTHONPATH
|
||||
pype_root = os.path.dirname(sys.executable)
|
||||
pype_root = os.path.dirname(os.path.realpath(__file__))
|
||||
os.environ["PYPE_ROOT"] = pype_root
|
||||
repos = os.listdir(os.path.join(pype_root, "repos"))
|
||||
repos = [os.path.join(pype_root, "repos", repo) for repo in repos]
|
||||
for repo in repos:
|
||||
sys.path.append(repo)
|
||||
|
||||
|
|
@ -94,6 +99,10 @@ def boot():
|
|||
print(art)
|
||||
t.echo(f"*** Pype [{__version__}] --------------------------------------")
|
||||
t.echo(">>> Using Pype from [ {} ]".format(os.path.dirname(cli.__file__)))
|
||||
t.echo(">>> Loading environments ...")
|
||||
load_environments()
|
||||
print_info()
|
||||
|
||||
try:
|
||||
cli.main(obj={}, prog_name="pype")
|
||||
except Exception:
|
||||
|
|
@ -103,4 +112,72 @@ def boot():
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def print_info() -> None:
|
||||
"""Print additional information to console."""
|
||||
from pype.lib import terminal as t
|
||||
from pype.lib.mongo import get_default_components
|
||||
from pype.lib.log import LOG_DATABASE_NAME, LOG_COLLECTION_NAME
|
||||
|
||||
components = get_default_components()
|
||||
|
||||
infos = []
|
||||
if os.getenv('PYPE_DEV'):
|
||||
infos.append(("Pype variant", "staging"))
|
||||
else:
|
||||
infos.append(("Pype variant", "production"))
|
||||
infos.append(("Running pype from", os.environ.get('PYPE_SETUP_PATH')))
|
||||
infos.append(("Using config at", os.environ.get('PYPE_CONFIG')))
|
||||
infos.append(("Using mongodb", components["host"]))
|
||||
|
||||
if os.environ.get("FTRACK_SERVER"):
|
||||
infos.append(("Using FTrack at",
|
||||
os.environ.get("FTRACK_SERVER")))
|
||||
|
||||
if os.environ.get('DEADLINE_REST_URL'):
|
||||
infos.append(("Using Deadline webservice at",
|
||||
os.environ.get("DEADLINE_REST_URL")))
|
||||
|
||||
if os.environ.get('MUSTER_REST_URL'):
|
||||
infos.append(("Using Muster at",
|
||||
os.environ.get("MUSTER_REST_URL")))
|
||||
|
||||
if components["host"]:
|
||||
infos.append(("Logging to MongoDB", components["host"]))
|
||||
infos.append((" - port", components["port"] or "<N/A>"))
|
||||
infos.append((" - database", LOG_DATABASE_NAME))
|
||||
infos.append((" - collection", LOG_COLLECTION_NAME))
|
||||
infos.append((" - user", components["username"] or "<N/A>"))
|
||||
if components["auth_db"]:
|
||||
infos.append((" - auth source", components["auth_db"]))
|
||||
|
||||
maximum = max([len(i[0]) for i in infos])
|
||||
for info in infos:
|
||||
padding = (maximum - len(info[0])) + 1
|
||||
t.echo("... {}:{}[ {} ]".format(info[0], " " * padding, info[1]))
|
||||
print('\n')
|
||||
|
||||
|
||||
def load_environments() -> None:
|
||||
import acre
|
||||
os.environ['PLATFORM'] = platform.system().lower()
|
||||
# FIXME (antirotor): Acre cannot read stuff from zip files.
|
||||
os.environ["TOOL_ENV"] = os.path.join(
|
||||
os.environ["PYPE_ROOT"],
|
||||
"pype-config",
|
||||
"environments"
|
||||
)
|
||||
tools_env = acre.get_tools(
|
||||
["global", "avalon", "ftrack", "deadline", "clockify"])
|
||||
pype_paths_env = dict()
|
||||
for key, value in dict(os.environ).items():
|
||||
if key.startswith('PYPE_'):
|
||||
pype_paths_env[key] = value
|
||||
|
||||
env = tools_env
|
||||
env.update(pype_paths_env)
|
||||
env = acre.compute(env, cleanup=True)
|
||||
env = acre.merge(env, os.environ)
|
||||
os.environ = env
|
||||
|
||||
|
||||
boot()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue