summaryrefslogtreecommitdiffstats
path: root/nixos/tests/windmill/python3.script
blob: c7b384cf1d70e68ddc34f6860f77cd6237898a04 (plain)
1
2
3
4
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
# WARN; Cannot download dependency modules from internet during sandbox testing!

import os
# import wmill

def main(
    no_default: str,
    #db: postgresql,
    name="my friend",
    age=42,
    obj: dict = {"even": "dicts"},
    l: list = ["or", "lists!"],
    file_: bytes = bytes(0),
):

    print(f"Hello World and a warm welcome especially to {name}")
    print("and its acolytes..", age, obj, l, len(file_))

    # retrieve variables, resources, states using the wmill client
    try:
        secret = wmill.get_variable("f/examples/secret")
    except:
        secret = "No secret yet at f/examples/secret !"
    print(f"The variable at `f/examples/secret`: {secret}")

    try:
        # Get last state of this script execution by the same trigger/user
        last_state = wmill.get_state()
        new_state = {"foo": 42} if last_state is None else last_state
        new_state["foo"] += 1
        wmill.set_state(new_state)
    except:
        new_state = {"foo": 43}

    # fetch context variables
    user = os.environ.get("WM_USERNAME")

    # return value is converted to JSON
    return {"splitted": name.split(), "user": user, "state": new_state}