Skip to content

publishing

Publishing related methods for traits.

TransferItem

Represents a single transfer item.

Source file path, destination file path, template that was used to construct the destination path, template data that was used in the template, size of the file, checksum of the file.

Attributes:

Name Type Description
source Path

Source file path.

destination Path

Destination file path.

size int

Size of the file.

checksum str

Checksum of the file.

template str

Template path.

template_data dict[str, Any]

Template data.

representation Representation

Reference to representation

related_trait FileLocation

Reference to the trait that this transfer is related to. This is used to update the trait with the new file path after the transfer is done.

Source code in client/ayon_core/pipeline/traits/publishing.py
 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
class TransferItem:
    """Represents a single transfer item.

    Source file path, destination file path, template that was used to
    construct the destination path, template data that was used in the
    template, size of the file, checksum of the file.

    Attributes:
        source (Path): Source file path.
        destination (Path): Destination file path.
        size (int): Size of the file.
        checksum (str): Checksum of the file.
        template (str): Template path.
        template_data (dict[str, Any]): Template data.
        representation (Representation): Reference to representation
        related_trait (FileLocation): Reference to the trait that this
            transfer is related to. This is used to update the trait with
            the new file path after the transfer is done.

    """
    source: Path
    destination: Path
    size: int
    checksum: str
    template: str
    template_data: dict[str, Any]
    representation: Representation
    related_trait: FileLocation

    def __init__(self,
        source: Path,
        destination: Path,
        size: int,
        checksum: str,
        template: str,
        template_data: dict[str, Any],
        representation: Representation,
        related_trait: FileLocation):

        self.source = source
        self.destination = destination
        self.size = size
        self.checksum = checksum
        self.template = template
        self.template_data = template_data
        self.representation = representation
        self.related_trait = related_trait

    @staticmethod
    def get_file_size(file_path: Path) -> int:
        """Get the size of the file.

        Args:
            file_path (Path): File path.

        Returns:
            int: Size of the file.

        """
        return file_path.stat().st_size

    @staticmethod
    def get_file_checksum(file_path: Path) -> str:
        """Get checksum of the file.

        Args:
            file_path (Path): File path.

        Returns:
            str: Checksum of the file.

        """
        return hashlib.sha256(
            file_path.read_bytes()
        ).hexdigest()

get_file_checksum(file_path) staticmethod

Get checksum of the file.

Parameters:

Name Type Description Default
file_path Path

File path.

required

Returns:

Name Type Description
str str

Checksum of the file.

Source code in client/ayon_core/pipeline/traits/publishing.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@staticmethod
def get_file_checksum(file_path: Path) -> str:
    """Get checksum of the file.

    Args:
        file_path (Path): File path.

    Returns:
        str: Checksum of the file.

    """
    return hashlib.sha256(
        file_path.read_bytes()
    ).hexdigest()

get_file_size(file_path) staticmethod

Get the size of the file.

Parameters:

Name Type Description Default
file_path Path

File path.

required

Returns:

Name Type Description
int int

Size of the file.

Source code in client/ayon_core/pipeline/traits/publishing.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@staticmethod
def get_file_size(file_path: Path) -> int:
    """Get the size of the file.

    Args:
        file_path (Path): File path.

    Returns:
        int: Size of the file.

    """
    return file_path.stat().st_size

get_legacy_files_for_representation(transfer_items, representation, anatomy)

Get legacy files for a given representation.

This expects the file to exist - it must run after the transfer is done.

This is used to prepare file information for tools working with legacy file data on representation. Like site-sync, etc.

Parameters:

Name Type Description Default
transfer_items list[TransferItem]

List of transfer items.

required
representation Representation

Representation to get files for.

required
anatomy Anatomy

Anatomy to use for preparing file info.

required

Returns:

Name Type Description
list list[dict[str, str]]

List of legacy files.

