forked from ron-rivest/audit-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
113 lines (77 loc) · 3.3 KB
/
cli.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
# cli.py
# Ronald L. Rivest (with Karim Husayn Karimi)
# July 22, 2017
# python3
"""
Command-line parser and dispatch for multi.py
"""
import argparse
import multi
import election_spec
import ids
import audit
import reported
##############################################################################
# Command-line arguments
def parse_args():
parser = argparse.ArgumentParser(description="""multi.py: A Bayesian post-election audit program for an
election with multiple contests and multiple paper ballot
collections.""")
# Mandatory argument: dirname
parser.add_argument("election_dirname", help="""
The name for this election of the subdirectory within the elections root directory.""")
# All others are optional
parser.add_argument("--election_name",
help="Human-readable name of the election.",
default="TestElection")
parser.add_argument("--elections_root",
help=("The directory where the subdirectory for the"
"election is to be found. Defaults to './elections'."),
default="./elections")
parser.add_argument("--set_audit_seed",
help=("Seed for the random number generator used for"
"auditing (arbitrary nonnegative integer)."
"(If omitted, sets from file, else clock.)"))
parser.add_argument("--read_election_spec",
action="store_true",
help="Read and check election spec.")
parser.add_argument("--read_reported",
action="store_true",
help="Read and check reported election data and results.")
parser.add_argument("--make_audit_orders",
action="store_true",
help="Make audit orders files.")
parser.add_argument("--read_audited",
action="store_true",
help="Read and check audited votes.")
parser.add_argument("--audit",
action="store_true",
help="Run audit based on current info.")
parser.add_argument("--pause",
action="store_true",
help="Pause after each audit stage to obtain confirmation before proceedings.")
args = parser.parse_args()
# print("Command line arguments:", args)
return args
def process_args(e, args):
e.election_dirname = ids.filename_safe(args.election_dirname)
e.election_name = args.election_name
ELECTIONS_ROOT = args.elections_root
if args.set_audit_seed != None:
audit.set_audit_seed(e, args.set_audit_seed)
if args.read_election_spec:
print("read_election_spec")
election_spec.read_election_spec(e)
elif args.read_reported:
print("read_reported")
election_spec.read_election_spec(e)
reported.read_reported(e)
elif args.make_audit_orders:
print("make_audit_orders")
audit_orders.compute_audit_orders(e)
elif args.read_audited:
print("read_audited--NO-OP-TBD")
elif args.audit:
election_spec.read_election_spec(e)
reported.read_reported(e)
audit.audit(e, args)