-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkargs.py
153 lines (122 loc) · 4.87 KB
/
checkargs.py
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
# ***************************************************************************
# * Copyright (c) 2015-2024 by Pierre-Henri WUILLEMIN *
# * {prenom.nom}_at_lip6.fr *
# * *
# * "act" is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program; if not, write to the *
# * Free Software Foundation, Inc., *
# * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
# **************************************************************************
import pickle
from .configuration import cfg
from .invocation import showInvocation
from .modules import check_modules
from .tests import checkAndWriteTests
from .utils import error, notif, critic, setifyString
def parseCommandLine():
a = cfg.parser.parse_args()
return a, a.cmds
def getCurrent() -> dict[str, str]:
current = {}
try:
with open(cfg.configFile, "rb") as fp:
shlv = pickle.load(fp)
except FileNotFoundError:
shlv = {}
for key in cfg.default: # .iterkeys():
current[key] = cfg.default[key]
if key not in cfg.non_persistent and key in shlv:
current[key] = shlv[key]
return current
def setCurrent(current: dict[str, str]):
shlv = {}
for key in current.keys():
if key not in cfg.non_persistent:
shlv[key] = current[key]
with open(cfg.configFile, "wb") as fp:
pickle.dump(shlv, fp)
def checkCurrent(current: dict[str, str], options: dict[str, str], args: list[str]):
# helper
def update(current: dict[str, str], key, val, test):
if test and current[key] != val:
current[key] = val
return test
# end of helper
# fixing options
for opt, value in options.__dict__.items():
if opt == 'cmds': # cmds are not options
continue
if opt not in current:
error(f"Options not known : {opt} in {current.keys()}")
update(current, opt, value, current[opt] != value)
# fixing possible "\" from compiler
current['destination'] = current['destination'].replace('\\', '/')
bT = bA = bM = False
# fixing args
for ar in args:
t = setifyString(ar)
arg = "+".join(t)
if update(current, 'targets', t, t.issubset(cfg.targets)):
if bT:
error(f"Targets overwritten by [{'+'.join(t)}]")
bT = True
continue
if update(current, 'action', arg, arg in cfg.actions):
if bA:
error(f"Action overwritten by [{arg}]")
bA = True
continue
if update(current, 'mode', arg, arg in cfg.modes):
if bM:
error(f"Mode overwritten by [{arg}]")
bM = True
continue
critic(f"arg [{arg}] unknown")
checkConsistency(current)
if not options.noSaveParams:
setCurrent(current)
showInvocation(current)
def checkConsistency(current: dict[str, str]):
has_notif = False
# helper
def check_aGrumTest(option, current):
if current[option]:
prefix = f"Option [{option}] acts only"
if current['targets'] != {'aGrUM'}:
has_notif = True
notif(prefix + " on target [aGrUM].")
if current['action'] != 'test':
critic(f"{prefix} on action [test] (not on [{current['action']}]).")
# end of helper
# test for only one target
if current['action'] == 'test':
if len(current['targets']) > 1:
first = "aGrUM" if "aGrUM" in current['targets'] else list(current['targets'])[
0]
has_notif = True
notif("Action [test] on only one target : selecting [" + first + "]")
current['targets'] = [first]
if current['stats'] and current['oneByOne']:
has_notif = True
notif("Options [stats] and [oneByOne] are mutually exclusive")
# check -t and -m
check_modules(current)
checkAndWriteTests(current)
check_aGrumTest('oneByOne', current)
if current['coverage'] and current['mode'] != "debug":
error("Option [coverage] can only be used with [debug] builds.")
current['coverage'] = False
if current['action'] == 'package':
critic("Action [package] is not implemented yed")
if has_notif:
print("")