Skip to content

submit_harmony_deadline

Submitting render job to Deadline.

HarmonySubmitDeadline

Bases: AbstractSubmitDeadline

Submit render write of Harmony scene to Deadline.

Renders are submitted to a Deadline Web Service as supplied via the environment variable DEADLINE_REST_URL.

Harmony workfile is .zip file that needs to be unzipped for Deadline first (DL expects unzipped folder). In case of use of published workfile, .zip file is copied to work/../renders and unzipped there.

Note

If Deadline configuration is not detected, this plugin will be disabled.

Attributes:

Name Type Description
use_published bool

Use published scene to render instead of the one in work area.

Source code in client/ayon_deadline/plugins/publish/harmony/submit_harmony_deadline.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
class HarmonySubmitDeadline(
    abstract_submit_deadline.AbstractSubmitDeadline
):
    """Submit render write of Harmony scene to Deadline.

    Renders are submitted to a Deadline Web Service as
    supplied via the environment variable ``DEADLINE_REST_URL``.

    Harmony workfile is `.zip` file that needs to be unzipped for Deadline
    first (DL expects unzipped folder). In case of use of published workfile,
    `.zip` file is copied to `work/../renders` and unzipped there.

    Note:
        If Deadline configuration is not detected, this plugin will
        be disabled.

    Attributes:
        use_published (bool): Use published scene to render instead of the
            one in work area.

    """

    label = "Submit to Deadline"
    order = pyblish.api.IntegratorOrder + 0.1
    hosts = ["harmony"]
    families = ["render.farm"]
    targets = ["local"]
    settings_category = "deadline"

    def get_job_info(self, job_info=None):
        job_info.Plugin = "HarmonyAYON"
        job_info.Frames = "{}-{}".format(
            self._instance.data["frameStartHandle"],
            self._instance.data["frameEndHandle"]
        )

        return job_info

    def _unzip_scene_file(self, published_scene: Path) -> Path:
        """Unzip scene zip file to its directory.

        Unzip scene file (if it is zip file) to work area if dir if available,
        if not to its current directory and
        return path to xstage file there. Xstage file is determined by its
        name.

        Args:
            published_scene (Path): path to zip file.

        Returns:
            Path: The path to unzipped xstage.
        """
        # if not zip, bail out.
        if "zip" not in published_scene.suffix or not is_zipfile(
            published_scene.as_posix()
        ):
            self.log.error("Published scene is not in zip.")
            self.log.error(published_scene)
            raise AssertionError("invalid scene format")

        # TODO eventually replace with registered_host().work_root or similar
        workdir = os.environ.get("AYON_WORKDIR")
        if workdir and os.path.exists(workdir):
            renders_path = os.path.join(workdir, "renders", "harmony")
            os.makedirs(renders_path, exist_ok=True)

            self.log.info(f"Copying '{published_scene}' -> '{renders_path}'")
            shutil.copy(published_scene.as_posix(), renders_path)
            published_scene = Path(
                os.path.join(renders_path), published_scene.name)
            (self._instance.context.data["cleanupFullPaths"].
             append(published_scene))

        xstage_path = (
            published_scene.parent
            / published_scene.stem
            / f"{published_scene.stem}.xstage"
        )
        unzip_dir = (published_scene.parent / published_scene.stem)
        with _ZipFile(published_scene, "r") as zip_ref:
            # UNC path (//?/) added to minimalize risk with extracting
            # to large file paths
            zip_ref.extractall("//?/" + str(unzip_dir.as_posix()))

        # find any xstage files in directory, prefer the one with the same name
        # as directory (plus extension)
        xstage_files = []
        for scene in unzip_dir.iterdir():
            if scene.suffix == ".xstage":
                xstage_files.append(scene)

        # there must be at least one (but maybe not more?) xstage file
        if not xstage_files:
            self.log.error("No xstage files found in zip")
            raise AssertionError("Invalid scene archive")

        ideal_scene = False
        # find the one with the same name as zip. In case there can be more
        # then one xtage file.
        for scene in xstage_files:
            # if /foo/bar/baz.zip == /foo/bar/baz/baz.xstage
            #             ^^^                     ^^^
            if scene.stem == published_scene.stem:
                xstage_path = scene
                ideal_scene = True

        # but sometimes xstage file has different name then zip - in that case
        # use that one.
        if not ideal_scene:
            xstage_path = xstage_files[0]
        return xstage_path

    def get_plugin_info(self):
        # this is path to published scene workfile _ZIP_. Before
        # rendering, we need to unzip it.
        published_scene = Path(
            self.from_published_scene(False))
        self.log.debug(f"Processing {published_scene.as_posix()}")
        xstage_path = self._unzip_scene_file(published_scene)
        render_path = xstage_path.parent / "renders"

        # for submit_publish job to create .json file in
        self._instance.data["outputDir"] = render_path
        # to let DL Explore Output
        # TODO update this when #79 is fixed
        self.job_info.OutputDirectory[0] = render_path.as_posix()
        new_expected_files = []
        render_path_str = str(render_path.as_posix())
        for file in self._instance.data["expectedFiles"]:
            _file = str(Path(file).as_posix())
            expected_dir_str = os.path.dirname(_file)
            new_expected_files.append(
                _file.replace(expected_dir_str, render_path_str)
            )
        audio_file = self._instance.data.get("audioFile")
        if audio_file:
            abs_path = xstage_path.parent / audio_file
            self._instance.context.data["audioFile"] = str(abs_path)

        self._instance.data["source"] = str(published_scene.as_posix())
        self._instance.data["expectedFiles"] = new_expected_files
        harmony_plugin_info = PluginInfo(
            SceneFile=xstage_path.as_posix(),
            Version=(
                self._instance.context.data["harmonyVersion"].split(".")[0]),
            FieldOfView=self._instance.context.data["FOV"],
            ResolutionX=self._instance.data["resolutionWidth"],
            ResolutionY=self._instance.data["resolutionHeight"]
        )

        leading_zeros = str(self._instance.data["leadingZeros"])
        frames_and_ext_pattern = f"0{{{leading_zeros}}}[1-9]\\.[a-zA-Z]{{3}}"
        render_prefix = re.sub(frames_and_ext_pattern, "",
                               self._instance.data["expectedFiles"][0])
        harmony_plugin_info.set_output(
            self._instance.data["setMembers"][0],
            self._instance.data["outputFormat"],
            render_prefix,
            self._instance.data["outputType"],
            self._instance.data["leadingZeros"],
            self._instance.data["outputStartFrame"]
        )

        all_write_nodes = self._instance.context.data["all_write_nodes"]
        disable_nodes = []
        for node in all_write_nodes:
            # disable all other write nodes
            if node != self._instance.data["setMembers"][0]:
                disable_nodes.append("node.setEnable('{}', false)"
                                     .format(node))
        harmony_plugin_info.PreRenderInlineScript = ';'.join(disable_nodes)

        return harmony_plugin_info.serialize()

