Save and export a Resolve workfile.
Raises:
| Type | Description |
RuntimeError | If saving, exporting or the project database override fails. Callers such as save_next_version rely on the host save raising instead of returning False. |
Source code in client/ayon_resolve/api/workio.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 | def save_file(filepath):
"""Save and export a Resolve workfile.
Raises:
RuntimeError: If saving, exporting or the project database override
fails. Callers such as ``save_next_version`` rely on the host
save raising instead of returning ``False``.
"""
project_manager = get_project_manager()
project_saved = project_manager.SaveProject()
if not project_saved:
log.error("Failed to save current project!")
raise RuntimeError("Failed to save current Resolve project.")
resolve_project = get_current_resolve_project()
incoming_wf = Path(filepath)
current_wf = incoming_wf.with_name(
resolve_project.GetName() + ".drp")
# handle project db override if set
project_name = get_current_project_name()
settings = get_project_settings(project_name)
override_is_valid = True
if settings["resolve"]["project_db"].get("enabled", False):
log.info("Handling project database override...")
overrides = settings["resolve"]["project_db"]
override_is_valid = handle_project_db_override(
project_name, overrides
)
if not override_is_valid:
raise RuntimeError(
"Failed to save Resolve workfile: invalid project "
"database override."
)
rename_db_project = settings["resolve"].get("rename_db_project_on_increment", True)
if (
"Untitled Project" not in current_wf.stem
and not _is_project_in_current_folder(project_manager, resolve_project)
):
# 'ExportProject' finds projects by name in the current folder only
folder_name = project_manager.GetCurrentFolder()
ProjectFolderMismatchWarning(
resolve_project.GetName(), folder_name
).exec_()
raise RuntimeError(
f"Resolve project '{resolve_project.GetName()}' is not in the"
f" current Project Manager folder '{folder_name}'."
" Open a workfile of this context or start a new project"
" before saving."
)
if "Untitled Project" in current_wf.stem:
# saving initial workfile from currently opened project
new_project = project_manager.CreateProject(incoming_wf.stem)
if not new_project:
raise RuntimeError(
f"Failed to create new Resolve project '{incoming_wf.stem}'."
)
if not project_manager.SaveProject():
raise RuntimeError(
f"Failed to save new Resolve project '{incoming_wf.stem}'."
)
exported = _export_project(
project_manager, incoming_wf.stem, incoming_wf.as_posix()
)
log.info(f"New project {incoming_wf.stem} exported: {exported}")
elif current_wf.stem != incoming_wf.stem:
# workfile shall be incremented
if rename_db_project:
# increment with local renaming
if not resolve_project.SetName(incoming_wf.stem):
raise RuntimeError(
f"Failed to rename Resolve project from "
f"'{current_wf.stem}' to '{incoming_wf.stem}'. "
"A project with that name may already exist."
)
try:
exported = _export_project(
project_manager, incoming_wf.stem, incoming_wf.as_posix()
)
except Exception:
if not resolve_project.SetName(current_wf.stem):
log.error(
"Failed to restore Resolve project name to '%s'.",
current_wf.stem,
)
raise
log.info(f"Incremented workfile with local rename to {incoming_wf.as_posix()}: {exported}")
else:
# increment without local renaming but reimport
_export_project(
project_manager, current_wf.stem, current_wf.as_posix()
)
exported = _export_project(
project_manager, current_wf.stem, incoming_wf.as_posix()
)
if not project_manager.ImportProject(incoming_wf.as_posix()):
raise RuntimeError(
f"Failed to import Resolve project from '{incoming_wf.as_posix()}'."
)
if project_manager.LoadProject(incoming_wf.stem) is None:
raise RuntimeError(
f"Failed to load Resolve project '{incoming_wf.stem}'."
)
log.info(f"Incremented workfile with reimport to {incoming_wf.as_posix()}: {exported}")
else:
# workfile export without increment
exported = _export_project(
project_manager, incoming_wf.stem, incoming_wf.as_posix()
)
log.info(f"Project exported without increment to {incoming_wf.as_posix()}: {exported}")
|