Add extra logging for the ONS 2016 S3 demo

Change-Id: I716262972b9d16cce7b9d2f0922d3ff1c823a4f7
diff --git a/TestON/bin/demo-summary b/TestON/bin/demo-summary
new file mode 100755
index 0000000..2f90a55
--- /dev/null
+++ b/TestON/bin/demo-summary
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e -o pipefail
+
+if [ "$#" -lt 1 ]; then
+    file="DemoCode"
+elif [ "$1" = "-s" ]; then
+    file="DemoSummary"
+else
+    printf "usage: $(basename $0) [options]\n\n"
+    printf "Simple command to print the latest test summary file.\n"
+    printf "\noptions:\n\t--help : Displays this message and exits\n"
+    printf "\t-f     : Tails the summary file and updates as the file is written to.\n\n"
+    exit 1
+fi
+ls -t ~/OnosSystemTest/TestON/logs/*/*${file}.txt | head -1 | xargs tail -n+1 -f
+exit 0
diff --git a/TestON/core/logger.py b/TestON/core/logger.py
index 05693ba..7abed25 100644
--- a/TestON/core/logger.py
+++ b/TestON/core/logger.py
@@ -118,6 +118,8 @@
         main.LogFileName = main.logdir + "/" + main.TEST + "_" +str(currentTime) + ".log"
         main.ReportFileName = main.logdir + "/" + main.TEST + "_" + str(currentTime) + ".rpt"
         main.WikiFileName = main.logdir + "/" + main.TEST + "Wiki.txt"
+        main.DemoCodeFileName = main.logdir + "/" + main.TEST + "-DemoCode.txt"
+        main.DemoSummaryFileName = main.logdir + "/" + main.TEST + "-DemoSummary.txt"
         main.SummaryFileName = main.logdir + "/" + main.TEST + "Summary.txt"
         main.JenkinsCSV = main.logdir + "/" + main.TEST + ".csv"
         main.TOTAL_TC_SUCCESS = 0
@@ -165,6 +167,68 @@
 
         main.log.wiki = wiki
 
+        def demoCode( msg ):
+            '''
+                Will append the message to the txt file for the Demo.
+            '''
+            colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
+                       'blue': '\033[94m', 'green': '\033[92m',
+                       'yellow': '\033[93m', 'red': '\033[91m',
+                       'end': '\033[0m' }
+
+            main.demoCodeFile = open( main.DemoCodeFileName, "a+" )
+            parsedMsg = ''
+            wrapped = False
+            for line in msg.splitlines():
+                if wrapped:
+                    parsedMsg += line
+                    if ')' in line:
+                        wrapped = False
+                        parsedMsg += colors['end']
+                elif "main.case(" in line:
+                    parsedMsg += colors['cyan'] + line + colors['end']
+                elif "main.step" in line:
+                    parsedMsg += colors['red'] + line + colors['end']
+                elif "utilities.assert_" in line and  "(" in line:
+                    parsedMsg += colors['purple'] + line
+                    if ')' not in line:
+                        wrapped = True
+                    else:
+                        parsedMsg += colors['end']
+                else:
+                    parsedMsg += line
+                parsedMsg += '\n'
+            main.demoCodeFile.write( parsedMsg + "\n" )
+            main.demoCodeFile.close()
+
+        main.log.demo = demoCode
+
+        def demoSummary( msg, level=None ):
+            '''
+                Will append the message to the txt file for the Demo.
+            '''
+            colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
+                       'blue': '\033[94m', 'green': '\033[92m',
+                       'yellow': '\033[93m', 'red': '\033[91m',
+                       'end': '\033[0m' }
+
+            main.demoSummaryFile = open( main.DemoSummaryFileName, "a+" )
+            parsedMsg = ''
+            if level is None:
+                parsedMsg += msg
+            elif level.lower() == "case":
+                parsedMsg += colors['cyan'] + "CASE:" + msg
+            elif level.lower() == "step":
+                parsedMsg += colors['yellow'] + "\tSTEP:"
+                parsedMsg += msg[ msg.find( ':' ) + 1 :]
+            parsedMsg += colors['end']
+            main.demoSummaryFile.write( parsedMsg + "\n" )
+            main.demoSummaryFile.close()
+
+        main.log.demoSummary = demoSummary
+
+
+
         def exact(exmsg):
             '''
                Will append the raw formatted message to the logs
@@ -190,6 +254,7 @@
             logfile = open(main.LogFileName,"a")
             logfile.write("\n"+ str(newmsg) +"\n")
             logfile.close()
+            main.log.demoSummary( msg, "case" )
             print newmsg
 
         main.log.case = case
@@ -204,6 +269,7 @@
             logfile = open(main.LogFileName,"a")
             logfile.write("\n"+ str(newmsg) +"\n")
             logfile.close()
+            main.log.demoSummary( msg, "step" )
             print newmsg
 
         main.log.step = step
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 76f7842..ae4ae3a 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -324,6 +324,7 @@
                 # NOTE: This is needed to catch results of main.step()'s
                 #       called inside functions or loops
                 self.stepResults = ( [], [], [], [] )
+                self.log.demo( code[testCaseNumber][step] )  # for ONS Demo
                 exec code[testCaseNumber][step] in module.__dict__
                 self.stepCount = self.stepCount + 1
                 self.parseStepResults( testCaseNumber )