Merge branch 'master' of ssh://git.ipfire.org/pub/git/people/jschlag/nitsi
[nitsi.git] / nitsi.in
CommitLineData
1ed8ca9f 1#!/usr/bin/python3
f72f2f70 2
2fa4467d 3from nitsi.test import test
d7036f7b 4from nitsi.logger import init_logging
1ed8ca9f 5import logging
7741c94d 6import argparse
1ed8ca9f 7
61b44c10
JS
8from nitsi.recipe import RecipeExeption
9
10from nitsi.test import TestException
11
1ed8ca9f
JS
12logger = logging.getLogger("nitsi")
13logger.setLevel(logging.DEBUG)
1ed8ca9f
JS
14# create console handler with a higher log level
15ch = logging.StreamHandler()
16ch.setLevel(logging.DEBUG)
17
18formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
1ed8ca9f
JS
19ch.setFormatter(formatter)
20# add the handlers to the logger
1ed8ca9f 21logger.addHandler(ch)
f72f2f70 22
7741c94d 23def main():
f72f2f70
JS
24 parser = argparse.ArgumentParser()
25
26 parser.add_argument("-d", "--directory", dest="dir")
27
75b554ca 28 parser.add_argument("-v", "--version", help="Display version and exit",
4cba2549
JS
29 action="store_true", dest="version")
30
f72f2f70
JS
31 args = parser.parse_args()
32
7741c94d 33 # We just log the version and exit
4cba2549
JS
34 if args.version:
35 logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
7741c94d
JS
36 return 0
37
38 # For all other stuff we need logging to a file
39 log_dir = init_logging(args.dir)
40 # We now going to log everything to log_dir/genaral.log
41 fh = logging.FileHandler("{}/general.log".format(log_dir))
42 fh.setLevel(logging.DEBUG)
43 logger.addHandler(fh)
44 logger.debug("We now logging everything to {}/general.log".format(log_dir))
d7036f7b 45
7741c94d
JS
46 # here we run a test
47 try:
48 currenttest = test(args.dir, log_dir)
49 currenttest.read_settings()
50 currenttest.virtual_environ_setup()
51 currenttest.load_recipe()
52 except RecipeExeption as e:
53 logger.exception(e)
54 exit(2)
61b44c10 55
7741c94d
JS
56 try:
57 currenttest.virtual_environ_start()
58 currenttest.run_recipe()
59 except TestException as e:
60 logger.exception(e)
61 return 1
62 except BaseException as e:
63 logger.exception(e)
64 return 3
65 finally:
66 currenttest.virtual_environ_stop()
67
68 return 0
69
70if __name__ == "__main__":
71 main()