Source code in client/ayon_core/pipeline/traits/publishing.py
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
def get_legacy_files_for_representation(
        transfer_items: list[TransferItem],
        representation: Representation,
        anatomy: "Anatomy",
    ) -> list[dict[str, str]]:
    """Get legacy files for a given representation.

    This expects the file to exist - it must run after the transfer
    is done.

    This is used to prepare file information for tools working with legacy
    file data on representation. Like site-sync, etc.

    Args:
        transfer_items (list[TransferItem]): List of transfer items.
        representation (Representation): Representation to get files for.
        anatomy (Anatomy): Anatomy to use for preparing file info.

    Returns:
        list: List of legacy files.

    """
    selected: list[TransferItem] = []
    selected.extend(
        item
        for item in transfer_items
        if item.representation == representation
    )
    files: list[dict[str, str]] = []
    files.extend(
        _prepare_file_info(item.destination, anatomy)
        for item in selected
    )
    return files

get_template_data_from_representation(representation, instance)

Get template data from representation.

Using representation traits and data on instance prepare data for formatting template.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
instance Instance

Instance to process.

required

Returns:

Name Type Description
dict dict

Template data.

Source code in client/ayon_core/pipeline/traits/publishing.py
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
def get_template_data_from_representation(
        representation: Representation,
        instance: pyblish.api.Instance) -> dict:
    """Get template data from representation.

    Using representation traits and data on instance
    prepare data for formatting template.

    Args:
        representation (Representation): Representation to process.
        instance (pyblish.api.Instance): Instance to process.

    Returns:
        dict: Template data.

    """
    template_data = copy.deepcopy(instance.data["anatomyData"])
    template_data["representation"] = representation.name
    template_data["version"] = instance.data["version"]
    # template_data["hierarchy"] = instance.data["hierarchy"]

    # add colorspace data to template data
    if representation.contains_trait(ColorManaged):
        colorspace_data: ColorManaged = representation.get_trait(
            ColorManaged)

        template_data["colorspace"] = {
            "colorspace": colorspace_data.color_space,
            "config": colorspace_data.config
        }

    # add explicit list of traits properties to template data
    # there must be some better way to handle this.

    with contextlib.suppress(MissingTraitError):
        # resolution from PixelBased trait
        template_data["resolution_width"] = representation.get_trait(
            PixelBased).display_window_width
        template_data["resolution_height"] = representation.get_trait(
            PixelBased).display_window_height

    with contextlib.suppress(MissingTraitError):
        # get fps from representation traits
        template_data["fps"] = representation.get_trait(
            FrameRanged).frames_per_second

    with contextlib.suppress(MissingTraitError):
        file_path = representation.get_trait(FileLocation).file_path
        if isinstance(file_path, str):
            file_path = Path(file_path)
        template_data["ext"] = file_path.suffix.lstrip(".")
    if not template_data.get("ext"):
        with contextlib.suppress(MissingTraitError):
            # Try FileLocations trait if FileLocation ext is empty
            file_locations_trait = representation.get_trait(
                FileLocations)
            if file_locations_trait.file_paths:
                first_file_loc = file_locations_trait.file_paths[0]
                file_path = first_file_loc.file_path
                if isinstance(file_path, str):
                    file_path = Path(file_path)
                template_data["ext"] = (file_path.suffix.lstrip("."))
        # Note: handle "output" and "originalBasename"
    return template_data

get_transfers_from_bundle(representation, template_item, transfers)

Get transfers from Bundle trait.

This will be called recursively for each sub-representation in the bundle that is a Bundle itself.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
template_item IntegrationTemplateItem

Template item.

required
transfers list

List of transfers.

required
Mutates

transfers (list): List of transfers. template_item (TemplateItem): Template item.

