# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
-import sys
import platform
import datetime
import shutil
return self.user_config_file_path
-def print_value(config, path, show_label, level=0, show_full_path=False):
+def print_value(config, path, show_label, logger, level=0, show_full_path=False):
'''Prints a value from the configuration. Prints recursively the values under the initial path.
:param config class 'src.pyconf.Config': The configuration from which the value is displayed.
:param path str : the path in the configuration of the value to print.
:param show_label boolean: if True, do a basic display. (useful for bash completion)
+ :param logger Logger: the logger instance
:param level int: The number of spaces to add before display.
:param show_full_path :
'''
try:
val = config.getByPath(path)
except Exception as e:
- sys.stdout.write(tab_level)
- sys.stdout.write("%s: ERROR %s\n" % (src.printcolors.printcLabel(vname), src.printcolors.printcError(str(e))))
+ logger.write(tab_level)
+ logger.write("%s: ERROR %s\n" % (src.printcolors.printcLabel(vname), src.printcolors.printcError(str(e))))
return
# in this case, display only the value
if show_label:
- sys.stdout.write(tab_level)
- sys.stdout.write("%s: " % src.printcolors.printcLabel(vname))
+ logger.write(tab_level)
+ logger.write("%s: " % src.printcolors.printcLabel(vname))
# The case where the value has under values, do a recursive call to the function
if dir(val).__contains__('keys'):
- if show_label: sys.stdout.write("\n")
+ if show_label: logger.write("\n")
for v in sorted(val.keys()):
- print_value(config, path + '.' + v, show_label, level + 1)
+ print_value(config, path + '.' + v, show_label, logger, level + 1)
elif val.__class__ == src.pyconf.Sequence or isinstance(val, list): # in this case, value is a list (or a Sequence)
- if show_label: sys.stdout.write("\n")
+ if show_label: logger.write("\n")
index = 0
for v in val:
- print_value(config, path + "[" + str(index) + "]", show_label, level + 1)
+ print_value(config, path + "[" + str(index) + "]", show_label, logger, level + 1)
index = index + 1
else: # case where val is just a str
- sys.stdout.write("%s\n" % val)
+ logger.write("%s\n" % val)
def description():
'''method that is called when salomeTools is called with --help option.
if options.value == ".":
# if argument is ".", print all the config
for val in sorted(runner.cfg.keys()):
- print_value(runner.cfg, val, True)
- return
- print_value(runner.cfg, options.value, True, level=0, show_full_path=False)
- return
+ print_value(runner.cfg, val, True, runner.logger)
+ else:
+ print_value(runner.cfg, options.value, True, runner.logger, level=0, show_full_path=False)
# case : edit user pyconf file or application file
elif options.edit:
# perform the copy
shutil.copyfile(source_full_path, dest_file)
- print(_("%s has been created.") % dest_file)
+ runner.logger.write(_("%s has been created.") % dest_file)
# case : display all the available pyconf applications
elif options.list:
# structure, and convert it from and to XML.
##
-import string, sys, re
+import string, sys, re, platform
class _SimpleElementPath:
# emulate pre-1.2 find/findtext/findall behaviour
def _escape_cdata(text, encoding=None, replace=str.replace):
# escape character data
try:
+ if platform.python_version()[0] == '2': # python 2.x.y
+ if encoding:
+ try:
+ text = _encode(text, encoding)
+ except UnicodeError:
+ return _encode_entity(text)
+
text = replace(text, "&", "&")
text = replace(text, "<", "<")
text = replace(text, ">", ">")
import sys
import os
+import datetime
import src
from . import printcolors
sys.stdout.flush()
def endWrite(self):
- self.xmlFile.write_tree()
+ dt = datetime.datetime.now()
+ endtime = dt.strftime('%Y%m%d_%H%M%S')
+ t0 = date_to_datetime(self.config.VARS.datehour)
+ tf = dt
+ delta = tf - t0
+ total_time = delta.total_seconds()
+ hours = int(total_time / 3600)
+ minutes = int((total_time - hours*3600) / 60)
+ seconds = total_time - hours*3600 - minutes*60
+ 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")
+
+def date_to_datetime(date):
+ Y = int(date[:4])
+ m = int(date[4:6])
+ dd = int(date[6:8])
+ H = int(date[9:11])
+ M = int(date[11:13])
+ S = int(date[13:15])
+ return datetime.datetime(Y, m, dd, H, M, S)
\ 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" /> <!-- encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>-->
+<xsl:template match="/">
+
+<head>
+ <title>SAlomeTools log</title>
+ <style type="text/css">
+ table { width : 100%;
+ margin:1px;
+ padding:1px;
+ border-collapse:collapse;
+ empty-cells : show;
+ }
+ td { vertical-align : center; padding: 15px; }
+ 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="1">
+ <tr>
+ <xsl:for-each select="SATcommand/field">
+ <td bgcolor="LightBlue">
+ <th><xsl:value-of select="@name"/></th>
+ </td>
+ </xsl:for-each>
+ </tr>
+ <tr>
+ <xsl:for-each select="SATcommand/field">
+ <td bgcolor="Beige"><xsl:value-of select="."/></td>
+ </xsl:for-each>
+ </tr>
+ </table>
+ <h1>command's traces :</h1>
+ <PRE><xsl:value-of select="SATcommand/traces"/></PRE>
+ </body>
+</xsl:template>
+</xsl:stylesheet>