From 72c0f0b044d349410e8b6da12d9b3506f5fbed64 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Wed, 17 Feb 2016 15:03:43 +0100 Subject: [PATCH] logging mechanism for extern commands like cmake, make, git, etc... --- commands/testcommand.py | 10 ++++++++++ src/logger.py | 18 ++++++++++++++---- src/xsl/command.xsl | 12 ++++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/commands/testcommand.py b/commands/testcommand.py index 2dbd7e0..0a181e9 100644 --- a/commands/testcommand.py +++ b/commands/testcommand.py @@ -1,12 +1,15 @@ #!/usr/bin/env python #-*- coding:utf-8 -*- +import subprocess + import src # Define all possible option for config command : sat config parser = src.options.Options() parser.add_option('u', 'unique', 'boolean', 'unique', "TEST d'option.") parser.add_option('v', 'value', 'string', 'value', "Appelle la commande config avec l'option value.") +parser.add_option('m', 'make', 'boolean', 'test_make', "Test d'une commande exterieure : make.") def description(): return _("Test d'une commande supplémentaire.") @@ -19,3 +22,10 @@ def run(args, runner, logger): elif options.value: runner.cfg.VARS.user = 'TEST' runner.config('-v ' + options.value, logger) + elif options.test_make: + command = "make" + logger.write("Execution of make\n", 3) + res = subprocess.call(command, cwd=str('/tmp'), shell=True, + stdout=logger.logTxtFile, stderr=logger.logTxtFile) + + print(res) \ No newline at end of file diff --git a/src/logger.py b/src/logger.py index a34ebfe..e2fcc0d 100644 --- a/src/logger.py +++ b/src/logger.py @@ -28,7 +28,7 @@ from . import xmlManager logCommandFileExpression = "^[0-9]{8}_+[0-9]{6}_+.*\.xml$" class Logger(object): - '''Class to handle log mechanism + '''Class to handle log mechanism. ''' def __init__(self, config, silent_sysstd=False): '''Initialization @@ -40,16 +40,25 @@ class Logger(object): self.default_level = 3 self.silentSysStd = silent_sysstd - # Construct log file location. There are two cases. With an application an without any application. + # Construct xml log file location for sat prints. logFileName = config.VARS.datehour + "_" + config.VARS.command + ".xml" logFilePath = os.path.join(config.SITE.log.logDir, logFileName) - + # Construct txt file location in order to log the external commands calls (cmake, make, git clone, etc...) + txtFileName = config.VARS.datehour + "_" + config.VARS.command + ".txt" + txtFilePath = os.path.join(config.SITE.log.logDir, "OUT", txtFileName) + src.ensure_path_exists(os.path.dirname(logFilePath)) + src.ensure_path_exists(os.path.dirname(txtFilePath)) self.logFileName = logFileName - self.logFilePath = logFilePath + self.logFilePath = logFilePath + self.txtFileName = txtFileName + self.txtFilePath = txtFilePath + # Initialize xml instance and put first fields like beginTime, user, command, etc... self.xmlFile = xmlManager.xmlLogFile(logFilePath, "SATcommand", attrib = {"application" : config.VARS.application}) self.putInitialXMLFields() + # Initialize the txt file for reading + self.logTxtFile = open(str(self.txtFilePath), 'w', buffering=0) def putInitialXMLFields(self): '''Method called at class initialization : Put all fields corresponding to the command context (user, time, ...) @@ -73,6 +82,7 @@ class Logger(object): self.xmlFile.append_node_attrib("Site", attrib={"application" : self.config.VARS.application}) # The initialization of the trace node self.xmlFile.add_simple_node("Log",text="") + self.xmlFile.add_simple_node("OutLog",text=os.path.join("OUT", self.txtFileName)) def write(self, message, level=None, screenOnly=False): '''the function used in the commands that will print in the terminal and the log file. diff --git a/src/xsl/command.xsl b/src/xsl/command.xsl index 76c3c48..f1d80ea 100644 --- a/src/xsl/command.xsl +++ b/src/xsl/command.xsl @@ -2,7 +2,7 @@ - + SAlomeTools log +

@@ -42,8 +43,15 @@ -

command's traces :

+ +

command's interne traces :

+ +

Called commands traces :

+ + + +
\ No newline at end of file -- 2.39.2