for rule in self.get_command_line_overrides(options, ["USER"]):
exec('cfg.' + rule) # this cannot be factorize because of the exec
+ # =======================================================================================
+ # Add log directory in the config
+ # get the log directory regarding the fact the command uses an application or not
+ if 'APPLICATION' in cfg:
+ logDir = os.path.join(cfg.APPLICATION.out_dir, 'LOGS')
+ else:
+ logDir = os.path.join(cfg.VARS.personalDir, 'LOGS')
+ cfg.VARS.logDir = logDir
+
return cfg
def setUserConfigFile(self, config):
# perform the copy
shutil.copyfile(source_full_path, dest_file)
- runner.logger.write(_("%s has been created.") % dest_file)
+ runner.logger.write(_("%s has been created.\n") % dest_file)
# case : display all the available pyconf applications
elif options.list:
--- /dev/null
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+import os
+import shutil
+
+import src
+
+# Define all possible option for log command : sat log <options>
+parser = src.options.Options()
+parser.add_option('t', 'terminal', 'boolean', 'terminal', "Terminal log.")
+
+
+
+def description():
+ return _("Gives access to logs of salomeTools.")
+
+def run(args, runner):
+ (options, args) = parser.parse_args(args)
+ if options.terminal:
+ print('terminal')
+
+ # Find stylesheet Directory and files
+ xslDir = os.path.join(runner.cfg.VARS.srcDir, 'xsl')
+ xslCommand = os.path.join(xslDir, "command.xsl")
+ xslHat = os.path.join(xslDir, "hat.xsl")
+ imgLogo = os.path.join(xslDir, "LOGO-SAT.png")
+
+ # get the log direcory. If there is an application, it is in cfg.APPLICATION.out_dir, else in user directory
+ logDir = runner.cfg.VARS.logDir
+
+ # copy the stylesheet in the log directory
+ shutil.copy2(xslCommand, logDir)
+ shutil.copy2(xslHat, logDir)
+ shutil.copy2(imgLogo, logDir)
+
+ xmlHatFilePath = os.path.join(logDir, 'hat.xml')
+ src.xmlManager.update_hat_xml(logDir)
+
+ src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath)
\ No newline at end of file
self.logFileName = logFileName
self.logFilePath = logFilePath
- self.xmlFile = xmlManager.xmlLogFile(logFilePath, config.VARS.command)
+ self.xmlFile = xmlManager.xmlLogFile(logFilePath, "SATcommand", attrib = {"command" : config.VARS.command})
self.putInitialXMLFields()
def putInitialXMLFields(self):
self.xmlFile.add_simple_node("field", text=endtime , attrib={"name" : "endTime"})
self.xmlFile.add_simple_node("field", text="%ih%im%is" % (hours, minutes, seconds) , attrib={"name" : "Total Time"})
self.xmlFile.write_tree(stylesheet = "command.xsl")
+ src.xmlManager.update_hat_xml(self.config.VARS.logDir)
def date_to_datetime(date):
Y = int(date[:4])
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
+import re
import src
from . import ElementTree as etree
class xmlLogFile(object):
'''Class to manage writing in salomeTools xml log file
'''
- def __init__(self, filePath, command):
+ def __init__(self, filePath, rootname, attrib = {}):
self.logFile = filePath
- src.ensure_path_exists(os.path.dirname(filePath))
- self.xmlroot = etree.Element("SATcommand", attrib = {"command" : command})
+ src.ensure_path_exists(os.path.dirname(filePath))
+ self.xmlroot = etree.Element(rootname, attrib = attrib)
def write_tree(self, stylesheet=None):
f = open(self.logFile, 'w')
f.write(etree.tostring(self.xmlroot, encoding='utf-8'))
f.close()
-
def add_simple_node(self, node_name, text=None, attrib={}):
n = etree.Element(node_name, attrib=attrib)
n.text = text
def append_node(self, node_name, text):
for field in self.xmlroot:
if field.tag == node_name:
- field.text += text
\ No newline at end of file
+ field.text += text
+
+def update_hat_xml(logDir):
+ xmlHatFilePath = os.path.join(logDir, 'hat.xml')
+ xmlHat = xmlLogFile(xmlHatFilePath, "LOGlist")
+
+ for fileName in os.listdir(logDir):
+ sExpr = "^[0-9]{8}_+[0-9]{6}_+[A-Za-z0-9]*.xml$"
+ oExpr = re.compile(sExpr)
+ if oExpr.search(fileName):
+ date_hour_cmd = fileName.split('_')
+ date_not_formated = date_hour_cmd[0]
+ date = "%s/%s/%s" % (date_not_formated[6:8], date_not_formated[4:6], date_not_formated[0:4] )
+ hour_not_formated = date_hour_cmd[1]
+ hour = "%s:%s:%s" % (hour_not_formated[0:2], hour_not_formated[2:4], hour_not_formated[4:6])
+ cmd = date_hour_cmd[2][:-len('.xml')]
+
+ xmlHat.add_simple_node("LogCommand", text=fileName, attrib = {"date" : date, "hour" : hour, "cmd" : cmd})
+
+ xmlHat.write_tree('hat.xsl')
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="html" />
+<xsl:template match="/">
+
+<head>
+ <title>SAlomeTools log</title>
+ <style type="text/css">
+ table {
+ margin:1px;
+ padding:1px;
+ border-collapse:collapse;
+ empty-cells : show;
+ }
+ td { vertical-align : center;}
+ h1 { text-align : center; }
+ .legend { font-weight : bold;
+ text-align : center;
+ }
+ .def { font-family: Arial, Verdana, "Times New Roman", Times, serif;}
+ hr.note { color: #BFBFBF; }
+ .note { text-align : right; font-style: italic; font-size: small; }
+ div.release { -moz-column-count: 2;
+ overflow: auto;
+ max-height: 250px;
+ }
+ </style>
+</head>
+ <body class="def" bgcolor="aliceblue">
+ <h1><img src="LOGO-SAT.png"/></h1>
+ <table border="0">
+ <tr>
+ <td width="100px">Command</td><td width="100px">date</td><td>time</td>
+ </tr>
+ <xsl:for-each select="LOGlist/LogCommand">
+ <xsl:sort select="." order="descending" />
+ <tr bgcolor="aliceblue" width="2">
+ <td>
+ <a title="log" target="_blank">
+ <xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute>
+ <xsl:value-of select="@cmd"/>
+ </a>
+ </td>
+ <td><xsl:value-of select="@date"/></td>
+ <td><xsl:value-of select="@hour"/></td>
+ </tr>
+ </xsl:for-each>
+ </table>
+ </body>
+</xsl:template>
+</xsl:stylesheet>