Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3066 from pypeclub/enhancement/OP-2858_move-Avalo…
Browse files Browse the repository at this point in the history
…nMongoDB-logic

General: Move mongo db logic and remove avalon repository
  • Loading branch information
iLLiCiTiT authored Apr 25, 2022
2 parents b59a408 + 2584881 commit 84991dd
Show file tree
Hide file tree
Showing 228 changed files with 1,842 additions and 1,271 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "repos/avalon-core"]
path = repos/avalon-core
url = https://github.com/pypeclub/avalon-core.git
67 changes: 18 additions & 49 deletions igniter/bootstrap_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ class BootstrapRepos:
Attributes:
data_dir (Path): local OpenPype installation directory.
live_repo_dir (Path): path to repos directory if running live,
otherwise `None`.
registry (OpenPypeSettingsRegistry): OpenPype registry object.
zip_filter (list): List of files to exclude from zip
openpype_filter (list): list of top level directories to
Expand All @@ -654,7 +652,7 @@ def __init__(self, progress_callback: Callable = None, message=None):
self.registry = OpenPypeSettingsRegistry()
self.zip_filter = [".pyc", "__pycache__"]
self.openpype_filter = [
"openpype", "repos", "schema", "LICENSE"
"openpype", "schema", "LICENSE"
]
self._message = message

Expand All @@ -667,11 +665,6 @@ def empty_progress(x: int):
progress_callback = empty_progress
self._progress_callback = progress_callback

if getattr(sys, "frozen", False):
self.live_repo_dir = Path(sys.executable).parent / "repos"
else:
self.live_repo_dir = Path(Path(__file__).parent / ".." / "repos")