Source code in client/ayon_core/pipeline/traits/publishing.py
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
def get_transfers_from_bundle(
        representation: Representation,
        template_item: IntegrationTemplateItem,
        transfers: list[TransferItem]
) -> None:
    """Get transfers from Bundle trait.

    This will be called recursively for each sub-representation in the
    bundle that is a Bundle itself.

    Args:
        representation (Representation): Representation to process.
        template_item (IntegrationTemplateItem): Template item.
        transfers (list): List of transfers.

    Mutates:
        transfers (list): List of transfers.
        template_item (TemplateItem): Template item.

    """
    bundle: Bundle = representation.get_trait(Bundle)
    for idx, sub_representation_traits in enumerate(bundle.items):
        sub_representation = Representation(
            name=f"{representation.name}_{idx}",
            traits=sub_representation_traits)
        # sub presentation transient:
        sub_representation.add_trait(Transient())
        if sub_representation.contains_trait(FileLocations):
            get_transfers_from_file_locations(
                sub_representation, template_item, transfers
            )
        elif sub_representation.contains_trait(FileLocation):
            get_transfers_from_file_location(
                sub_representation, template_item, transfers
            )
        elif sub_representation.contains_trait(Bundle):
            get_transfers_from_bundle(
                sub_representation, template_item, transfers
            )

get_transfers_from_file_location(representation, template_item, transfers)

Get transfers from FileLocation trait.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
template_item IntegrationTemplateItem

Template item.

required
transfers list

List of transfers.

required
Mutates

transfers (list): List of transfers. template_item (TemplateItem): Template item.

Source code in client/ayon_core/pipeline/traits/publishing.py
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
def get_transfers_from_file_location(
        representation: Representation,
        template_item: IntegrationTemplateItem,
        transfers: list[TransferItem]
) -> None:
    """Get transfers from FileLocation trait.

    Args:
        representation (Representation): Representation to process.
        template_item (IntegrationTemplateItem): Template item.
        transfers (list): List of transfers.

    Mutates:
        transfers (list): List of transfers.
        template_item (TemplateItem): Template item.

    """
    path_template_object: "AnatomyStringTemplate" = (
        template_item.template_object["path"]
    )
    file_path = representation.get_trait(FileLocation).file_path
    if isinstance(file_path, str):
        file_path = Path(file_path)

    template_item.template_data["ext"] = (
        file_path.suffix.lstrip(".")
    )
    template_item.template_data.pop("frame", None)
    with contextlib.suppress(MissingTraitError):
        udim = representation.get_trait(UDIM)
        template_item.template_data["udim"] = udim.udim[0]

    template_filled = path_template_object.format_strict(
        template_item.template_data
    )

    # add used values to the template data
    used_values: dict = template_filled.used_values
    template_item.template_data.update(used_values)

    file_loc: FileLocation = representation.get_trait(FileLocation)
    file_path = file_loc.file_path
    if isinstance(file_path, str):
        file_path = Path(file_path)

    transfers.append(
        TransferItem(
            source=file_path,
            destination=Path(template_filled),
            size=file_loc.file_size or TransferItem.get_file_size(
                file_path),
            checksum=file_loc.file_hash or TransferItem.get_file_checksum(
                file_path),
            template=template_item.template_object["path"],
            template_data=template_item.template_data,
            representation=representation,
            related_trait=file_loc
        )
    )
    # add template path and the data to resolve it
    # remove template if already exists
    with contextlib.suppress(ValueError):
        representation.remove_trait(TemplatePath)

    representation.add_trait(TemplatePath(
        template=template_item.template_object["path"],
        data=template_item.template_data
    ))

get_transfers_from_file_locations(representation, template_item, transfers)

Get transfers from FileLocations trait.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
template_item IntegrationTemplateItem

Template item.

required
transfers list

List of transfers.

required
Mutates

transfers (list): List of transfers. template_item (TemplateItem): Template item.

