mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
remove modified_environ function
This commit is contained in:
parent
e86215b142
commit
1ad1cea494
4 changed files with 0 additions and 117 deletions
|
|
@ -43,7 +43,6 @@ from .lib import (
|
|||
get_subsets,
|
||||
get_version_from_path,
|
||||
get_last_version_from_path,
|
||||
modified_environ,
|
||||
add_tool_to_environment,
|
||||
source_hash,
|
||||
get_latest_version
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ from .lib_old import (
|
|||
get_ffmpeg_tool_path,
|
||||
get_hierarchy,
|
||||
add_tool_to_environment,
|
||||
modified_environ,
|
||||
is_latest,
|
||||
any_outdated,
|
||||
_rreplace,
|
||||
|
|
|
|||
|
|
@ -197,38 +197,6 @@ def add_tool_to_environment(tools):
|
|||
os.environ.update(env)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def modified_environ(*remove, **update):
|
||||
"""
|
||||
Temporarily updates the ``os.environ`` dictionary in-place.
|
||||
|
||||
The ``os.environ`` dictionary is updated in-place so that the modification
|
||||
is sure to work in all situations.
|
||||
|
||||
:param remove: Environment variables to remove.
|
||||
:param update: Dictionary of environment variables
|
||||
and values to add/update.
|
||||
"""
|
||||
env = os.environ
|
||||
update = update or {}
|
||||
remove = remove or []
|
||||
|
||||
# List of environment variables being updated or removed.
|
||||
stomped = (set(update.keys()) | set(remove)) & set(env.keys())
|
||||
# Environment variables and values to restore on exit.
|
||||
update_after = {k: env[k] for k in stomped}
|
||||
# Environment variables and values to remove on exit.
|
||||
remove_after = frozenset(k for k in update if k not in env)
|
||||
|
||||
try:
|
||||
env.update(update)
|
||||
[env.pop(k, None) for k in remove]
|
||||
yield
|
||||
finally:
|
||||
env.update(update_after)
|
||||
[env.pop(k) for k in remove_after]
|
||||
|
||||
|
||||
def is_latest(representation):
|
||||
"""Return whether the representation is from latest version
|
||||
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
import os
|
||||
import acre
|
||||
|
||||
from avalon import api, lib, io
|
||||
import pype.api as pype
|
||||
|
||||
|
||||
class PremierePro(api.Action):
|
||||
|
||||
name = "premiere_2019"
|
||||
label = "Premiere Pro"
|
||||
icon = "premiere_icon"
|
||||
order = 996
|
||||
|
||||
def is_compatible(self, session):
|
||||
"""Return whether the action is compatible with the session"""
|
||||
if "AVALON_TASK" in session:
|
||||
return True
|
||||
return False
|
||||
|
||||
def process(self, session, **kwargs):
|
||||
"""Implement the behavior for when the action is triggered
|
||||
|
||||
Args:
|
||||
session (dict): environment dictionary
|
||||
|
||||
Returns:
|
||||
Popen instance of newly spawned process
|
||||
|
||||
"""
|
||||
|
||||
with pype.modified_environ(**session):
|
||||
# Get executable by name
|
||||
app = lib.get_application(self.name)
|
||||
executable = lib.which(app["executable"])
|
||||
|
||||
# Run as server
|
||||
arguments = []
|
||||
|
||||
tools_env = acre.get_tools([self.name])
|
||||
env = acre.compute(tools_env)
|
||||
env = acre.merge(env, current_env=dict(os.environ))
|
||||
|
||||
if not env.get('AVALON_WORKDIR', None):
|
||||
project_name = env.get("AVALON_PROJECT")
|
||||
anatomy = pype.Anatomy(project_name)
|
||||
os.environ['AVALON_PROJECT'] = project_name
|
||||
io.Session['AVALON_PROJECT'] = project_name
|
||||
|
||||
task_name = os.environ.get(
|
||||
"AVALON_TASK", io.Session["AVALON_TASK"]
|
||||
)
|
||||
asset_name = os.environ.get(
|
||||
"AVALON_ASSET", io.Session["AVALON_ASSET"]
|
||||
)
|
||||
application = lib.get_application(
|
||||
os.environ["AVALON_APP_NAME"]
|
||||
)
|
||||
|
||||
project_doc = io.find_one({"type": "project"})
|
||||
data = {
|
||||
"task": task_name,
|
||||
"asset": asset_name,
|
||||
"project": {
|
||||
"name": project_doc["name"],
|
||||
"code": project_doc["data"].get("code", '')
|
||||
},
|
||||
"hierarchy": pype.get_hierarchy(),
|
||||
"app": application["application_dir"]
|
||||
}
|
||||
anatomy_filled = anatomy.format(data)
|
||||
workdir = anatomy_filled["work"]["folder"]
|
||||
|
||||
os.environ["AVALON_WORKDIR"] = workdir
|
||||
|
||||
env.update(dict(os.environ))
|
||||
|
||||
lib.launch(
|
||||
executable=executable,
|
||||
args=arguments,
|
||||
environment=env
|
||||
)
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue