Skip to content

validate_workfile_project_name

ValidateWorkfileProjectName

Bases: ContextPlugin

Validate project name stored in workfile metadata.

It is not possible to publish from different project than is set in environment variable "AYON_PROJECT_NAME".

Source code in client/ayon_tvpaint/plugins/publish/validate_workfile_project_name.py
 5
 6
 7
 8
 9
10
11
12
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
class ValidateWorkfileProjectName(pyblish.api.ContextPlugin):
    """Validate project name stored in workfile metadata.

    It is not possible to publish from different project than is set in
    environment variable "AYON_PROJECT_NAME".
    """

    label = "Validate Workfile Project Name"
    order = pyblish.api.ValidatorOrder

    settings_category = "tvpaint"

    def process(self, context):
        workfile_context = context.data.get("workfile_context")
        # If workfile context is missing than project is matching to
        #   global project
        if not workfile_context:
            self.log.info(
                "Workfile context (\"workfile_context\") is not filled."
            )
            return

        workfile_project_name = workfile_context["project_name"]
        env_project_name = context.data["projectName"]
        if workfile_project_name == env_project_name:
            self.log.info((
                "Both workfile project and environment project are same. {}"
            ).format(env_project_name))
            return

        # Raise an error
        raise PublishXmlValidationError(
            self,
            (
                # Short message
                "Workfile from different Project ({})."
                # Description what's wrong
                " It is not possible to publish when TVPaint was launched in"
                "context of different project. Current context project is"
                " \"{}\". Launch TVPaint in context of project \"{}\""
                " and then publish."
            ).format(
                workfile_project_name,
                env_project_name,
                workfile_project_name,
            ),
            formatting_data={
                "workfile_project_name": workfile_project_name,
                "expected_project_name": env_project_name
            }
        )