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

Commit

Permalink
Fix local workfile overwritten on update in some cases (#7)
Browse files Browse the repository at this point in the history
* Fix: Local workfile overwrite when local version number is higher than published workfile version number (WiP)

* Changed regex search, clean up

* Readded mistakenly removed newline
  • Loading branch information
Sharkitty authored and Tilix4 committed Mar 15, 2023
1 parent 880e0f2 commit 608da47
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions openpype/modules/sync_server/sync_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Python 3 only implementation."""
import os
import re
import shutil
import asyncio
import threading
Expand All @@ -15,9 +16,12 @@
from openpype.pipeline import Anatomy
from openpype.pipeline.template_data import get_template_data_with_names
from openpype.pipeline.load.utils import get_representation_path_with_anatomy
from openpype.pipeline.workfile.path_resolving import get_workfile_template_key
from openpype.pipeline.workfile.path_resolving import (
get_workfile_template_key,
get_workdir,
)
from openpype.settings.lib import get_project_settings
from openpype.client.entities import get_asset_by_name
from openpype.client.entities import get_asset_by_name, get_project

from .utils import SyncStatus, ResumableError

Expand Down Expand Up @@ -349,12 +353,59 @@ def download_last_published_workfile(
workfile_data = get_template_data_with_names(
project_name, asset_name, task_name, host_name
)
workfile_data["version"] = last_version_doc["name"] + 1
workfile_data["ext"] = last_published_workfile_path.split(".")[-1]

extension = last_published_workfile_path.split(".")[-1]

project_settings = get_project_settings(project_name)
template_key = get_workfile_template_key(
task_name, host_name, project_name, get_project_settings(project_name)
task_name, host_name, project_name, project_settings
)

# Get version patter for regex search
version_pattern = anatomy.templates[template_key]["version"]
version_pattern = re.sub(
r"{version.*?}",
r"([0-9]+)",
version_pattern,
)

# Get local workfile version number
last_local_workfile_version = None
for filename in sorted(
os.listdir(
get_workdir(
get_project(project_name),
asset_doc,
task_name,
host_name,
anatomy=anatomy,
template_key=template_key,
project_settings=project_settings,
)
),
reverse=True,
):
if filename.endswith(extension):
match = re.search(
version_pattern,
filename
)
if match:
last_local_workfile_version = int(match.group(1))
break

# Set workfile data workfile version
# Either last published version or last local version, whichever is higher
workfile_data["version"] = (
last_local_workfile_version + 1
if (
last_local_workfile_version
and last_local_workfile_version > last_version_doc["name"]
)
else last_version_doc["name"] + 1
)
workfile_data["ext"] = extension

anatomy_result = anatomy.format(workfile_data)
local_workfile_path = anatomy_result[template_key]["path"]

Expand Down

0 comments on commit 608da47

Please sign in to comment.