Changeset: 41aa66ef40e5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=41aa66ef40e5
Added Files:
        testing/Mz.py.in
Modified Files:
        testing/CMakeLists.txt
        testing/Mtest.py.in
Branch: mtest
Log Message:

rename to Mz


diffs (truncated from 6354 to 300 lines):

diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -115,6 +115,10 @@ configure_file(Mtest.py.in
   ${CMAKE_CURRENT_BINARY_DIR}/Mtest.py
   @ONLY)
 
+configure_file(Mz.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Mz.py
+  @ONLY)
+
 configure_file(listexports.py.in
   ${CMAKE_CURRENT_BINARY_DIR}/listexports.py
   @ONLY)
@@ -125,6 +129,12 @@ install(FILES
   DESTINATION ${CMAKE_INSTALL_BINDIR}
   COMPONENT pytesting)
 
+install(FILES
+  ${CMAKE_CURRENT_BINARY_DIR}/Mz.py
+  PERMISSIONS ${PROGRAM_PERMISSIONS_DEFAULT}
+  DESTINATION ${CMAKE_INSTALL_BINDIR}
+  COMPONENT pytesting)
+
 if(PYTHON3_LIBDIR)
   install(FILES
     Mfilter.py
diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -32,8 +32,6 @@ import struct
 import signal
 import fnmatch
 import glob
-from MonetDBtesting.helpers import build_work_ctx
-
 try:
     import winreg               # Python 3 on Windows
 except ImportError:
@@ -421,6 +419,150 @@ CONDITIONALS = {
     'HAVE_IPV6'            : "",
 }
 
+# a bunch of classes to help with generating (X)HTML files
+class _Encode:
+    # mix-in class for encoding text and attribute values so that they
+    # don't get interpreted as something else by the browser
+    def encode(self, data, attr):
+        map = [('&', '&'),          # MUST be first
+               ('<', '&lt;'),
+               ('>', '&gt;'),
+               (None, None),
+               # following chars only translated in attr values (attr is True)
+               ('"', '&quot;'),
+               ('\t', '&#9;'),
+               ('\n', '&#10;'),
+               ('\r', '&#13;'),
+               ]
+        for c, tr in map:
+            if c is None:
+                if not attr:
+                    break
+                continue
+            data = data.replace(c, tr)
+        return data
+
+class Element(_Encode):
+    # class to represent an (X)HTML element with its attributes and
+    # children
+
+    # inline elements, we do not add newlines to the contents of these
+    # elements
+    inline = ['tt','i','b','big','small','em','strong','dfn','code',
+              'samp','kbd','var','cite','abbr','acronym','a','img',
+              'object','br','script','map','q','sub','sup','span',
+              'bdo','input','select','textarea','label','button','font']
+    # empty elements
+    empty = ['link', 'basefont', 'br', 'area', 'img', 'param', 'hr',
+             'input', 'col', 'frame', 'isindex', 'base', 'meta', ]
+    xml = True                          # write XHTML instead of HTML
+
+    def __init__(self, tag, attrdict = None, *children):
+        self.tag = tag
+        if attrdict is None:
+            attrdict = {}
+        self.attrdict = attrdict
+        if children is None:
+            children = []
+        self.isempty = tag.lower() in self.empty
+        if self.isempty:
+            if children:
+                raise ValueError("empty element can't have children")
+            self.children = None
+        else:
+            self.children = list(children)
+
+    def __str__(self):
+        # string representation of the element with its children
+        s = ['<%s' % self.tag]
+        for name, value in sorted(self.attrdict.items()):
+            s.append(' %s="%s"' % (name, self.encode(value, True)))
+        if self.children or (not self.xml and not self.isempty):
+            s.append('>')
+            for c in self.children:
+                s.append(str(c))
+            s.append('</%s>' % self.tag)
+        elif self.xml:
+            s.append('/>')
+        else:
+            s.append('>')               # empty HTML element
+        return ''.join(s)
+
+    def write(self, f, newline = False):
+        # write the element with its children to a file
+        # if newline is set, add newlines at strategic points
+        if self.tag.lower() == 'html':
+            # before we write the DOCTYPE we should really check
+            # whether the document conforms...
+            if self.xml:
+                f.write('<!DOCTYPE html PUBLIC '
+                        '"-//W3C//DTD XHTML 1.0 Transitional//EN"\n'
+                        '                      '
+                        
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>\n')
+            else:
+                f.write('<!DOCTYPE html PUBLIC '
+                        '"-//W3C//DTD HTML 4.01 Transitional//EN"\n'
+                        '                      '
+                        '"http://www.w3.org/TR/html4/loose.dtd";>\n')
+        inline = self.tag.lower() in self.inline
+        f.write('<%s' % self.tag)
+        for name, value in sorted(self.attrdict.items()):
+            f.write(' %s="%s"' % (name, self.encode(value, True)))
+        if self.children or (not self.xml and not self.isempty):
+            if not inline:
+                for c in self.children:
+                    if not isinstance(c, Element):
+                        inline = True
+                        break
+            f.write('>')
+            if newline and not inline:
+                f.write('\n')
+            for c in self.children:
+                c.write(f, newline and not inline)
+            f.write('</%s>' % self.tag)
+        elif self.xml:
+            f.write('/>')
+        else:
+            f.write('>')                # empty HTML element
+        if newline:
+            f.write('\n')
+
+    def addchild(self, child):
+        self.children.append(child)
+
+    def addchildren(self, children):
+        for child in children:
+            self.children.append(child)
+
+    def inschild(self, index, child):
+        self.children.insert(index, child)
+
+class Text(_Encode):
+    # class to represent text in (X)HTML
+    def __init__(self, text = '', raw = False):
+        self.text = text
+        self.raw = raw
+
+    def __str__(self):
+        if self.raw:
+            return self.text
+        return self.encode(self.text, False)
+
+    def write(self, f, newline = False):
+        f.write(str(self))
+        if newline and not self.raw:
+            f.write('\n')
+
+class Comment:
+    # class to represent an (X)HTML comment (not currently used)
+    def __init__(self, text):
+        self.text = text
+
+    def __str__(self):
+        return '<!--%s-->' % self.text
+
+    def write(self, f, newline = False):
+        f.write(str(self))
 
 class Timer:
     # interface to the threading.Timer function that interprets a
@@ -450,11 +592,34 @@ green = '#00aa00'
 darkgreen = '#005500'
 orange = '#ffaa00'
 purple = '#aa00aa'
+stylesheet = Element('style', None, Text('''
+.error     { font-weight: bold; font-style: italic; color: red; }
+.segfault  { font-weight: bold; font-style: italic; color: purple; }
+.abort     { font-weight: bold; font-style: italic; color: purple; }
+.recursion { font-weight: bold; font-style: italic; color: purple; }
+.timeout   { font-weight: bold; font-style: italic; color: purple; }
+.socket    { font-weight: bold; font-style: italic; color: purple; }
+.warning   { font-weight: bold; color: orange; }
+.good      {  }
+.header    { font-family: helvetica, arial; text-align: center; }
+.black     { color: black; }
+'''))
 
 TIMES = []
 
 random.seed(time.time())
 
+#TODO:
+#class TimeoutError:
+#       def __init__(self, text):
+#               self.text = text
+#       def __str__(self):
+#               return self.text
+#
+#def AlarmHandler(signum, frame) :
+#       raise TimeoutError, "Timeout"
+#### AlarmHandler(signum, frame) #
+
 def ErrMsg(TEXT) :
     STDOUT.flush()
     STDERR.write("\n%s:  ERROR:  %s\n\n" % (THISFILE, TEXT))
@@ -482,6 +647,12 @@ def startswithpath(str,pre) :
     return os.path.normcase(str[:len(pre)]) == os.path.normcase(pre)
 ### startswithpath(str,pre) #
 
+##def path(str) :
+##    return str.replace('/', os.sep)
+### path(str) #
+##def url(str) :
+##    return str.replace(os.sep, '/')
+### url(str) #
 if sys.version_info[0] == 2:
     import urllib
     path = urllib.url2pathname
@@ -513,8 +684,506 @@ def try_open(path, mode) :
     return f
 ###  try_open(path, mode) #
 
+def CreateHtmlIndex (env, *body) :
+    TSTDIR=env['TSTDIR']
+    TSTTRGDIR=env['TSTTRGDIR']
+
+    if TSTDIR:
+        INDEX=".index"
+    else:
+        INDEX="index"
+
+    if body:
+        BACK = os.getcwd()
+        os.chdir(TSTTRGDIR)
+
+        if TSTDIR:
+            header = Text(TSTDIR)
+            if URLPREFIX:
+                header = Element('a',
+                                 {'href': '%s%s/%s' % (URLPREFIX, url(TSTDIR), 
TSTSUFF),
+                                  'target': '%s_%s_body' % (DISTVER, TSTDIR),
+                                  'class': 'black'},
+                                 header)
+            tr = Element('tr', {'valign': 'top'},
+                         Element('th', {'class': 'header'},
+                                 header))
+            tr.addchildren(body)
+            hbody = Element('body',
+                            {'bgcolor': white,
+                             'text': black,
+                             'link': green,
+                             'vlink': darkgreen,
+                             'alink': lime},
+                            Element('center', {},
+                                    Element('table',
+                                            {'align': 'abscenter',
+                                             'border': '1',
+                                             'cellspacing': '0',
+                                             'cellpadding': '3'},
+                                            tr)))
+        else:
+            header = Element('h3', {},
+                             Text(DISTVER))
+            hbody = Element('body',
+                            {'bgcolor': white,
+                             'text': black,
+                             'link': green,
+                             'vlink': darkgreen,
+                             'alink': lime},
+                            header)
+            hbody.addchildren(body)
+        html = Element('html', {},
+                       Element('head', {},
+                               Element('meta', {'charset':'utf8'}),
+                               Element('title', {}, Text(HTMLTITLE)),
+                               stylesheet),
+                       hbody)
+        f = openutf8("%s.head.html" % INDEX,"w")
+        html.write(f, True)
+        f.close()
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to