Source code in client/ayon_core/pipeline/traits/publishing.py
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
def get_transfers_from_file_locations(
        representation: Representation,
        template_item: IntegrationTemplateItem,
        transfers: list[TransferItem]) -> None:
    """Get transfers from FileLocations trait.

    Args:
        representation (Representation): Representation to process.
        template_item (IntegrationTemplateItem): Template item.
        transfers (list): List of transfers.

    Mutates:
        transfers (list): List of transfers.
        template_item (TemplateItem): Template item.

    """
    if representation.contains_trait(Sequence):
        get_transfers_from_sequence(
            representation, template_item, transfers
        )

    elif representation.contains_trait(UDIM) and \
            not representation.contains_trait(Sequence):
        # handle UDIM not in sequence
        get_transfers_from_udim(
            representation, template_item, transfers
        )

    else:
        get_transfers_from_file_locations_common_root(
            representation, template_item, transfers
        )

get_transfers_from_file_locations_common_root(representation, template_item, transfers)

Get transfers from FileLocations trait preserving relative hierarchy.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
template_item IntegrationTemplateItem

Template item.

required
transfers list

List of transfers.

required
Mutates

transfers (list): List of transfers. template_item (TemplateItem): Template item.

Source code in client/ayon_core/pipeline/traits/publishing.py
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
def get_transfers_from_file_locations_common_root(
        representation: Representation,
        template_item: IntegrationTemplateItem,
        transfers: list[TransferItem]
) -> None:
    """Get transfers from FileLocations trait preserving relative hierarchy.

    Args:
        representation (Representation): Representation to process.
        template_item (IntegrationTemplateItem): Template item.
        transfers (list): List of transfers.

    Mutates:
        transfers (list): List of transfers.
        template_item (TemplateItem): Template item.

    """
    file_locations_trait = representation.get_trait(FileLocations)
    if not file_locations_trait.file_paths:
        return

    try:
        common_root = file_locations_trait.get_common_root()
    except ValueError as exc:
        raise PublishError(
            f"Could not determine common root for representation "
            f"'{representation.name}'"
        ) from exc

    path_template_object = template_item.template_object["path"]
    template_filled = path_template_object.format_strict(
        template_item.template_data
    )

    used_values = template_filled.used_values
    template_item.template_data.update(used_values)

    destination_root = Path(template_filled)
    if destination_root.suffix:
        destination_root = destination_root.parent

    for file_loc in file_locations_trait.file_paths:
        source = file_loc.file_path
        if isinstance(source, str):
            source = Path(source)

        relative_path = source.relative_to(common_root)
        destination = destination_root / relative_path

        transfers.append(
            TransferItem(
                source=source,
                destination=destination,
                size=file_loc.file_size or TransferItem.get_file_size(source),
                checksum=(
                    file_loc.file_hash
                    or TransferItem.get_file_checksum(source)
                ),
                template=template_item.template_object["path"],
                template_data=template_item.template_data,
                representation=representation,
                related_trait=file_loc
            )
        )

    if not representation.contains_trait(TemplatePath):
        representation.add_trait(
            TemplatePath(
                template=template_item.template_object["path"],
                data=template_item.template_data,
            )
        )

get_transfers_from_representations(instance, template, representations)

Get transfers from representations.

This method will go through all representations and prepare transfers based on the traits they contain. First it will validate the representation, and then it will prepare template data for the representation. It specifically handles FileLocations, FileLocation, Bundle, Sequence and UDIM traits.

Parameters:

Name Type Description Default
instance Instance

Instance to process.

required
template AnatomyStringTemplate

Template to use for formatting destination paths.

required
representations list[Representation]

List of representations.

required

Returns:

Type Description
list[TransferItem]

list[TransferItem]: List of transfers.

Raises:

Type Description
PublishError

If representation is invalid.

