mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
OP-2951 - implemented synching referenced files in workfile
When workfile is synched, it checks for referenced files (added by Loader) and tries to sync them too.
This commit is contained in:
parent
ea8b3b79b1
commit
d340d05bf0
1 changed files with 61 additions and 11 deletions
|
|
@ -1,9 +1,19 @@
|
|||
from openpype.modules import ModulesManager
|
||||
from openpype.pipeline import load
|
||||
:from openpype.lib.avalon_context import get_linked_ids_for_representations
|
||||
from openpype.modules.sync_server.utils import SiteAlreadyPresentError
|
||||
|
||||
|
||||
class AddSyncSite(load.LoaderPlugin):
|
||||
"""Add sync site to representation"""
|
||||
"""Add sync site to representation
|
||||
|
||||
If family of synced representation is 'workfile', it looks for all
|
||||
representations which are referenced (loaded) in workfile with content of
|
||||
'inputLinks'.
|
||||
It doesn't do any checks for site, most common use case is when artist is
|
||||
downloading workfile to his local site, but it might be helpful when
|
||||
artist is re-uploading broken representation on remote site also.
|
||||
"""
|
||||
representations = ["*"]
|
||||
families = ["*"]
|
||||
|
||||
|
|
@ -12,21 +22,61 @@ class AddSyncSite(load.LoaderPlugin):
|
|||
icon = "download"
|
||||
color = "#999999"
|
||||
|
||||
_sync_server = None
|
||||
|
||||
@property
|
||||
def sync_server(self):
|
||||
if not self._sync_server:
|
||||
manager = ModulesManager()
|
||||
self._sync_server = manager.modules_by_name["sync_server"]
|
||||
|
||||
return self._sync_server
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
self.log.info("Adding {} to representation: {}".format(
|
||||
data["site_name"], data["_id"]))
|
||||
self.add_site_to_representation(data["project_name"],
|
||||
data["_id"],
|
||||
data["site_name"])
|
||||
family = context["representation"]["context"]["family"]
|
||||
project_name = data["project_name"]
|
||||
repre_id = data["_id"]
|
||||
|
||||
add_ids = [repre_id]
|
||||
if family == "workfile":
|
||||
links = get_linked_ids_for_representations(project_name,
|
||||
add_ids,
|
||||
link_type="reference")
|
||||
add_ids.extend(links)
|
||||
|
||||
add_ids = set(add_ids)
|
||||
self.log.info("Add to repre_ids {}".format(add_ids))
|
||||
is_main = True
|
||||
for add_repre_id in add_ids:
|
||||
self.add_site_to_representation(project_name,
|
||||
add_repre_id,
|
||||
data["site_name"],
|
||||
is_main)
|
||||
is_main = False
|
||||
|
||||
self.log.debug("Site added.")
|
||||
|
||||
@staticmethod
|
||||
def add_site_to_representation(project_name, representation_id, site_name):
|
||||
"""Adds new site to representation_id, resets if exists"""
|
||||
manager = ModulesManager()
|
||||
sync_server = manager.modules_by_name["sync_server"]
|
||||
sync_server.add_site(project_name, representation_id, site_name,
|
||||
force=True)
|
||||
def add_site_to_representation(self, project_name, representation_id,
|
||||
site_name, is_main):
|
||||
"""Adds new site to representation_id, resets if exists
|
||||
|
||||
Args:
|
||||
project_name (str)
|
||||
representation_id (ObjectId):
|
||||
site_name (str)
|
||||
is_main (bool): true for really downloaded, false for references,
|
||||
force redownload main file always, for references only if
|
||||
broken
|
||||
"""
|
||||
try:
|
||||
self.sync_server.add_site(project_name, representation_id,
|
||||
site_name,
|
||||
force=is_main,
|
||||
force_only_broken=not is_main)
|
||||
except SiteAlreadyPresentError:
|
||||
self.log.debug("Site present", exc_info=True)
|
||||
|
||||
def filepath_from_context(self, context):
|
||||
"""No real file loading"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue