Add --version command
[nitsi.git] / nitsi.in
1 #!/usr/bin/python3
2
3 from nitsi.test import test
4 import logging
5
6 logger = logging.getLogger("nitsi")
7 logger.setLevel(logging.DEBUG)
8 # create file handler which logs even debug messages
9 fh = logging.FileHandler('nitsi.log')
10 fh.setLevel(logging.DEBUG)
11 # create console handler with a higher log level
12 ch = logging.StreamHandler()
13 ch.setLevel(logging.DEBUG)
14
15 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
16 fh.setFormatter(formatter)
17 ch.setFormatter(formatter)
18 # add the handlers to the logger
19 logger.addHandler(fh)
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         currenttest = test(args.dir)
38         currenttest.read_settings()
39         currenttest.virtual_environ_setup()
40         currenttest.load_recipe()
41         try:
42             currenttest.virtual_environ_start()
43             currenttest.run_recipe()
44         except BaseException as e:
45             print(e)
46         finally:
47             currenttest.virtual_environ_stop()