Source code in client/ayon_core/pipeline/traits/publishing.py
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
def get_transfers_from_representations(
        instance: pyblish.api.Instance,
        template: AnatomyTemplateItem,
        representations: list[Representation]
) -> list[TransferItem]:
    """Get transfers from representations.

    This method will go through all representations and prepare transfers
    based on the traits they contain. First it will validate the
    representation, and then it will prepare template data for the
    representation. It specifically handles FileLocations, FileLocation,
    Bundle, Sequence and UDIM traits.

    Args:
        instance (pyblish.api.Instance): Instance to process.
        template (AnatomyStringTemplate): Template to use for formatting
            destination paths.
        representations (list[Representation]): List of representations.

    Returns:
        list[TransferItem]: List of transfers.

    Raises:
        PublishError: If representation is invalid.

    """
    instance_template_data: dict[str, str] = {}
    transfers: list[TransferItem] = []
    # prepare template and data to format it
    for representation in representations:

        # validate representation first, this will go through all traits
        # and check if they are valid
        try:
            representation.validate()
        except TraitValidationError as e:
            msg = f"Representation '{representation.name}' is invalid: {e}"
            raise PublishError(msg) from e

        template_data = get_template_data_from_representation(
            representation, instance)
        # add instance based template data

        template_data.update(instance_template_data)

        # treat Variant as `output` in template data
        with contextlib.suppress(MissingTraitError):
            template_data["output"] = (
                representation.get_trait(Variant).variant
            )

        template_item = IntegrationTemplateItem(
            anatomy=instance.context.data["anatomy"],
            template_data=copy.deepcopy(template_data),
            template_object=template
        )

        if representation.contains_trait(FileLocations):
            # If representation has FileLocations trait (list of files)
            # it can be a Sequence, UDIM tile set, or a group of related
            # files that share a common root and preserve their hierarchy.
            # Note: we do not support yet frame sequence of multiple UDIM
            # tiles in the same representation.
            get_transfers_from_file_locations(
                representation, template_item, transfers
            )
        elif representation.contains_trait(FileLocation):
            # This is just a single file representation
            get_transfers_from_file_location(
                representation, template_item, transfers
            )

        elif representation.contains_trait(Bundle):
            # Bundle groups multiple "sub-representations" together.
            # It has a list of lists with traits, some might be
            # FileLocations,but some might be "file-less" representations
            # or even other bundles.
            get_transfers_from_bundle(
                representation, template_item, transfers
            )
    return transfers

get_transfers_from_sequence(representation, template_item, transfers)

Get transfers from Sequence trait.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
template_item IntegrationTemplateItem

Template item.

required
transfers list

List of transfers.

required
Mutates

transfers (list): List of transfers. template_item (TemplateItem): Template item.

Source code in client/ayon_core/pipeline/traits/publishing.py
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
def get_transfers_from_sequence(
        representation: Representation,
        template_item: IntegrationTemplateItem,
        transfers: list[TransferItem]
) -> None:
    """Get transfers from Sequence trait.

    Args:
        representation (Representation): Representation to process.
        template_item (IntegrationTemplateItem): Template item.
        transfers (list): List of transfers.

    Mutates:
        transfers (list): List of transfers.
        template_item (TemplateItem): Template item.

    """
    sequence: Sequence = representation.get_trait(Sequence)
    path_template_object: AnatomyStringTemplate = (
        template_item.template_object["path"]
    )
    frames: list[int] = sequence.get_frame_list(
        representation.get_trait(FileLocations),
        regex=sequence.frame_regex)

    # Go through all frames in the sequence and
    # find their corresponding file locations, then
    # format their template and add them to transfers.
    for frame in frames:
        file_loc: FileLocation = representation.get_trait(
            FileLocations).get_file_location_for_frame(
            frame, sequence)

        template_item.template_data["frame"] = frame
        template_item.template_data["ext"] = (
            file_loc.file_path.suffix.lstrip("."))
        template_filled = path_template_object.format_strict(
                template_item.template_data
        )

        # add used values to the template data
        used_values: dict = template_filled.used_values
        template_item.template_data.update(used_values)

        transfers.append(
            TransferItem(
                source=file_loc.file_path,
                destination=Path(template_filled),
                size=file_loc.file_size or TransferItem.get_file_size(
                    file_loc.file_path),
                checksum=file_loc.file_hash or TransferItem.get_file_checksum(
                    file_loc.file_path),
                template=template_item.template_object["path"],
                template_data=template_item.template_data,
                representation=representation,
                related_trait=file_loc
            )
        )

    # add template path and the data to resolve it
    if not representation.contains_trait(TemplatePath):
        representation.add_trait(TemplatePath(
            template=template_item.template_object["path"],
            data=template_item.template_data
        ))

