-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
166 lines (143 loc) · 4.7 KB
/
setup.py
File metadata and controls
166 lines (143 loc) · 4.7 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import argparse
import tomllib
from time import timezone
def int_or_str(data):
try:
return int(data)
except ValueError:
return str(data)
def add_argument(argument, parser, ARGS):
match argument:
case "help":
parser.add_argument(
"--help",
action="help",
default=argparse.SUPPRESS,
help="Show all script startup parameters and exit"
)
case "SILENT":
parser.add_argument(
"-s", "--silent",
help="Do not open the created image or plot",
action="store_const",
const=not ARGS["SILENT"],
default=ARGS["SILENT"],
dest="SILENT"
)
case "IMAGE":
parser.add_argument(
"-i", "--image",
help="Do not save plot image",
action="store_const",
const=not ARGS["IMAGE"],
default=ARGS["IMAGE"],
dest="IMAGE"
)
case "CUMULATIVE":
parser.add_argument(
"-c",
help="Display staticics for all time or by week",
action="store_const",
const=not ARGS["CUMULATIVE"],
default=ARGS["CUMULATIVE"],
dest="CUMULATIVE",
)
case "HIDE_VOID":
parser.add_argument(
"-v",
help="Hide void on the density or average plot",
action="store_const",
const=not ARGS["HIDE_VOID"],
default=ARGS["HIDE_VOID"],
dest="HIDE_VOID"
)
case "LABEL_TRESHOLD":
parser.add_argument(
"-t",
help="Threshold for displaying the stage time on the main plot",
default=ARGS["LABEL_TRESHOLD"],
type=float,
dest="LABEL_TRESHOLD"
)
case "AV_LABEL_TRESHOLD":
parser.add_argument(
"-avt",
help="Threshold for displaying the stage time on the average plot",
default=ARGS["AV_LABEL_TRESHOLD"],
type=float,
dest="AV_LABEL_TRESHOLD"
)
case "SHOW_LEGEND":
parser.add_argument(
"-l",
help="Displaying the plot legend",
action="store_const",
const=not ARGS["SHOW_LEGEND"],
default=ARGS["SHOW_LEGEND"],
dest="SHOW_LEGEND"
)
case "LEGEND_COLUMNS":
parser.add_argument(
"-lc",
help="Number of legend columns",
dest="LEGEND_COLUMNS",
type=int,
default=ARGS["LEGEND_COLUMNS"],
)
case "START_RADIUS":
parser.add_argument(
"-r",
help="Initial radius of the circle",
dest="START_RADIUS",
type=float,
default=ARGS["START_RADIUS"],
)
case "IMAGE_SIDE":
parser.add_argument(
"-h",
help="Image side size (width and height)",
dest="IMAGE_SIDE",
type=int_or_str,
default=ARGS["IMAGE_SIDE"],
)
case "IMAGE_SCALE":
parser.add_argument(
"-x",
help="Image size multiplier",
dest="IMAGE_SCALE",
type=int,
default=ARGS["IMAGE_SCALE"],
)
case "PLOT_WIDTH":
parser.add_argument(
"-w",
help="Plot width",
dest="PLOT_WIDTH",
type=float,
default=ARGS["PLOT_WIDTH"],
)
case "PLOT_HEIGHT":
parser.add_argument(
"-h",
help="Plot height",
dest="PLOT_HEIGHT",
type=float,
default=ARGS["PLOT_HEIGHT"],
)
def setup(script_name):
settings = tomllib.load(open("settings.toml", "rb"))
# Get settings
ACTIVITIES = settings["activities"]
ARGS = settings["global"] | settings[script_name]
# Parse arguments
parser = argparse.ArgumentParser(add_help=False)
add_argument("help", parser, ARGS)
for argument in ARGS:
add_argument(argument, parser, ARGS)
parsed_args = dict(parser.parse_args()._get_kwargs())
for arg in parsed_args:
ARGS[arg] = parsed_args[arg]
# Setup auto settings
if "UTC_OFFSET" in ARGS and ARGS["UTC_OFFSET"] == "auto":
ARGS["UTC_OFFSET"] = -timezone
return ARGS, ACTIVITIES