Skip to content

action_where_run_ask

ActionWhereIRun

Bases: LocalAction

Show where same user has running AYON instances.

Source code in client/ayon_ftrack/event_handlers_user/action_where_run_ask.py
 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
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
89
90
91
class ActionWhereIRun(LocalAction):
    """Show where same user has running AYON instances."""

    identifier = "ayon.ask.where.i.run"
    show_identifier = "ayon.show.where.i.run"
    label = "AYON Admin"
    variant = "- Where I run"
    description = "Show PC info where user have running AYON"

    def _discover(self, _event):
        return {
            "items": [{
                "label": self.label,
                "variant": self.variant,
                "description": self.description,
                "actionIdentifier": self.discover_identifier,
                "icon": self.icon,
            }]
        }

    def _launch(self, event):
        self.trigger_action(self.show_identifier, event)

    def register(self):
        # Register default action callbacks
        super(ActionWhereIRun, self).register()

        # Add show identifier
        show_subscription = (
            "topic=ftrack.action.launch"
            " and data.actionIdentifier={}"
            " and source.user.username={}"
        ).format(
            self.show_identifier,
            self.session.api_user
        )
        self.session.event_hub.subscribe(
            show_subscription,
            self._show_info
        )

    def _show_info(self, event):
        title = "Where Do I Run?"
        msgs = {}
        all_keys = ["Hostname", "IP", "Username", "System name", "PC name"]
        try:
            host_name = socket.gethostname()
            msgs["Hostname"] = host_name
            msgs["IP"] = get_host_ip() or "N/A"
        except Exception:
            pass

        try:
            system_name, pc_name, *_ = platform.uname()
            msgs["System name"] = system_name
            msgs["PC name"] = pc_name
        except Exception:
            pass

        try:
            msgs["Username"] = getpass.getuser()
        except Exception:
            pass

        for key in all_keys:
            if not msgs.get(key):
                msgs[key] = "-Undefined-"

        items = []
        first = True
        separator = {"type": "label", "value": "---"}
        for key, value in msgs.items():
            if first:
                first = False
            else:
                items.append(separator)
            self.log.debug("{}: {}".format(key, value))

            subtitle = {"type": "label", "value": "<h3>{}</h3>".format(key)}
            items.append(subtitle)
            message = {"type": "label", "value": "<p>{}</p>".format(value)}
            items.append(message)

        self.show_interface(items, title, event=event)