Skip to content

validate_scene_set_workspace

ValidateSceneSetWorkspace

Bases: MayaContextPlugin

Validate the scene is inside the currently set Maya workspace

Source code in client/ayon_maya/plugins/publish/validate_scene_set_workspace.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class ValidateSceneSetWorkspace(plugin.MayaContextPlugin):
    """Validate the scene is inside the currently set Maya workspace"""

    order = ValidatePipelineOrder
    label = 'Maya Workspace Set'

    def process(self, context):

        scene_name = cmds.file(query=True, sceneName=True)
        if not scene_name:
            raise PublishValidationError(
                "Scene hasn't been saved. Workspace can't be validated.")

        root_dir = cmds.workspace(query=True, rootDirectory=True)

        if not is_subdir(scene_name, root_dir):
            raise PublishValidationError(
                "Maya workspace is not set correctly.\n\n"
                f"Current workfile `{scene_name}` is not inside the "
                f"current Maya project root directory `{root_dir}`.\n\n"
                "Please use Workfile app to re-save."
            )

is_subdir(path, root_dir)

Returns whether path is a subdirectory (or file) within root_dir

Source code in client/ayon_maya/plugins/publish/validate_scene_set_workspace.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def is_subdir(path, root_dir):
    """ Returns whether path is a subdirectory (or file) within root_dir """
    path = os.path.realpath(path)
    root_dir = os.path.realpath(root_dir)

    # If not on same drive
    if os.path.splitdrive(path)[0].lower() != os.path.splitdrive(root_dir)[0].lower():  # noqa: E501
        return False

    # Get 'relative path' (can contain ../ which means going up)
    relative = os.path.relpath(path, root_dir)

    # Check if the path starts by going up, if so it's not a subdirectory. :)
    if relative.startswith(os.pardir) or relative == os.curdir:
        return False
    else:
        return True