Added running configurable disk mapping command before start of OP

This commit is contained in:
Petr Kalis 2021-09-29 18:50:50 +02:00
parent 2921bc6c46
commit a6e334c16d
4 changed files with 108 additions and 1 deletions

View file

@ -7,6 +7,11 @@
"global": []
}
},
"disk_mapping": {
"windows": [],
"linux": [],
"darwin": []
},
"openpype_path": {
"windows": [],
"darwin": [],

View file

@ -40,6 +40,74 @@
{
"type": "splitter"
},
{
"type": "dict",
"key": "disk_mapping",
"label": "Disk mapping",
"collapsible": false,
"children": [
{
"key": "windows",
"label": "Windows",
"type": "list",
"object_type": {
"type": "list-strict",
"key": "item",
"object_types": [
{
"label": "Source",
"type": "path"
},
{
"label": "Destination",
"type": "path"
}
]
}
},
{
"key": "linux",
"label": "Linux",
"type": "list",
"object_type": {
"type": "list-strict",
"key": "item",
"object_types": [
{
"label": "Source",
"type": "path"
},
{
"label": "Destination",
"type": "path"
}
]
}
},
{
"key": "darwin",
"label": "MacOS",
"type": "list",
"object_type": {
"type": "list-strict",
"key": "item",
"object_types": [
{
"label": "Source",
"type": "path"
},
{
"label": "Destination",
"type": "path"
}
]
}
}
]
},
{
"type": "splitter"
},
{
"type": "path",
"key": "openpype_path",

View file

@ -168,7 +168,7 @@ class CacheValues:
class MongoSettingsHandler(SettingsHandler):
"""Settings handler that use mongo for storing and loading of settings."""
global_general_keys = ("openpype_path", "admin_password")
global_general_keys = ("openpype_path", "admin_password", "disk_mapping")
def __init__(self):
# Get mongo connection

View file

@ -102,6 +102,8 @@ import subprocess
import site
from pathlib import Path
from igniter.tools import get_openpype_global_settings
# OPENPYPE_ROOT is variable pointing to build (or code) directory
# WARNING `OPENPYPE_ROOT` must be defined before igniter import
@ -275,6 +277,35 @@ def run(arguments: list, env: dict = None) -> int:
return p.returncode
def run_disk_mapping_commands(mongo_url):
""" 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")
if not disk_mapping:
return
for mapping in disk_mapping.get(low_platform):
source, destination = mapping
args = ["subst", destination.rstrip('/'), source.rstrip('/')]
_print("disk mapping args:: {}".format(args))
try:
output = subprocess.Popen(args)
if output.returncode != 0:
exc_msg = "Executing arguments was not successful: \"{}\"".format(
args)
raise RuntimeError(exc_msg)
except TypeError:
_print("Error in mapping drive")
raise
def set_avalon_environments():
"""Set avalon specific environments.
@ -886,6 +917,9 @@ def boot():
os.environ["OPENPYPE_MONGO"] = openpype_mongo
os.environ["OPENPYPE_DATABASE_NAME"] = "openpype" # name of Pype database
_print(">>> run disk mapping command ...")
run_disk_mapping_commands(openpype_mongo)
# 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)