Makefile: Ship nitsi.in in tarball
[people/ms/nitsi.git] / nitsi.in
1 #!/usr/bin/python3
2
3 import argparse
4 import logging
5
6 from nitsi.logger import init_logging
7 from nitsi.recipe import RecipeExeption
8 from nitsi.test import TestException, test
9
10 logger = logging.getLogger("nitsi")
11 logger.setLevel(logging.DEBUG)
12 # create console handler with a higher log level
13 ch = logging.StreamHandler()
14 ch.setLevel(logging.DEBUG)
15
16 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
17 ch.setFormatter(formatter)
18 # add the handlers to the logger
19 logger.addHandler(ch)
20
21 def main():
22 parser = argparse.ArgumentParser()
23
24 parser.add_argument("-d", "--directory", dest="dir")
25
26 parser.add_argument("-v", "--version", help="Display version and exit",
27 action="store_true", dest="version")
28
29 args = parser.parse_args()
30
31 # We just log the version and exit
32 if args.version:
33 logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
34 return 0
35
36 # For all other stuff we need logging to a file
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
44 # here we run a test
45 try:
46 currenttest = test(args.dir, log_dir)
47 currenttest.read_settings()
48 currenttest.virtual_environ_setup()
49 currenttest.load_recipe()
50 except RecipeExeption as e:
51 logger.exception(e)
52 return 2
53
54 try:
55 currenttest.virtual_environ_start()
56 currenttest.run_recipe()
57 except TestException as e:
58 logger.exception(e)
59 return 1
60 except BaseException as e:
61 logger.exception(e)
62 return 3
63 finally:
64 currenttest.virtual_environ_stop()
65
66 return 0
67
68 if __name__ == "__main__":
69 return_value = main()
70 logger.debug("Return value of main is: {}".format(return_value))
71 exit(return_value)