-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo
executable file
·81 lines (58 loc) · 1.92 KB
/
demo
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
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
#!/usr/bin/env python3
import os
import sys
def docker_exec(service, index, cmd):
os.system(f"docker compose exec --index {index} {service} bash -c '{cmd}'")
def server_exec(cmd):
docker_exec("server", 1, cmd)
def server_django_exec(code):
server_exec(f"poetry run ./manage.py shell -c '\\''{code}'\\''")
def server_init():
# TODO: Consider removing existing data first.
server_django_exec("""
from core.models.commissioner import Commissioner
from core.models.data_point import DataPoint
from core.models.survey import Query, Survey
c = Commissioner.objects.create(name="KDE")
s = Survey.objects.create(name="Test", commissioner=c, group_size=4,
group_count=1)
dp = DataPoint.objects.create(name="Test", key="test", type=1)
Query.objects.create(survey=s, data_point=dp, cohorts=["1", "2", "3"])
""")
pass
def client_exec(index, cmd):
docker_exec("client", index, cmd)
def client_init():
# TODO: Consider removing any existing data points first, perhaps removing
# the database file while the daemon is running would work.
values = {
"1": "1",
"2": "2",
"3": "2",
"4": "3"
}
for index, value in values.items():
client_exec(index,
". ./dbus-env.sh && dbus-send --type=method_call "
"--dest=org.privact.client / "
"org.privact.client.Data.submit_data_point "
f"string:test string:{value}")
def init_all():
server_init()
client_init()
commands = {
"server-init": server_init,
"client-init": client_init,
"init-all": init_all
}
def show_usage():
print(f"Usage: {sys.argv[0]} {'|'.join(commands.keys())}")
if __name__ == "__main__":
if len(sys.argv) < 2:
show_usage()
sys.exit(1)
command = sys.argv[1]
if command not in commands:
show_usage()
sys.exit(2)
commands[command]()