Skip to content

collect_celaction_cli_kwargs

CollectCelactionCliKwargs

Bases: ContextPlugin

Collects all keyword arguments passed from the terminal

Source code in client/ayon_celaction/plugins/publish/collect_celaction_cli_kwargs.py
 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
56
57
58
59
60
class CollectCelactionCliKwargs(pyblish.api.ContextPlugin):
    """ Collects all keyword arguments passed from the terminal """

    label = "Collect Celaction Cli Kwargs"
    order = pyblish.api.CollectorOrder - 0.1

    def process(self, context):
        args = list(sys.argv[1:])
        self.log.info(str(args))
        missing_kwargs = []
        passing_kwargs = {}
        for key in (
            "chunk",
            "frameStart",
            "frameEnd",
            "resolutionWidth",
            "resolutionHeight",
            "currentFile",
        ):
            arg_key = f"--{key}"
            if arg_key not in args:
                missing_kwargs.append(key)
                continue
            arg_idx = args.index(arg_key)
            args.pop(arg_idx)
            if key != "currentFile":
                value = args.pop(arg_idx)
            else:
                path_parts = []
                while arg_idx < len(args):
                    path_parts.append(args.pop(arg_idx))
                value = " ".join(path_parts).strip('"')

            passing_kwargs[key] = value

        if missing_kwargs:
            self.log.debug("Missing arguments {}".format(
                ", ".join(
                    [f'"{key}"' for key in missing_kwargs]
                )
            ))

        self.log.info("Storing kwargs ...")
        self.log.debug("_ passing_kwargs: {}".format(pformat(passing_kwargs)))

        # set kwargs to context data
        context.set_data("passingKwargs", passing_kwargs)

        # get kwargs onto context data as keys with values
        for k, v in passing_kwargs.items():
            self.log.info(f"Setting `{k}` to instance.data with value: `{v}`")
            if k in ["frameStart", "frameEnd"]:
                context.data[k] = passing_kwargs[k] = int(v)
            else:
                context.data[k] = v