forked from dslab-epfl/bugbase
/
configure.py
executable file
·77 lines (60 loc) · 2.33 KB
/
configure.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
This is an automated way to configure the working environment when working with bugbase
"""
from argparse import ArgumentParser
import logging
from lib import hooks, logger, exceptions
from lib.parsers import arguments
from lib.configuration.coredump import setup_coredumps
from lib.configuration.dependencies import install
from lib.configuration import update
__author__ = "Benjamin Schubert, benjamin.schubert@epfl.ch"
def parse_args() -> tuple:
"""
Creates a parser for command lines attributes and parses them
:return: True if the program is to run interactively
"""
parser = ArgumentParser(
description="An automated configure script for Bugbase usage", parents=[arguments.get_verbosity_parser()]
)
parser.add_argument(
"--default", help="use default values and don't ask anything (non-interactive mode)",
action="store_false", dest="interactive"
)
parser.add_argument(
"-f", "--force", help="Force reinstall of all programs if used",
action="store_true", dest="force"
)
args = parser.parse_args()
logging.getLogger().setLevel(args.logging_level)
return args.interactive, args.force
def main(__interactive__: bool, force: bool) -> None:
"""
Updates the configuration if the program is to be run interactively,
then install necessary items
:param __interactive__: if the config has to be updated
:param force: True to force reinstall of the programs, else will only install the ones that are not installed
"""
if __interactive__ and update.update():
logging.error("An error occurred, could not finish configuration")
return 1
try:
install(force)
setup_coredumps()
hooks.load_plugins()
hooks.configure(force)
except (exceptions.InstallationErrorException, exceptions.DistributionNotSupportedException) as exception:
logging.error(exception)
logging.error("Configure script failed. Please rerun it after correcting errors. You can add --default in order"
" to skip questions")
return 1
finally:
logging.verbose("Cleaning environment")
if __name__ == "__main__":
try:
logger.setup_logging()
exit(main(*parse_args()))
except KeyboardInterrupt:
exit(1)