PluginInfo

Bases: object

Plugin info structure for Harmony Deadline plugin.

Source code in client/ayon_deadline/plugins/publish/harmony/submit_harmony_deadline.py
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
@attr.s
class PluginInfo(object):
    """Plugin info structure for Harmony Deadline plugin."""

    SceneFile = attr.ib()
    # Harmony version
    Version = attr.ib()

    Camera = attr.ib(default="")
    FieldOfView = attr.ib(default=41.11)
    IsDatabase = attr.ib(default=False)
    ResolutionX = attr.ib(default=1920)
    ResolutionY = attr.ib(default=1080)

    # Resolution name preset, default
    UsingResPreset = attr.ib(default=False)
    ResolutionName = attr.ib(default="HDTV_1080p24")

    PreRenderInlineScript = attr.ib(default=None)

    # --------------------------------------------------
    _outputNode = attr.ib(factory=list)

    @property
    def OutputNode(self):  # noqa: N802
        """Return all output nodes formatted for Deadline.

        Returns:
            dict: as `{'Output0Node', 'Top/renderFarmDefault'}`

        """
        out = {}
        for index, v in enumerate(self._outputNode):
            out["Output{}Node".format(index)] = v
        return out

    @OutputNode.setter
    def OutputNode(self, val):  # noqa: N802
        self._outputNode.append(val)

    # --------------------------------------------------
    _outputType = attr.ib(factory=list)

    @property
    def OutputType(self):  # noqa: N802
        """Return output nodes type formatted for Deadline.

        Returns:
            dict: as `{'Output0Type', 'Image'}`

        """
        out = {}
        for index, v in enumerate(self._outputType):
            out["Output{}Type".format(index)] = v
        return out

    @OutputType.setter
    def OutputType(self, val):  # noqa: N802
        self._outputType.append(val)

    # --------------------------------------------------
    _outputLeadingZero = attr.ib(factory=list)

    @property
    def OutputLeadingZero(self):  # noqa: N802
        """Return output nodes type formatted for Deadline.

        Returns:
            dict: as `{'Output0LeadingZero', '3'}`

        """
        out = {}
        for index, v in enumerate(self._outputLeadingZero):
            out["Output{}LeadingZero".format(index)] = v
        return out

    @OutputLeadingZero.setter
    def OutputLeadingZero(self, val):  # noqa: N802
        self._outputLeadingZero.append(val)

    # --------------------------------------------------
    _outputFormat = attr.ib(factory=list)

    @property
    def OutputFormat(self):  # noqa: N802
        """Return output nodes format formatted for Deadline.

        Returns:
            dict: as `{'Output0Type', 'PNG4'}`

        """
        out = {}
        for index, v in enumerate(self._outputFormat):
            out["Output{}Format".format(index)] = v
        return out

    @OutputFormat.setter
    def OutputFormat(self, val):  # noqa: N802
        self._outputFormat.append(val)

    # --------------------------------------------------
    _outputStartFrame = attr.ib(factory=list)

    @property
    def OutputStartFrame(self):  # noqa: N802
        """Return start frame for output nodes formatted for Deadline.

        Returns:
            dict: as `{'Output0StartFrame', '1'}`

        """
        out = {}
        for index, v in enumerate(self._outputStartFrame):
            out["Output{}StartFrame".format(index)] = v
        return out

    @OutputStartFrame.setter
    def OutputStartFrame(self, val):  # noqa: N802
        self._outputStartFrame.append(val)

    # --------------------------------------------------
    _outputPath = attr.ib(factory=list)

    @property
    def OutputPath(self):  # noqa: N802
        """Return output paths for nodes formatted for Deadline.

        Returns:
            dict: as `{'Output0Path', '/output/path'}`

        """
        out = {}
        for index, v in enumerate(self._outputPath):
            out["Output{}Path".format(index)] = v
        return out

    @OutputPath.setter
    def OutputPath(self, val):  # noqa: N802
        self._outputPath.append(val)

    def set_output(self, node, image_format, output,
                   output_type="Image", zeros=3, start_frame=1):
        """Helper to set output.

        This should be used instead of setting properties individually
        as so index remain consistent.

        Args:
            node (str): harmony write node name
            image_format (str): format of output (PNG4, TIF, ...)
            output (str): output path
            output_type (str, optional): "Image" or "Movie" (not supported).
            zeros (int, optional): Leading zeros (for 0001 = 3)
            start_frame (int, optional): Sequence offset.

        """

        self.OutputNode = node
        self.OutputFormat = image_format
        self.OutputPath = output
        self.OutputType = output_type
        self.OutputLeadingZero = zeros
        self.OutputStartFrame = start_frame

    def serialize(self):
        """Return all data serialized as dictionary.

        Returns:
            OrderedDict: all serialized data.

        """
        def filter_data(a, v):
            if a.name.startswith("_"):
                return False
            if v is None:
                return False
            return True

        serialized = attr.asdict(
            self, dict_factory=OrderedDict, filter=filter_data)
        serialized.update(self.OutputNode)
        serialized.update(self.OutputFormat)
        serialized.update(self.OutputPath)
        serialized.update(self.OutputType)
        serialized.update(self.OutputLeadingZero)
        serialized.update(self.OutputStartFrame)

        return serialized

