Move tests and virtual environment example into examples subfolder
[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
JS
5import logging
6
7logger = logging.getLogger("nitsi")
8logger.setLevel(logging.DEBUG)
1ed8ca9f
JS
9# create console handler with a higher log level
10ch = logging.StreamHandler()
11ch.setLevel(logging.DEBUG)
12
13formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
1ed8ca9f
JS
14ch.setFormatter(formatter)
15# add the handlers to the logger
1ed8ca9f 16logger.addHandler(ch)
f72f2f70
JS
17
18if __name__ == "__main__":
19 import argparse
20
21 parser = argparse.ArgumentParser()
22
23 parser.add_argument("-d", "--directory", dest="dir")
24
4cba2549
JS
25 parser.add_argument("-v" "--version", help="Display version and exit",
26 action="store_true", dest="version")
27
f72f2f70
JS
28 args = parser.parse_args()
29
4cba2549
JS
30 if args.version:
31 logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
32 else:
d7036f7b
JS
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)
4cba2549
JS
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()