~dricottone/fiddler-231027

ref: 6a48adeee0de7a0710b0edbf1ec61e8f929ac201 fiddler-231027/vote/__main__.py -rw-r--r-- 1.2 KiB
6a48adeeDominic Ricottone Initial commit 11 months ago
                                                                                
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
#!/usr/bin/env python

VERSION=(1,0,0,)

import sys

from . import cli
from . import vote

def main():
    _self = sys.argv[0]
    _config, _positionals = cli.main(sys.argv[1:])

    if "version" in _config.keys():
        sys.stderr.write(f"{_self}: {'.'.join(str(v) for v in VERSION)}\n")
        sys.exit(0)
    elif "help" in _config.keys():
        sys.stderr.write(f"Usage: {_self} [OPTIONS]\n")
        sys.stderr.write(f"Options:\n")
        sys.stderr.write(f"  -c=N, --candidates=N       number of candidates [Default: 3]\n")
        sys.stderr.write(f"  -h, -x, --help             print this message and exit\n")
        sys.stderr.write(f"  -r=N, --representatives=N  number of voting representatives [Default: 221]\n")
        sys.stderr.write(f"  -t=N, --trials=N           number of trials to run [Default: 1]\n")
        sys.stderr.write(f"  -v, -V, --version          print version and exit\n")
        sys.exit(0)

    _candidates = int(_config.get("candidates", 3))
    _representatives = int(_config.get("representatives", 221))
    _trials = int(_config.get("trials", 3))
    if _trials == 1:
        vote.run1(_candidates, _representatives)
    else:
        vote.runmany(_candidates, _representatives, _trials)

if __name__ == '__main__':
    main()