@staticmethod
def get_version_path_from_list(
version: str, version_list: list) -> Union[Path, None]:
Expand Down Expand Up @@ -736,11 +729,12 @@ def create_version_from_live_code(
# if repo dir is not set, we detect local "live" OpenPype repository
# version and use it as a source. Otherwise repo_dir is user
# entered location.
if not repo_dir:
version = OpenPypeVersion.get_installed_version_str()
repo_dir = self.live_repo_dir
else:
if repo_dir:
version = self.get_version(repo_dir)
else:
installed_version = OpenPypeVersion.get_installed_version()
version = str(installed_version)
repo_dir = installed_version.path

if not version:
self._print("OpenPype not found.", LOG_ERROR)
Expand All @@ -756,7 +750,7 @@ def create_version_from_live_code(
Path(temp_dir) / f"openpype-v{version}.zip"
self._print(f"creating zip: {temp_zip}")

self._create_openpype_zip(temp_zip, repo_dir.parent)
self._create_openpype_zip(temp_zip, repo_dir)
if not os.path.exists(temp_zip):
self._print("make archive failed.", LOG_ERROR)
return None
Expand Down Expand Up @@ -1057,27 +1051,11 @@ def add_paths_from_archive(archive: Path) -> None:
if not archive.is_file() and not archive.exists():
raise ValueError("Archive is not file.")

with ZipFile(archive, "r") as zip_file:
name_list = zip_file.namelist()

roots = []
paths = []
for item in name_list:
if not item.startswith("repos/"):
continue

root = item.split("/")[1]

if root not in roots:
roots.append(root)
paths.append(
f"{archive}{os.path.sep}repos{os.path.sep}{root}")
sys.path.insert(0, paths[-1])

sys.path.insert(0, f"{archive}")
archive_path = str(archive)
sys.path.insert(0, archive_path)
pythonpath = os.getenv("PYTHONPATH", "")
python_paths = pythonpath.split(os.pathsep)
python_paths += paths
python_paths.insert(0, archive_path)

os.environ["PYTHONPATH"] = os.pathsep.join(python_paths)

Expand All @@ -1094,24 +1072,8 @@ def add_paths_from_directory(directory: Path) -> None:
directory (Path): path to directory.
"""
sys.path.insert(0, directory.as_posix())
directory /= "repos"
if not directory.exists() and not directory.is_dir():
raise ValueError("directory is invalid")

roots = []
for item in directory.iterdir():
if item.is_dir():
root = item.as_posix()
if root not in roots:
roots.append(root)
sys.path.insert(0, root)

pythonpath = os.getenv("PYTHONPATH", "")
paths = pythonpath.split(os.pathsep)
paths += roots

os.environ["PYTHONPATH"] = os.pathsep.join(paths)
sys.path.insert(0, directory.as_posix())

@staticmethod
def find_openpype_version(version, staging):
Expand Down Expand Up @@ -1437,6 +1399,7 @@ def install_version(self,
# create destination parent directories even if they don't exist.
destination.mkdir(parents=True)

remove_source_file = False
# version is directory
if openpype_version.path.is_dir():
# create zip inside temporary directory.
Expand Down Expand Up @@ -1470,6 +1433,8 @@ def install_version(self,
self._progress_callback(35)
openpype_version.path = self._copy_zip(
openpype_version.path, destination)
# Mark zip to be deleted when done
remove_source_file = True

# extract zip there
self._print("extracting zip to destination ...")
Expand All @@ -1478,6 +1443,10 @@ def install_version(self,
zip_ref.extractall(destination)
self._progress_callback(100)

# Remove zip file copied to local app data
if remove_source_file:
os.remove(openpype_version.path)

return destination

def _copy_zip(self, source: Path, destination: Path) -> Path:
Expand Down
5 changes: 2 additions & 3 deletions openpype/hooks/pre_global_host_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
prepare_app_environments,
prepare_context_environments
)

import avalon.api
from openpype.pipeline import AvalonMongoDB


class GlobalHostDataHook(PreLaunchHook):
Expand Down Expand Up @@ -64,7 +63,7 @@ def prepare_global_data(self):
self.data["anatomy"] = Anatomy(project_name)

# Mongo connection
dbcon = avalon.api.AvalonMongoDB()
dbcon = AvalonMongoDB()
dbcon.Session["AVALON_PROJECT"] = project_name
dbcon.install()

Expand Down
9 changes: 4 additions & 5 deletions openpype/hosts/aftereffects/api/launch_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

from Qt import QtCore

from openpype.pipeline import legacy_io
from openpype.tools.utils import host_tools

from avalon import api
from openpype.tools.adobe_webserver.app import WebServerTool

from .ws_stub import AfterEffectsServerStub
Expand Down Expand Up @@ -271,13 +270,13 @@ async def set_context(self, project, asset, task):
log.info("Setting context change")
log.info("project {} asset {} ".format(project, asset))
if project:
api.Session["AVALON_PROJECT"] = project
legacy_io.Session["AVALON_PROJECT"] = project
os.environ["AVALON_PROJECT"] = project
if asset:
api.Session["AVALON_ASSET"] = asset
legacy_io.Session["AVALON_ASSET"] = asset
os.environ["AVALON_ASSET"] = asset
if task:
api.Session["AVALON_TASK"] = task
legacy_io.Session["AVALON_TASK"] = task
os.environ["AVALON_TASK"] = task

async def read(self):
Expand Down
30 changes: 8 additions & 22 deletions openpype/hosts/aftereffects/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from Qt import QtWidgets

import pyblish.api
from avalon import io

from openpype import lib
from openpype.api import Logger
Expand All @@ -14,7 +13,7 @@
deregister_loader_plugin_path,
deregister_creator_plugin_path,
AVALON_CONTAINER_ID,
registered_host,
legacy_io,
)
import openpype.hosts.aftereffects
from openpype.lib import register_event_callback
Expand Down Expand Up @@ -140,23 +139,11 @@ def check_inventory():
if not lib.any_outdated():
return

host = pyblish.api.registered_host()
outdated_containers = []
for container in host.ls():
representation = container['representation']
representation_doc = io.find_one(
{
"_id": io.ObjectId(representation),
"type": "representation"
},
projection={"parent": True}
)
if representation_doc and not lib.is_latest(representation_doc):
outdated_containers.append(container)

# Warn about outdated containers.
print("Starting new QApplication..")
_app = QtWidgets.QApplication(sys.argv)
_app = QtWidgets.QApplication.instance()
if not _app:
print("Starting new QApplication..")
_app = QtWidgets.QApplication([])

message_box = QtWidgets.QMessageBox()
message_box.setIcon(QtWidgets.QMessageBox.Warning)
Expand Down Expand Up @@ -282,11 +269,10 @@ def update_context_data(data, changes):

def get_context_title():
"""Returns title for Creator window"""
import avalon.api

project_name = avalon.api.Session["AVALON_PROJECT"]
asset_name = avalon.api.Session["AVALON_ASSET"]
task_name = avalon.api.Session["AVALON_TASK"]
project_name = legacy_io.Session["AVALON_PROJECT"]
asset_name = legacy_io.Session["AVALON_ASSET"]
task_name = legacy_io.Session["AVALON_TASK"]
return "{}/{}/{}".format(project_name, asset_name, task_name)


Expand Down
7 changes: 3 additions & 4 deletions openpype/hosts/aftereffects/plugins/create/create_render.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from avalon import api as avalon_api

from openpype import resources
from openpype.lib import BoolDef, UISeparatorDef
from openpype.hosts.aftereffects import api
from openpype.pipeline import (
Creator,
CreatedInstance,
CreatorError
CreatorError,
legacy_io,
)


Expand Down Expand Up @@ -116,7 +115,7 @@ def _handle_legacy(self, instance_data):
instance_data.pop("uuid")

if not instance_data.get("task"):
instance_data["task"] = avalon_api.Session.get("AVALON_TASK")
instance_data["task"] = legacy_io.Session.get("AVALON_TASK")

if not instance_data.get("creator_attributes"):
is_old_farm = instance_data["family"] != "renderLocal"
Expand Down
23 changes: 14 additions & 9 deletions openpype/hosts/aftereffects/plugins/create/workfile_creator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from avalon import io

import openpype.hosts.aftereffects.api as api
from openpype.pipeline import (
AutoCreator,
CreatedInstance
CreatedInstance,
legacy_io,
)


Expand Down Expand Up @@ -36,13 +35,16 @@ def create(self, options=None):
break

variant = ''
project_name = io.Session["AVALON_PROJECT"]
asset_name = io.Session["AVALON_ASSET"]
task_name = io.Session["AVALON_TASK"]
host_name = io.Session["AVALON_APP"]
project_name = legacy_io.Session["AVALON_PROJECT"]
asset_name = legacy_io.Session["AVALON_ASSET"]
task_name = legacy_io.Session["AVALON_TASK"]
host_name = legacy_io.Session["AVALON_APP"]

if existing_instance is None:
asset_doc = io.find_one({"type": "asset", "name": asset_name})
asset_doc = legacy_io.find_one({
"type": "asset",
"name": asset_name
})
subset_name = self.get_subset_name(
variant, task_name, asset_doc, project_name, host_name
)
Expand All @@ -67,7 +69,10 @@ def create(self, options=None):
existing_instance["asset"] != asset_name
or existing_instance["task"] != task_name
):
asset_doc = io.find_one({"type": "asset", "name": asset_name})
asset_doc = legacy_io.find_one({
"type": "asset",
"name": asset_name
})
subset_name = self.get_subset_name(
variant, task_name, asset_doc, project_name, host_name
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from avalon import api

import pyblish.api
from openpype.lib import get_subset_name_with_asset_doc
from openpype.pipeline import legacy_io


class CollectWorkfile(pyblish.api.ContextPlugin):
Expand Down Expand Up @@ -41,7 +42,7 @@ def process(self, context):
instance.data["publish"] = instance.data["active"] # for DL

def _get_new_instance(self, context, scene_file):
task = api.Session["AVALON_TASK"]
task = legacy_io.Session["AVALON_TASK"]
version = context.data["version"]
asset_entity = context.data["assetEntity"]
project_entity = context.data["projectEntity"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from avalon import api
import pyblish.api

import openpype.api
from openpype.pipeline import PublishXmlValidationError
from openpype.pipeline import (
PublishXmlValidationError,
legacy_io,
)
from openpype.hosts.aftereffects.api import get_stub


Expand All @@ -27,7 +30,7 @@ def process(self, context, plugin):
for instance in instances:
data = stub.read(instance[0])

data["asset"] = api.Session["AVALON_ASSET"]
data["asset"] = legacy_io.Session["AVALON_ASSET"]
stub.imprint(instance[0].instance_id, data)


Expand All @@ -51,7 +54,7 @@ class ValidateInstanceAsset(pyblish.api.InstancePlugin):

def process(self, instance):
instance_asset = instance.data["asset"]
current_asset = api.Session["AVALON_ASSET"]
current_asset = legacy_io.Session["AVALON_ASSET"]
msg = (
f"Instance asset {instance_asset} is not the same "
f"as current context {current_asset}."
Expand Down
Loading

0 comments on commit 84991dd

Please sign in to comment.