get_transfers_from_udim(representation, template_item, transfers)

Get transfers from UDIM trait.

Parameters:

Name Type Description Default
representation Representation

Representation to process.

required
template_item IntegrationTemplateItem

Template item.

required
transfers list

List of transfers.

required
Mutates

transfers (list): List of transfers. template_item (TemplateItem): Template item.

Source code in client/ayon_core/pipeline/traits/publishing.py
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def get_transfers_from_udim(
        representation: Representation,
        template_item: IntegrationTemplateItem,
        transfers: list[TransferItem]
) -> None:
    """Get transfers from UDIM trait.

    Args:
        representation (Representation): Representation to process.
        template_item (IntegrationTemplateItem): Template item.
        transfers (list): List of transfers.

    Mutates:
        transfers (list): List of transfers.
        template_item (TemplateItem): Template item.

    """
    udim: UDIM = representation.get_trait(UDIM)
    path_template_object: "AnatomyStringTemplate" = (
        template_item.template_object["path"]
    )
    for file_loc in representation.get_trait(
            FileLocations).file_paths:
        template_item.template_data["udim"] = (
            udim.get_udim_from_file_location(file_loc)
        )

        template_filled = path_template_object.format_strict(
            template_item.template_data
        )

        # add used values to the template data
        used_values: dict = template_filled.used_values
        template_item.template_data.update(used_values)

        transfers.append(
            TransferItem(
                source=file_loc.file_path,
                destination=Path(template_filled),
                size=file_loc.file_size or TransferItem.get_file_size(
                    file_loc.file_path),
                checksum=file_loc.file_hash or TransferItem.get_file_checksum(
                    file_loc.file_path),
                template=template_item.template_object["path"],
                template_data=template_item.template_data,
                representation=representation,
                related_trait=file_loc
            )
        )
    # add template path and the data to resolve it
    representation.add_trait(TemplatePath(
        template=template_item.template_object["path"],
        data=template_item.template_data
    ))

replace_paths_in_representation(representation, transfers)

Replace paths in representation traits based on transfers.

This is used to update the traits with the new file paths after the transfer is done.

Parameters:

Name Type Description Default
representation Representation

Representation to update.

required
transfers list[TransferItem]

List of transfer items.

required
Mutates

representation (Representation): Representation with updated paths.

Source code in client/ayon_core/pipeline/traits/publishing.py
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
def replace_paths_in_representation(
        representation: Representation,
        transfers: list[TransferItem]
) -> None:
    """Replace paths in representation traits based on transfers.

    This is used to update the traits with the new file paths after the
    transfer is done.

    Args:
        representation (Representation): Representation to update.
        transfers (list[TransferItem]): List of transfer items.

    Mutates:
        representation (Representation): Representation with updated paths.

    """
    for transfer in transfers:
        if transfer.representation == representation:
            if representation.contains_trait(FileLocation):
                f_trait: FileLocation = representation.get_trait(
                    FileLocation)
                path_in_trait = f_trait.file_path
                if path_in_trait == transfer.source:
                    f_trait.file_path = transfer.destination
            if representation.contains_trait(FileLocations):
                fl_trait: FileLocations = representation.get_trait(
                    FileLocations)
                for idx, file_loc in enumerate(fl_trait.file_paths):
                    path_in_trait = file_loc.file_path
                    if path_in_trait == transfer.source:
                        fl_trait.file_paths[idx].file_path = (
                            transfer.destination
                        )