Salome HOME
add xsl stylesheet
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 8 Feb 2016 15:02:44 +0000 (16:02 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 8 Feb 2016 15:02:44 +0000 (16:02 +0100)
commands/config.py
src/ElementTree.py
src/logger.py
src/xsl/command.xsl [new file with mode: 0644]

index 32e48813fc8eaf0b8f1c5dfe444a71c988c18b9b..e8701dd30cff7a8891fb872967a3af5af3f6d259 100644 (file)
@@ -17,7 +17,6 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
 import os
-import sys
 import platform
 import datetime
 import shutil
@@ -337,12 +336,13 @@ class ConfigManager:
         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 :
     '''            
@@ -360,28 +360,28 @@ def print_value(config, path, show_label, level=0, show_full_path=False):
     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.
@@ -403,10 +403,9 @@ def run(args, runner):
         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:
@@ -460,7 +459,7 @@ def run(args, runner):
             
             # 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:
index 8714da7ef2dad2de2ebad95c4efe04be3462a683..d11ad7fe2df0838170b29281b9ba457ae134fb6a 100644 (file)
@@ -106,7 +106,7 @@ __all__ = [
 # 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
@@ -798,6 +798,13 @@ def _encode_entity(text, pattern=_escape):
 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, "&", "&amp;")
         text = replace(text, "<", "&lt;")
         text = replace(text, ">", "&gt;")
index d3be7952d83b7e0d948d01815abbf16f082e3417..9b0135d3ca72a18d2d27d15bc16bcc6ba8623646 100644 (file)
@@ -18,6 +18,7 @@
 
 import sys
 import os
+import datetime
 
 import src
 from . import printcolors
@@ -105,4 +106,24 @@ class Logger(object):
         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
diff --git a/src/xsl/command.xsl b/src/xsl/command.xsl
new file mode 100644 (file)
index 0000000..7d0507a
--- /dev/null
@@ -0,0 +1,49 @@
+<?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>