Author: gnichols
Date: 2011-07-25 14:18:04 +0000 (Mon, 25 Jul 2011)
New Revision: 1029
Added:
trunk/server/cgi/saveFile.py
trunk/server/cgi/saved.py
trunk/server/cgi/template.py
Modified:
trunk/server/cgi/Makefile
trunk/server/cgi/v7xml.py
trunk/server/cgi/xsl/summary.xsl
trunk/server/index.html
Log:
725441 - FEAT: save command should store results on server for review
Modified: trunk/server/cgi/Makefile
===================================================================
--- trunk/server/cgi/Makefile 2011-07-25 14:16:59 UTC (rev 1028)
+++ trunk/server/cgi/Makefile 2011-07-25 14:18:04 UTC (rev 1029)
@@ -16,7 +16,7 @@
.PHONY: clean
-FILES := v7web.py v7xml.py networkTest.py
+FILES := v7web.py v7xml.py networkTest.py saveFile.py saved.py template.py
SUBDIRS := xsl
V7_SERVER_ROOT := /var/www/v7
Added: trunk/server/cgi/saveFile.py
===================================================================
--- trunk/server/cgi/saveFile.py (rev 0)
+++ trunk/server/cgi/saveFile.py 2011-07-25 14:18:04 UTC (rev 1029)
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Greg Nichols
+#
+
+# this cgi is used by the http transfer portion of the network test. It saves the file
enclosure to the v7
+# storage area for the upload portion of the test. The network test uses a simple
request for the file
+# for the download test
+
+import os,sys,cgi
+v7ClassLibraryPath = '/usr/share/v7/lib/'
+sys.path.append(v7ClassLibraryPath)
+os.putenv("PYTHONPATH", v7ClassLibraryPath)
+from v7.hash import hashModule
+
+from v7.environment import Environment
+
+environment = Environment()
+
+import cgitb
+cgitb.enable()
+
+
+def saveFiles():
+ ipAddress = cgi.escape(os.environ["REMOTE_ADDR"])
+
+ files = list()
+ fieldStorage = cgi.FieldStorage()
+ try:
+ serverPath = fieldStorage["server-path"]
+ except:
+ print "Error: no server-path is set"
+ return False
+ print "server-path:"
+ if serverPath.value:
+ serverPath = os.path.join(*serverPath.value.split())
+ print serverPath
+ directory = os.path.join(environment.getServerDirectory(), "store",
serverPath)
+ print "directory %s" % directory
+ try:
+ os.makedirs(directory)
+ except OSError:
+ # directory exists
+ pass
+ for key in fieldStorage.keys():
+ if fieldStorage[key].name == 'file':
+ path = os.path.join(directory, fieldStorage[key].filename)
+ file = open(path, "wb")
+ file.write(fieldStorage[key].value.decode("base64"))
+ file.close()
+ print " Saved: " + path
+
+
+
+print "Content-type: text/plain";
+print
+
+
+files = saveFiles()
+
+
+
+sys.stdout.flush()
+
+
Property changes on: trunk/server/cgi/saveFile.py
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/server/cgi/saved.py
===================================================================
--- trunk/server/cgi/saved.py (rev 0)
+++ trunk/server/cgi/saved.py 2011-07-25 14:18:04 UTC (rev 1029)
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Greg Nichols
+#
+
+import os,sys,cgi,lxml, re
+from lxml import etree
+v7ClassLibraryPath = '/usr/share/v7/lib/'
+sys.path.append(v7ClassLibraryPath)
+os.putenv("PYTHONPATH", v7ClassLibraryPath)
+v7ServerRoot = '/var/www/v7'
+
+from v7.environment import Environment
+from template import Template
+
+environment = Environment()
+
+import cgitb
+cgitb.enable()
+
+
+def getParameters():
+ fieldStorage = cgi.FieldStorage()
+ # convert to a regular dict()
+ parameters = { "path": ""}
+ for key in fieldStorage.keys():
+ parameters[key] = fieldStorage[key].value
+
+ return parameters
+
+
+def showSavedResults(parameters):
+ localPath = os.path.join(environment.getServerDirectory(), "store")
+ resultsFileFilter = re.compile("\.(xml|xml.gz)$", re.IGNORECASE)
+ fileNamePattern =
re.compile("^v7-results-(?P<hostname>[^\-]+)-(?P<date>[0-9]+)\.xml(.gz)?$")
+ for (root,dirs,files) in os.walk(localPath):
+ files = filter(resultsFileFilter.search, files)
+ if files:
+ info = root[len(localPath):]
+ print " ".join(info.split("/")[1:]) +
"<br>"
+
+ for file in files:
+ match = fileNamePattern.search(file)
+ if match:
+ dateStamp = match.group("date")
+ date = "%s-%s-%s" % (dateStamp[4:6], dateStamp[6:8],
dateStamp[:4])
+ hostname = match.group("hostname")
+ print " <a
href=\"v7xml.py?sheet=summary&content=html&rpath=%s/%s\">%s
%s</a><br>" % (root, file, hostname, date)
+ print "<br>"
+
+parameters = getParameters()
+template = Template()
+template.writeHeader()
+print "<!--"
+for key in parameters:
+ print "%s=%s" % (key, parameters[key])
+print" -->"
+
+print """
+ <h2>Saved Test Results</h2>
+ """
+showSavedResults(parameters)
+template.writeFooter()
+sys.stdout.flush()
+
+
Property changes on: trunk/server/cgi/saved.py
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/server/cgi/template.py
===================================================================
--- trunk/server/cgi/template.py (rev 0)
+++ trunk/server/cgi/template.py 2011-07-25 14:18:04 UTC (rev 1029)
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Greg Nichols
+#
+
+import os
+
+class Template:
+
+ def __init__(self):
+ return
+
+ def getHostName(self):
+ system,node,release,version,machine = os.uname()
+ return node
+
+ def writeHeader(self):
+ print "Content-type: text/html";
+ print """
+
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+ <html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
+
+ <head>
+ <title>Red Hat Hardware Certification</title>
+ <link rel="shortcut icon"
href="/v7/images/favicon.ico">
+ <link rel="stylesheet" href="/v7/css/v7.css">
+
+ </head>
+
+ <body id="mainone">
+
+
+ <div id="wrap">
+ <div id="innerwrap">
+
+ <!-- HEADER -->
+ <div id="header">
+ <img src="/v7/images/logo_rh_home.png" alt="Red Hat Home"
width="96" height="31" id="rhLogo" />
+ </div><!-- end header -->
+
+ """
+ # Navigation
+ print "<h1>%s</h1><h1> Hardware Certification Test
Server</h1>" % self.getHostName()
+ print """
+ <table>
+ <tr>
+ <td><a href="/v7/">Home</a></td>
+ </tr>
+ </table>
+ <br/><br/>
+ """
+
+ def writeFooter(self):
+ print """
+ </div></div>
+ </body>
+ </html>
+ """
Modified: trunk/server/cgi/v7xml.py
===================================================================
--- trunk/server/cgi/v7xml.py 2011-07-25 14:16:59 UTC (rev 1028)
+++ trunk/server/cgi/v7xml.py 2011-07-25 14:18:04 UTC (rev 1029)
@@ -15,13 +15,13 @@
# Author: Greg Nichols
#
-import os,sys,cgi,lxml
+import os,sys,cgi,lxml,gzip
from lxml import etree
v7ClassLibraryPath = '/usr/share/v7/lib/'
sys.path.append(v7ClassLibraryPath)
os.putenv("PYTHONPATH", v7ClassLibraryPath)
-v7ServerRoot = '/var/www/v7'
+
from v7.environment import Environment
environment = Environment()
@@ -33,36 +33,47 @@
def getParameters():
fieldStorage = cgi.FieldStorage()
# convert to a regular dict()
- parameters = { "sheet": "default",
"content":"xml", "devices":"\'hide\'",
"device-classes": "\'hide\'"}
+ cgiParameters = { "sheet": "default",
"content":"xml", "rpath":environment.getResultsPath()}
+ xsltParameters = { "devices":"\'hide\'",
"device-classes": "\'hide\'",
"rpath":"\'%s\'" % environment.getResultsPath()}
for key in fieldStorage.keys():
- if key in ["sheet", "content"]:
- parameters[key] = fieldStorage[key].value
- else:
- # assume all parameter values are strings (wrap them in ''s)
- parameters[key] = "\'%s\'" % fieldStorage[key].value
- return parameters
+ cgiParameters[key] = fieldStorage[key].value
+ # assume all parameter values are strings (wrap them in ''s)
+ xsltParameters[key] = "\'%s\'" % fieldStorage[key].value
+ return (cgiParameters, xsltParameters)
-def doTransform(parameters):
- xslt = etree.parse("%s/xsl/%s.xsl" % (v7ServerRoot,
parameters["sheet"]))
+def doTransform(cgiParameters, xsltParameters):
+ xslt = etree.parse("%s/xsl/%s.xsl" % (environment.getServerDirectory(),
cgiParameters["sheet"]))
transform = etree.XSLT(xslt)
- results = etree.parse(environment.getResultsPath())
- output = transform(results, **parameters)
+ resultsPath = environment.getResultsPath()
+ if "rpath" in cgiParameters:
+ resultsPath = cgiParameters["rpath"]
+ if resultsPath[-2:] == "gz":
+ results = gzip.open(resultsPath, 'rb')
+ else:
+ results = open(resultsPath)
+
+ results = etree.parse(results)
+ output = transform(results, **xsltParameters)
# write the transformed doc to the output
output.write(sys.stdout)
sys.stdout.flush()
-parameters = getParameters()
-print "Content-type: text/%s" % parameters["content"];
+(cgiParameters, xsltParameters) = getParameters()
+print "Content-type: text/%s" % cgiParameters["content"];
print
-print "<!--"
-for key in parameters:
- print "%s=%s" % (key, parameters[key])
+print "<!-- cgi parameters"
+for key in cgiParameters:
+ print "%s=%s" % (key, cgiParameters[key])
print" -->"
+print "<!-- xslt parameters"
+for key in xsltParameters:
+ print "%s=%s" % (key, xsltParameters[key])
+print" -->"
-doTransform(parameters)
+doTransform(cgiParameters, xsltParameters)
sys.stdout.flush()
Modified: trunk/server/cgi/xsl/summary.xsl
===================================================================
--- trunk/server/cgi/xsl/summary.xsl 2011-07-25 14:16:59 UTC (rev 1028)
+++ trunk/server/cgi/xsl/summary.xsl 2011-07-25 14:18:04 UTC (rev 1029)
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:variable name="results" select="HHHH" />
<xsl:template match="/certification-test">
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -->
@@ -20,7 +21,7 @@
<!-- overview -->
<h1>Hardware Certification Test Suite</h1>
-
+
<table class="overview">
<thead></thead>
@@ -41,9 +42,25 @@
<table class="navigation">
<tr><td>See Also:</td>
<td><a href="/v7/">Home</a></td>
- <td><a
href="v7xml.py?sheet=summary&content=html">Summary</a></td>
+ <td>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:text>v7xml.py?sheet=summary</xsl:text>
+ <xsl:text>&content=html</xsl:text>
+ <xsl:text>&rpath=</xsl:text><xsl:value-of
select="$rpath"/>
+ </xsl:attribute>
+ Summary
+ </a></td>
- <td><a
href="v7xml.py?sheet=device">Devices</a></td>
+ <td>
+ <a>
+
+ <xsl:attribute name="href">
+
<xsl:text>v7xml.py?sheet=device&rpath=</xsl:text><xsl:value-of
select="$rpath"/>
+ </xsl:attribute>
+ Devices
+ </a>
+ </td>
</tr>
</table>
@@ -70,6 +87,7 @@
<xsl:if test="@logical-device !=
''">
<xsl:text>&device=</xsl:text><xsl:value-of
select="$currentTest/@logical-device"/>
</xsl:if>
+
<xsl:text>&rpath=</xsl:text><xsl:value-of
select="$rpath"/>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
@@ -82,7 +100,7 @@
<a>
<xsl:attribute name="href">
<xsl:text>v7xml.py?sheet=device&udi=</xsl:text><xsl:value-of
select="@udi"/>
-
+
<xsl:text>&rpath=</xsl:text><xsl:value-of
select="$rpath"/>
</xsl:attribute>
<xsl:value-of select="@logical-device"/>
</a>
@@ -140,6 +158,7 @@
<xsl:if test="$currentTest/@logical-device != ''">
<xsl:text>&device=</xsl:text><xsl:value-of
select="$currentTest/@logical-device"/>
</xsl:if>
+ <xsl:text>&rpath=</xsl:text><xsl:value-of
select="$rpath"/>
</xsl:attribute>
<xsl:value-of select="$currentRun/summary" />
</a>
Modified: trunk/server/index.html
===================================================================
--- trunk/server/index.html 2011-07-25 14:16:59 UTC (rev 1028)
+++ trunk/server/index.html 2011-07-25 14:18:04 UTC (rev 1029)
@@ -24,12 +24,15 @@
<!-- overview -->
<h1>Hardware Certification Test Suite</h1>
<p> Welcome to the Red Hat v7 Hardware Certification Test Suite.</p>
+
+ <br>
+ Test Results Storage:<br>
+ <a
href="cgi/saved.py?sheet=summary&content=html">Saved Test
Results</a><br>
<br>
- Test Results:<br>
+ This Server's Test Results:<br>
<a
href="cgi/v7xml.py?sheet=summary&content=html">Summary</a><br>
<a href="cgi/v7xml.py">Filtered XML</a>
<br>
- <a href="results.xml">Raw
XML</a<br>
<br>
<a href="docs">Documentation</a><br>
<br>