f8f79455785cb84958c425c7b554e4781639f19f
[nitsi.git] / nitsi.in
1 #!/usr/bin/python3
2
3 from nitsi.test import test
4 from nitsi.logger import init_logging
5 import logging
6
7 from nitsi.recipe import RecipeExeption
8
9 from nitsi.test import TestException
10
11 logger = logging.getLogger("nitsi")
12 logger.setLevel(logging.DEBUG)
13 # create console handler with a higher log level
14 ch = logging.StreamHandler()
15 ch.setLevel(logging.DEBUG)
16
17 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
18 ch.setFormatter(formatter)
19 # add the handlers to the logger
20 logger.addHandler(ch)
21
22 if __name__ == "__main__":
23     import argparse
24
25     parser = argparse.ArgumentParser()
26
27     parser.add_argument("-d", "--directory", dest="dir")
28
29     parser.add_argument("-v", "--version", help="Display version and exit",
30                     action="store_true", dest="version")
31
32     args = parser.parse_args()
33
34     if args.version:
35         logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
36     else:
37         log_dir = init_logging(args.dir)
38         # We now going to log everything to log_dir/genaral.log
39         fh = logging.FileHandler("{}/general.log".format(log_dir))
40         fh.setLevel(logging.DEBUG)
41         logger.addHandler(fh)
42         logger.debug("We now logging everything to {}/general.log".format(log_dir))
43         try:
44             currenttest = test(args.dir, log_dir)
45             currenttest.read_settings()
46             currenttest.virtual_environ_setup()
47             currenttest.load_recipe()
48         except RecipeExeption as e:
49             logger.exception(e)
50             exit(2)
51
52         try:
53             currenttest.virtual_environ_start()
54             currenttest.run_recipe()
55         except TestException as e:
56             logger.exception(e)
57             exit(1)
58         except BaseException as e:
59             logger.exception(e)
60             exit(3)
61         finally:
62             currenttest.virtual_environ_stop()
63
64         exit(0)