Skip to content

csv_publish

csvpublish(filepath, project_name, folder_path, task_name=None, ignore_validators=False)

Publish CSV file.

Parameters:

Name Type Description Default
filepath str

Path to CSV file.

required
project_name str

Project name.

required
folder_path str

Folder path.

required
task_name Optional[str]

Task name.

None
ignore_validators Optional[bool]

Option to ignore validators.

False
Source code in client/ayon_traypublisher/csv_publish.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
def csvpublish(
    filepath,
    project_name,
    folder_path,
    task_name=None,
    ignore_validators=False
):
    """Publish CSV file.

    Args:
        filepath (str): Path to CSV file.
        project_name (str): Project name.
        folder_path (str): Folder path.
        task_name (Optional[str]): Task name.
        ignore_validators (Optional[bool]): Option to ignore validators.

    """
    os.environ["AYON_PROJECT_NAME"] = project_name

    # initialization of host
    host = TrayPublisherHost()
    install_host(host)

    # form precreate data with field values
    file_field = FileDefItem.from_paths([filepath], False).pop().to_dict()
    precreate_data = {
        "csv_filepath_data": file_field,
    }

    # create context initialization
    create_context = CreateContext(host, headless=True)
    folder_entity = create_context.get_folder_entity(folder_path)

    if not folder_entity:
        ValueError(
            f"Folder path '{folder_path}' doesn't "
            f"exists at project '{project_name}'."
        )

    task_entity = create_context.get_task_entity(
        folder_path,
        task_name,
    )

    if not task_entity:
        ValueError(
            f"Task name '{task_name}' doesn't "
            f"exists at folder '{folder_path}'."
        )

    create_context.create(
        "io.ayon.creators.traypublisher.csv_ingest",
        "Main",
        folder_entity=folder_entity,
        task_entity=task_entity,
        pre_create_data=precreate_data,
    )

    # publishing context initialization
    pyblish_context = pyblish.api.Context()
    pyblish_context.data["create_context"] = create_context

    targets = None
    # redefine targets (skip 'local' to disable validators)
    if ignore_validators:
        targets = ["default", "ingest"]

    # publishing
    pyblish.util.publish(context=pyblish_context, targets=targets)