Hi!
We have set up sitesync where we have our internal server available through sftp for artists outside the office.
sftp is set up as a site where “alternative sites” is studio.
This seems to be working correctly most of the time, but today we ran into an issue where the status on some files are not correct for sftp. A file was published from a machine that was set for studio:studio. Sitesync says the file is available on studio, but “N/A” on sftp.
There has been something weird going on with settings, might be related to this: Site sync settings issue
What i am actually wondering is if there any scripts or process i can run to update the sitesync status on the files. i.e it goes through any missing files on sftp and check if they are available, and sets the correct status.
Related to that would also be something that checks all local files if they are uploaded to remote, and queues any missing files.
Any help or points in the right direction here would be great!
You could experiment with:
from ayon_api import get_representations
from ayon_core.addon import AddonsManager
from ayon_sitesync.utils import SiteAlreadyPresentError, SiteSyncStatus
PROJECT_NAME = "sitesync_project" # FILLME
SITE_NAME = "studio" # FILLME, keep studio as default
STATUS = SiteSyncStatus.OK # SiteSyncStatus.QUEUED >> should be synchronized to SITE_NAME
manager = AddonsManager()
sitesync_addon = manager.get("sitesync")
representations = list(get_representations(PROJECT_NAME, fields=["id"]))
no_of_representations = {len(representations)}
print(f"Found no_of_representations {no_of_representations}")
for idx, repre in enumerate(representations):
if idx % 50 == 0:
print(f"Processing {idx} representation out of {no_of_representations}")
try:
sitesync_addon.add_site(PROJECT_NAME, repre["id"], SITE_NAME, status=STATUS)
except SiteAlreadyPresentError:
pass
This could be used on a project where SiteSync was setup during production. This script makes all already published representation present on studio.
It could be run from any Launcher > Admin > Console.
thanks! Just so I understand this code, this would set the status off all representations on studio site to “OK”? So if i wanted to update all representations on sftp to OK, I would just update “SITE_NAME” to that, right?
Actually want I would need to do is set the status on the representation to the same as what is on studio, as they are actually the same filesystem. As there might be some stray files that somebody has local and haven’t been able to upload.
if i wanted to fix any missed uploads, i would use “sitesync_addon .get_repre_sync_state” to check the state and set the representation to queued if it is on local, but not on remote, does that sound right? Not sure if that function gives me the right info though.
Okay, testing this a bit I came up with this:
from ayon_api import get_representations
from ayon_core.addon import AddonsManager
from ayon_sitesync.utils import SiteAlreadyPresentError, SiteSyncStatus
PROJECT_NAME = "PROJECT_NAME" # FILLME
SITE_NAME = "studio" # FILLME, keep studio as default
SFTP_SITE_NAME = "sftp" #FILLME
manager = AddonsManager()
sitesync_addon = manager.get("sitesync")
representations = list(get_representations(PROJECT_NAME, fields=["id"]))
no_of_representations = {len(representations)}
print(f"Found no_of_representations {no_of_representations}")
for idx, repre in enumerate(representations):
if idx % 50 == 0:
print(f"Processing {idx} representation out of {no_of_representations}", flush=True)
try:
state = sitesync_addon.get_repre_sync_state(
PROJECT_NAME,repre["id"], SITE_NAME, SFTP_SITE_NAME
)
if not state:
# I don't know why this happens, where the state is None ¯\_(ツ)_/¯
continue
localstatus = state["localStatus"]["status"]
remoteStatus = state["remoteStatus"]["status"]
if localstatus != remoteStatus and localstatus == SiteSyncStatus.OK:
print(f"Setting local status to {localstatus} for representation {repre['id']}")
sitesync_addon.add_site(
PROJECT_NAME, repre["id"],
SFTP_SITE_NAME,
status=localstatus
)
except SiteAlreadyPresentError:
pass
This seems to work, do you think there is any edgecases where this might mess up?
And then for fixing any missed uploads I could do this:
from ayon_api import get_representations
from ayon_core.addon import AddonsManager
from ayon_sitesync.utils import SiteAlreadyPresentError, SiteSyncStatus
PROJECT_NAME = "PROJECT_NAME" # FILLME
manager = AddonsManager()
sitesync_addon = manager.get("sitesync")
LOCAL_SITE_NAME = sitesync_addon.get_active_site(PROJECT_NAME)
REMOTE_SITE_NAME = sitesync_addon.get_remote_site(PROJECT_NAME)
if LOCAL_SITE_NAME == REMOTE_SITE_NAME:
print("Local and remote site names are the same, exiting.")
else:
representations = list(get_representations(PROJECT_NAME, fields=["id"]))
no_of_representations = {len(representations)}
print(f"Found no_of_representations {no_of_representations}")
for idx, repre in enumerate(representations):
if idx % 50 == 0:
print(f"Processing {idx} representation out of {no_of_representations}", flush=True)
try:
state = sitesync_addon.get_repre_sync_state(
PROJECT_NAME,repre["id"], LOCAL_SITE_NAME, REMOTE_SITE_NAME
)
if not state:
# I don't know why this happens, where the state is None ¯\_(ツ)_/¯
continue
localstatus = state["localStatus"]["status"]
remoteStatus = state["remoteStatus"]["status"]
if localstatus == SiteSyncStatus.OK and remoteStatus == SiteSyncStatus.NA:
print(f"Setting local status to QUEUED for representation {repre['id']}")
sitesync_addon.add_site(
PROJECT_NAME,
repre["id"],
LOCAL_SITE_NAME,
status=SiteSyncStatus.QUEUED
)
except SiteAlreadyPresentError:
pass
Would that work / not mess anything up?