OutputFormat property writable

Return output nodes format formatted for Deadline.

Returns:

Name Type Description
dict

as {'Output0Type', 'PNG4'}

OutputLeadingZero property writable

Return output nodes type formatted for Deadline.

Returns:

Name Type Description
dict

as {'Output0LeadingZero', '3'}

OutputNode property writable

Return all output nodes formatted for Deadline.

Returns:

Name Type Description
dict

as {'Output0Node', 'Top/renderFarmDefault'}

OutputPath property writable

Return output paths for nodes formatted for Deadline.

Returns:

Name Type Description
dict

as {'Output0Path', '/output/path'}

OutputStartFrame property writable

Return start frame for output nodes formatted for Deadline.

Returns:

Name Type Description
dict

as {'Output0StartFrame', '1'}

OutputType property writable

Return output nodes type formatted for Deadline.

Returns:

Name Type Description
dict

as {'Output0Type', 'Image'}

serialize()

Return all data serialized as dictionary.

Returns:

Name Type Description
OrderedDict

all serialized data.

Source code in client/ayon_deadline/plugins/publish/harmony/submit_harmony_deadline.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def serialize(self):
    """Return all data serialized as dictionary.

    Returns:
        OrderedDict: all serialized data.

    """
    def filter_data(a, v):
        if a.name.startswith("_"):
            return False
        if v is None:
            return False
        return True

    serialized = attr.asdict(
        self, dict_factory=OrderedDict, filter=filter_data)
    serialized.update(self.OutputNode)
    serialized.update(self.OutputFormat)
    serialized.update(self.OutputPath)
    serialized.update(self.OutputType)
    serialized.update(self.OutputLeadingZero)
    serialized.update(self.OutputStartFrame)

    return serialized

set_output(node, image_format, output, output_type='Image', zeros=3, start_frame=1)

Helper to set output.

This should be used instead of setting properties individually as so index remain consistent.

Parameters:

Name Type Description Default
node str

harmony write node name

required
image_format str

format of output (PNG4, TIF, ...)

required
output str

output path

required
output_type str

"Image" or "Movie" (not supported).

'Image'
zeros int

Leading zeros (for 0001 = 3)

3
start_frame int

Sequence offset.

1
Source code in client/ayon_deadline/plugins/publish/harmony/submit_harmony_deadline.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def set_output(self, node, image_format, output,
               output_type="Image", zeros=3, start_frame=1):
    """Helper to set output.

    This should be used instead of setting properties individually
    as so index remain consistent.

    Args:
        node (str): harmony write node name
        image_format (str): format of output (PNG4, TIF, ...)
        output (str): output path
        output_type (str, optional): "Image" or "Movie" (not supported).
        zeros (int, optional): Leading zeros (for 0001 = 3)
        start_frame (int, optional): Sequence offset.

    """

    self.OutputNode = node
    self.OutputFormat = image_format
    self.OutputPath = output
    self.OutputType = output_type
    self.OutputLeadingZero = zeros
    self.OutputStartFrame = start_frame