Add logger.py to makefile
[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 logger = logging.getLogger("nitsi")
8 logger.setLevel(logging.DEBUG)
9 # create console handler with a higher log level
10 ch = logging.StreamHandler()
11 ch.setLevel(logging.DEBUG)
12
13 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
14 ch.setFormatter(formatter)
15 # add the handlers to the logger
16 logger.addHandler(ch)
17
18 if __name__ == "__main__":
19     import argparse
20
21     parser = argparse.ArgumentParser()
22
23     parser.add_argument("-d", "--directory", dest="dir")
24
25     parser.add_argument("-v" "--version", help="Display version and exit",
26                     action="store_true", dest="version")
27
28     args = parser.parse_args()
29
30     if args.version:
31         logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
32     else:
33         log_dir = init_logging(args.dir)
34         # We now going to log everything to log_dir/genaral.log
35         fh = logging.FileHandler("{}/general.log".format(log_dir))
36         fh.setLevel(logging.DEBUG)
37         logger.addHandler(fh)
38         logger.debug("We now logging everything to {}/general.log".format(log_dir))
39
40         currenttest = test(args.dir, log_dir)
41         currenttest.read_settings()
42         currenttest.virtual_environ_setup()
43         currenttest.load_recipe()
44         try:
45             currenttest.virtual_environ_start()
46             currenttest.run_recipe()
47         except BaseException as e:
48             print(e)
49         finally:
50             currenttest.virtual_environ_stop()