Skip to content

pre_launch_args

PhotoshopPrelaunchHook

Bases: PreLaunchHook

Launch arguments preparation.

Hook add python executable and script path to Photoshop implementation before Photoshop executable and add last workfile path to launch arguments.

Existence of last workfile is checked. If workfile does not exists tries to copy templated workfile from predefined path.

Source code in client/ayon_photoshop/hooks/pre_launch_args.py
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
class PhotoshopPrelaunchHook(PreLaunchHook):
    """Launch arguments preparation.

    Hook add python executable and script path to Photoshop implementation
    before Photoshop executable and add last workfile path to launch arguments.

    Existence of last workfile is checked. If workfile does not exists tries
    to copy templated workfile from predefined path.
    """
    app_groups = {"photoshop"}

    order = 20
    launch_types = {LaunchTypes.local}

    def execute(self):
        # Pop executable
        executable_path = self.launch_context.launch_args.pop(0)

        # Pop rest of launch arguments - There should not be other arguments!
        remainders = []
        while self.launch_context.launch_args:
            remainders.append(self.launch_context.launch_args.pop(0))

        script_path = get_launch_script_path()

        new_launch_args = get_ayon_launcher_args(
            "run", script_path, executable_path
        )
        # Add workfile path if exists
        workfile_path = self.data["last_workfile_path"]
        if (
            self.data.get("start_last_workfile")
            and workfile_path
            and os.path.exists(workfile_path)
        ):
            new_launch_args.append(workfile_path)

        # Append as whole list as these arguments should not be separated
        self.launch_context.launch_args.append(new_launch_args)

        if remainders:
            self.launch_context.launch_args.extend(remainders)

        self.launch_context.kwargs = get_launch_kwargs(
            self.launch_context.kwargs
        )

get_launch_kwargs(kwargs)

Explicit setting of kwargs for Popen for Photoshop.

Expected behavior - ayon_console opens window with logs - ayon has stdout/stderr available for capturing

Parameters:

Name Type Description Default
kwargs Union[dict, None]

Current kwargs or None.

required
Source code in client/ayon_photoshop/hooks/pre_launch_args.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
def get_launch_kwargs(kwargs):
    """Explicit setting of kwargs for Popen for Photoshop.

    Expected behavior
    - ayon_console opens window with logs
    - ayon has stdout/stderr available for capturing

    Args:
        kwargs (Union[dict, None]): Current kwargs or None.

    """
    if kwargs is None:
        kwargs = {}

    if platform.system().lower() != "windows":
        return kwargs

    if is_using_ayon_console():
        kwargs.update({
            "creationflags": subprocess.CREATE_NEW_CONSOLE
        })
    else:
        kwargs.update({
            "creationflags": subprocess.CREATE_NO_WINDOW,
            "stdout": subprocess.DEVNULL,
            "stderr": subprocess.DEVNULL
        })
    return kwargs