]> git.ipfire.org Git - nitsi.git/blobdiff - nitsi.in
Move tests and virtual environment example into examples subfolder
[nitsi.git] / nitsi.in
index a87aa0a82d407f9c56dd9b94fbe7157f33522e1b..2090e0dafd7a928d05588114dcca4c64a7f4ff6c 100755 (executable)
--- a/nitsi.in
+++ b/nitsi.in
@@ -1,22 +1,18 @@
 #!/usr/bin/python3
 
 from nitsi.test import test
+from nitsi.logger import init_logging
 import logging
 
 logger = logging.getLogger("nitsi")
 logger.setLevel(logging.DEBUG)
-# create file handler which logs even debug messages
-fh = logging.FileHandler('nitsi.log')
-fh.setLevel(logging.DEBUG)
 # create console handler with a higher log level
 ch = logging.StreamHandler()
 ch.setLevel(logging.DEBUG)
 
 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
-fh.setFormatter(formatter)
 ch.setFormatter(formatter)
 # add the handlers to the logger
-logger.addHandler(fh)
 logger.addHandler(ch)
 
 if __name__ == "__main__":
@@ -26,16 +22,29 @@ if __name__ == "__main__":
 
     parser.add_argument("-d", "--directory", dest="dir")
 
+    parser.add_argument("-v" "--version", help="Display version and exit",
+                    action="store_true", dest="version")
+
     args = parser.parse_args()
 
-    currenttest = test(args.dir)
-    currenttest.read_settings()
-    currenttest.virtual_environ_setup()
-    currenttest.load_recipe()
-    try:
-        currenttest.virtual_environ_start()
-        currenttest.run_recipe()
-    except BaseException as e:
-        print(e)
-    finally:
-        currenttest.virtual_environ_stop()
\ No newline at end of file
+    if args.version:
+        logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
+    else:
+        log_dir = init_logging(args.dir)
+        # We now going to log everything to log_dir/genaral.log
+        fh = logging.FileHandler("{}/general.log".format(log_dir))
+        fh.setLevel(logging.DEBUG)
+        logger.addHandler(fh)
+        logger.debug("We now logging everything to {}/general.log".format(log_dir))
+
+        currenttest = test(args.dir, log_dir)
+        currenttest.read_settings()
+        currenttest.virtual_environ_setup()
+        currenttest.load_recipe()
+        try:
+            currenttest.virtual_environ_start()
+            currenttest.run_recipe()
+        except BaseException as e:
+            print(e)
+        finally:
+            currenttest.virtual_environ_stop()
\ No newline at end of file