mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #2607 from BigRoy/optimize_startup
Global: Optimize OpenPype startup
This commit is contained in:
commit
aadf253a13
4 changed files with 59 additions and 56 deletions
|
|
@ -23,7 +23,8 @@ from .user_settings import (
|
|||
OpenPypeSettingsRegistry
|
||||
)
|
||||
from .tools import (
|
||||
get_openpype_path_from_db,
|
||||
get_openpype_global_settings,
|
||||
get_openpype_path_from_settings,
|
||||
get_expected_studio_version_str
|
||||
)
|
||||
|
||||
|
|
@ -973,9 +974,19 @@ class BootstrapRepos:
|
|||
for line in checksums_data.split("\n") if line
|
||||
]
|
||||
|
||||
# get list of files in zip minus `checksums` file itself
|
||||
# and turn in to set to compare against list of files
|
||||
# from checksum file. If difference exists, something is
|
||||
# wrong
|
||||
files_in_zip = set(zip_file.namelist())
|
||||
files_in_zip.remove("checksums")
|
||||
files_in_checksum = {file[1] for file in checksums}
|
||||
diff = files_in_zip.difference(files_in_checksum)
|
||||
if diff:
|
||||
return False, f"Missing files {diff}"
|
||||
|
||||
# calculate and compare checksums in the zip file
|
||||
for file in checksums:
|
||||
file_name = file[1]
|
||||
for file_checksum, file_name in checksums:
|
||||
if platform.system().lower() == "windows":
|
||||
file_name = file_name.replace("/", "\\")
|
||||
h = hashlib.sha256()
|
||||
|
|
@ -983,21 +994,9 @@ class BootstrapRepos:
|
|||
h.update(zip_file.read(file_name))
|
||||
except FileNotFoundError:
|
||||
return False, f"Missing file [ {file_name} ]"
|
||||
if h.hexdigest() != file[0]:
|
||||
if h.hexdigest() != file_checksum:
|
||||
return False, f"Invalid checksum on {file_name}"
|
||||
|
||||
# get list of files in zip minus `checksums` file itself
|
||||
# and turn in to set to compare against list of files
|
||||
# from checksum file. If difference exists, something is
|
||||
# wrong
|
||||
files_in_zip = zip_file.namelist()
|
||||
files_in_zip.remove("checksums")
|
||||
files_in_zip = set(files_in_zip)
|
||||
files_in_checksum = {file[1] for file in checksums}
|
||||
diff = files_in_zip.difference(files_in_checksum)
|
||||
if diff:
|
||||
return False, f"Missing files {diff}"
|
||||
|
||||
return True, "All ok"
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -1011,16 +1010,22 @@ class BootstrapRepos:
|
|||
tuple(line.split(":"))
|
||||
for line in checksums_data.split("\n") if line
|
||||
]
|
||||
files_in_dir = [
|
||||
|
||||
# compare file list against list of files from checksum file.
|
||||
# If difference exists, something is wrong and we invalidate directly
|
||||
files_in_dir = set(
|
||||
file.relative_to(path).as_posix()
|
||||
for file in path.iterdir() if file.is_file()
|
||||
]
|
||||
)
|
||||
files_in_dir.remove("checksums")
|
||||
files_in_dir = set(files_in_dir)
|
||||
files_in_checksum = {file[1] for file in checksums}
|
||||
|
||||
for file in checksums:
|
||||
file_name = file[1]
|
||||
diff = files_in_dir.difference(files_in_checksum)
|
||||
if diff:
|
||||
return False, f"Missing files {diff}"
|
||||
|
||||
# calculate and compare checksums
|
||||
for file_checksum, file_name in checksums:
|
||||
if platform.system().lower() == "windows":
|
||||
file_name = file_name.replace("/", "\\")
|
||||
try:
|
||||
|
|
@ -1028,11 +1033,8 @@ class BootstrapRepos:
|
|||
except FileNotFoundError:
|
||||
return False, f"Missing file [ {file_name} ]"
|
||||
|
||||
if file[0] != current:
|
||||
if file_checksum != current:
|
||||
return False, f"Invalid checksum on {file_name}"
|
||||
diff = files_in_dir.difference(files_in_checksum)
|
||||
if diff:
|
||||
return False, f"Missing files {diff}"
|
||||
|
||||
return True, "All ok"
|
||||
|
||||
|
|
@ -1262,7 +1264,8 @@ class BootstrapRepos:
|
|||
openpype_path = None
|
||||
# try to get OpenPype path from mongo.
|
||||
if location.startswith("mongodb"):
|
||||
openpype_path = get_openpype_path_from_db(location)
|
||||
global_settings = get_openpype_global_settings(location)
|
||||
openpype_path = get_openpype_path_from_settings(global_settings)
|
||||
if not openpype_path:
|
||||
self._print("cannot find OPENPYPE_PATH in settings.")
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ from Qt.QtCore import QTimer # noqa
|
|||
from .install_thread import InstallThread
|
||||
from .tools import (
|
||||
validate_mongo_connection,
|
||||
get_openpype_path_from_db,
|
||||
get_openpype_icon_path
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -161,18 +161,17 @@ def get_openpype_global_settings(url: str) -> dict:
|
|||
return global_settings.get("data") or {}
|
||||
|
||||
|
||||
def get_openpype_path_from_db(url: str) -> Union[str, None]:
|
||||
def get_openpype_path_from_settings(settings: dict) -> Union[str, None]:
|
||||
"""Get OpenPype path from global settings.
|
||||
|
||||
Args:
|
||||
url (str): mongodb url.
|
||||
settings (dict): mongodb url.
|
||||
|
||||
Returns:
|
||||
path to OpenPype or None if not found
|
||||
"""
|
||||
global_settings = get_openpype_global_settings(url)
|
||||
paths = (
|
||||
global_settings
|
||||
settings
|
||||
.get("openpype_path", {})
|
||||
.get(platform.system().lower())
|
||||
) or []
|
||||
|
|
|
|||
52
start.py
52
start.py
|
|
@ -86,7 +86,7 @@ Todo:
|
|||
Move or remove bootstrapping environments out of the code.
|
||||
|
||||
Attributes:
|
||||
silent_commands (list): list of commands for which we won't print OpenPype
|
||||
silent_commands (set): list of commands for which we won't print OpenPype
|
||||
logo and info header.
|
||||
|
||||
.. _MongoDB:
|
||||
|
|
@ -195,15 +195,15 @@ import igniter # noqa: E402
|
|||
from igniter import BootstrapRepos # noqa: E402
|
||||
from igniter.tools import (
|
||||
get_openpype_global_settings,
|
||||
get_openpype_path_from_db,
|
||||
get_openpype_path_from_settings,
|
||||
validate_mongo_connection,
|
||||
OpenPypeVersionNotFound
|
||||
) # noqa
|
||||
from igniter.bootstrap_repos import OpenPypeVersion # noqa: E402
|
||||
|
||||
bootstrap = BootstrapRepos()
|
||||
silent_commands = ["run", "igniter", "standalonepublisher",
|
||||
"extractenvironments"]
|
||||
silent_commands = {"run", "igniter", "standalonepublisher",
|
||||
"extractenvironments"}
|
||||
|
||||
|
||||
def list_versions(openpype_versions: list, local_version=None) -> None:
|
||||
|
|
@ -281,12 +281,11 @@ def run(arguments: list, env: dict = None) -> int:
|
|||
return p.returncode
|
||||
|
||||
|
||||
def run_disk_mapping_commands(mongo_url):
|
||||
def run_disk_mapping_commands(settings):
|
||||
""" Run disk mapping command
|
||||
|
||||
Used to map shared disk for OP to pull codebase.
|
||||
"""
|
||||
settings = get_openpype_global_settings(mongo_url)
|
||||
|
||||
low_platform = platform.system().lower()
|
||||
disk_mapping = settings.get("disk_mapping")
|
||||
|
|
@ -923,12 +922,14 @@ def boot():
|
|||
os.environ["OPENPYPE_DATABASE_NAME"] = \
|
||||
os.environ.get("OPENPYPE_DATABASE_NAME") or "openpype"
|
||||
|
||||
global_settings = get_openpype_global_settings(openpype_mongo)
|
||||
|
||||
_print(">>> run disk mapping command ...")
|
||||
run_disk_mapping_commands(openpype_mongo)
|
||||
run_disk_mapping_commands(global_settings)
|
||||
|
||||
# Get openpype path from database and set it to environment so openpype can
|
||||
# find its versions there and bootstrap them.
|
||||
openpype_path = get_openpype_path_from_db(openpype_mongo)
|
||||
openpype_path = get_openpype_path_from_settings(global_settings)
|
||||
|
||||
if getattr(sys, 'frozen', False):
|
||||
local_version = bootstrap.get_version(Path(OPENPYPE_ROOT))
|
||||
|
|
@ -1057,29 +1058,30 @@ def boot():
|
|||
_print(" - for modules ...")
|
||||
set_modules_environments()
|
||||
|
||||
from openpype import cli
|
||||
from openpype.lib import terminal as t
|
||||
from openpype.version import __version__
|
||||
|
||||
assert version_path, "Version path not defined."
|
||||
info = get_info(use_staging)
|
||||
info.insert(0, f">>> Using OpenPype from [ {version_path} ]")
|
||||
|
||||
t_width = 20
|
||||
try:
|
||||
t_width = os.get_terminal_size().columns - 2
|
||||
except (ValueError, OSError):
|
||||
# running without terminal
|
||||
pass
|
||||
# print info when not running scripts defined in 'silent commands'
|
||||
if all(arg not in silent_commands for arg in sys.argv):
|
||||
from openpype.lib import terminal as t
|
||||
from openpype.version import __version__
|
||||
|
||||
_header = f"*** OpenPype [{__version__}] "
|
||||
info = get_info(use_staging)
|
||||
info.insert(0, f">>> Using OpenPype from [ {version_path} ]")
|
||||
|
||||
info.insert(0, _header + "-" * (t_width - len(_header)))
|
||||
for i in info:
|
||||
# don't show for running scripts
|
||||
if all(item not in sys.argv for item in silent_commands):
|
||||
t_width = 20
|
||||
try:
|
||||
t_width = os.get_terminal_size().columns - 2
|
||||
except (ValueError, OSError):
|
||||
# running without terminal
|
||||
pass
|
||||
|
||||
_header = f"*** OpenPype [{__version__}] "
|
||||
info.insert(0, _header + "-" * (t_width - len(_header)))
|
||||
|
||||
for i in info:
|
||||
t.echo(i)
|
||||
|
||||
from openpype import cli
|
||||
try:
|
||||
cli.main(obj={}, prog_name="openpype")
|
||||
except Exception: # noqa
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue