]> git.ipfire.org Git - people/ms/nitsi.git/blame - nitsi.in
Fix argument parsing of '--version'
[people/ms/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
61b44c10
JS
7from nitsi.recipe import RecipeExeption
8
9from nitsi.test import TestException
10
1ed8ca9f
JS
11logger = logging.getLogger("nitsi")
12logger.setLevel(logging.DEBUG)
1ed8ca9f
JS
13# create console handler with a higher log level
14ch = logging.StreamHandler()
15ch.setLevel(logging.DEBUG)
16
17formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
1ed8ca9f
JS
18ch.setFormatter(formatter)
19# add the handlers to the logger
1ed8ca9f 20logger.addHandler(ch)
f72f2f70
JS
21
22if __name__ == "__main__":
23 import argparse
24
25 parser = argparse.ArgumentParser()
26
27 parser.add_argument("-d", "--directory", dest="dir")
28
75b554ca 29 parser.add_argument("-v", "--version", help="Display version and exit",
4cba2549
JS
30 action="store_true", dest="version")
31
f72f2f70
JS
32 args = parser.parse_args()
33
4cba2549
JS
34 if args.version:
35 logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
36 else:
d7036f7b
JS
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))
61b44c10
JS
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)
d7036f7b 51
4cba2549
JS
52 try:
53 currenttest.virtual_environ_start()
54 currenttest.run_recipe()
61b44c10
JS
55 except TestException as e:
56 logger.exception(e)
57 exit(1)
4cba2549 58 except BaseException as e:
61b44c10
JS
59 logger.exception(e)
60 exit(3)
4cba2549 61 finally:
61b44c10
JS
62 currenttest.virtual_environ_stop()
63
64 exit(0)