gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r202049 - in /gump/branches/Gump3/webgump: htdocs/app/handler.py lib/python/webgump/__init__.py lib/python/webgump/controllers/doc.py lib/python/webgump/controllers/home.py lib/python/webgump/util/__init__.py xdocs/ xdocs/index.xml
Date Mon, 27 Jun 2005 20:31:59 GMT
Author: leosimons
Date: Mon Jun 27 13:31:58 2005
New Revision: 202049

URL: http://svn.apache.org/viewcvs?rev=202049&view=rev
Log:
Demoing xdocs being properly served up by python.

Added:
    gump/branches/Gump3/webgump/lib/python/webgump/controllers/doc.py
      - copied, changed from r201976, gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py
    gump/branches/Gump3/webgump/xdocs/
    gump/branches/Gump3/webgump/xdocs/index.xml
      - copied, changed from r201976, gump/branches/Gump3/dynagump/webapp/index.xml
Modified:
    gump/branches/Gump3/webgump/htdocs/app/handler.py
    gump/branches/Gump3/webgump/lib/python/webgump/__init__.py
    gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py
    gump/branches/Gump3/webgump/lib/python/webgump/util/__init__.py

Modified: gump/branches/Gump3/webgump/htdocs/app/handler.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/webgump/htdocs/app/handler.py?rev=202049&r1=202048&r2=202049&view=diff
==============================================================================
--- gump/branches/Gump3/webgump/htdocs/app/handler.py (original)
+++ gump/branches/Gump3/webgump/htdocs/app/handler.py Mon Jun 27 13:31:58 2005
@@ -8,12 +8,12 @@
 
 from webgump.util import log
 from webgump.util.log import Logger
+from webgump.util import bust_cache
 
-#DEBUG = True
-DEBUG = False
+import webgump
 
-class SecurityError(Exception):
-    pass
+DEBUG = True
+#DEBUG = False
 
 class Handler:
     def __init__(self, req):
@@ -34,10 +34,20 @@
             self._settings()
             action = self._get_action()
             self.status = action(self.req, self.settings)
-        except SecurityError, msg:
-            #self.req.write("<p style=\"color: red\"><strong>%s</strong></p>"
% msg)
+        except webgump.SecurityError, msg:
+            self.req.status = apache.HTTP_BAD_REQUEST
+            bust_cache(self.req)
+
+            self.req.write("<p style=\"color: red\"><strong>%s</strong></p>"
% msg)
             self.log.exception("Naughty client!", doNotLogToWebPage=True)
-            raise apache.SERVER_RETURN, apache.HTTP_BAD_REQUEST
+            return apache.OK
+        except webgump.Error, msg:
+            self.req.status = apache.HTTP_INTERNAL_SERVER_ERROR
+            bust_cache(self.req)
+
+            self.req.write("<p><strong>%s</strong></p>" % msg)
+            self.log.exception("Internal error!", doNotLogToWebPage=True)
+            return apache.OK
         except IOError:
             self.req = None
             self.log.error("Client is gone.")
@@ -50,11 +60,8 @@
                 self.log.exception("Uncaught exception!")
             except:
                 pass
-        #try:
-        #    if DEBUG:
-        #        self._debug_info()
-        #except:
-        #    pass
+        
+        #self._debug_info()
     
         if self.status:
             return self.status
@@ -76,18 +83,19 @@
         for key,val in self.req.subprocess_env.items():
             self.settings[key] = val
 
+        self.settings['TEMPLATE_ROOT'] = \
+            os.path.abspath(os.path.join(self.settings['DOCUMENT_ROOT'], "../templates"))
+        self.settings['DOCUMENTATION_ROOT'] = \
+            os.path.abspath(os.path.join(self.settings['DOCUMENT_ROOT'], "../xdocs"))
+
         query_vars = util.parse_qs(self.req.subprocess_env["QUERY_STRING"])
         self.settings['HTTP_GET_VARS'] = query_vars
         for key,val in query_vars.items():
             if key in self.settings:
-                raise SecurityError, "Illegal query parameter '%s'!" % key
+                raise webgump.SecurityError, "Illegal query parameter '%s'!" % key
             val.reverse()
             self.settings[key] = val[0]
             val.reverse()
-
-        self.settings['TEMPLATE_ROOT'] = \
-            os.path.abspath(os.path.join(self.settings['DOCUMENT_ROOT'], "../templates"))
-
     
     def _get_action(self):
         """Determine the controller to fire up."""
@@ -109,13 +117,17 @@
         else:
             raise "No action '%s' available in controller '%s'" % (action, controller)  

         
-    #def _debug_info(self):
-    #    """Write basic environment information to the web page."""
-    #    self.req.write("<hr/><p><strong>DEBUG INFO</strong></p>\n")
-    #    self.req.write("<p><em>Webapp Settings</em></p>\n<pre>")
-    #    for (key,val) in self.settings.items():
-    #        self.req.write("%s: %s\n" % (key,val))
-    #    self.req.write("</pre>")
+    def _debug_info(self):
+        """Write basic environment information to the web page."""
+        try:
+            if DEBUG:
+                self.req.write("<hr/><p><strong>DEBUG INFO</strong></p>\n")
+                self.req.write("<p><em>Webapp Settings</em></p>\n<pre>")
+                for (key,val) in self.settings.items():
+                    self.req.write("%s: %s\n" % (key,val))
+                self.req.write("</pre>")
+        except:
+            pass
 
 
 def _find_controller_module(controller):

Modified: gump/branches/Gump3/webgump/lib/python/webgump/__init__.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/webgump/lib/python/webgump/__init__.py?rev=202049&r1=202048&r2=202049&view=diff
==============================================================================
--- gump/branches/Gump3/webgump/lib/python/webgump/__init__.py (original)
+++ gump/branches/Gump3/webgump/lib/python/webgump/__init__.py Mon Jun 27 13:31:58 2005
@@ -0,0 +1,5 @@
+class Error(Exception):
+    pass
+
+class SecurityError(Error):
+    pass

Copied: gump/branches/Gump3/webgump/lib/python/webgump/controllers/doc.py (from r201976, gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/webgump/lib/python/webgump/controllers/doc.py?p2=gump/branches/Gump3/webgump/lib/python/webgump/controllers/doc.py&p1=gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py&r1=201976&r2=202049&rev=202049&view=diff
==============================================================================
--- gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py (original)
+++ gump/branches/Gump3/webgump/lib/python/webgump/controllers/doc.py Mon Jun 27 13:31:58
2005
@@ -1,26 +1,57 @@
 #!/usr/bin/env python
+import webgump
+from webgump.util.log import Logger
 from webgump.util.template import TemplateEngine
+
 from gump.util.mysql import Database
-from webgump.util.log import Logger
+
+from mod_python import apache
+import os
+from rfc822 import formatdate
+
+DEFAULT_PAGE_NAME="index.xml"
 
 def view(req, settings):
-    req.content_type = "text/html"
-    
+    log = Logger(req, name="controllers.doc")
     dblog = Logger(req, name="webgump.db")
     db = Database(dblog,settings["db_host"], settings["db_user"],
                   settings["db_password"],settings["db_name"])
     
-    (affected, rows) = db.execute('SELECT * FROM test;')
-    content = []
-    for row in rows:
-        content.append(row["content"])
+    page = DEFAULT_PAGE_NAME
+    if "page" in settings:
+        page = settings["page"]
+    
+    docroot = settings["DOCUMENTATION_ROOT"]
+    pagepath = os.path.abspath(os.path.join(docroot, page))
+    log.debug("Looking for documentation page '%s'" % pagepath)
+    if not pagepath.startswith(docroot):
+        raise webgump.SecurityError, "Requested page '%s' is illegal!" % page
+    
+    if not os.path.exists(pagepath) or not os.path.isfile(pagepath):
+        raise webgump.Error, "Requested page '%s' cannot be found!" % page
+    
+    if not os.access(pagepath, os.R_OK):
+        raise webgump.SecurityError, "Access denied to page '%s'!" % page
     
-    settings["content"] = content
-    settings["log"] = Logger(req, name="webgump.ezt")
-    template = "view"
-    template_engine = TemplateEngine(settings['TEMPLATE_ROOT'])
+    f = False
     try:
-        template_engine.render_template(template, req, settings)
-    except:
-        req.write("<p><strong>Error occurred rendering template '%s':</strong></p>\n"
% template)
-        raise
+        try:
+            lastmodified = os.path.getmtime(pagepath)
+            #req.headers_out['Last-Modified'] = formatdate(lastmodified)
+            req.mtime = lastmodified
+            #req.headers_out['X-Webgump'] = 'Test'
+            req.content_type = "text/html"
+        
+            f = open(pagepath, mode='r')
+            for line in f:
+                req.write(line)
+            
+            return apache.OK
+        except IOError:
+            raise webgump.Error, "Error reading requested page '%s'!" % page
+    finally:
+        if f:
+            try:
+                f.close()
+            except:
+                pass

Modified: gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py?rev=202049&r1=202048&r2=202049&view=diff
==============================================================================
--- gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py (original)
+++ gump/branches/Gump3/webgump/lib/python/webgump/controllers/home.py Mon Jun 27 13:31:58
2005
@@ -1,10 +1,15 @@
 #!/usr/bin/env python
+
+from webgump.util.log import Logger
 from webgump.util.template import TemplateEngine
+from webgump.util import bust_cache
+
 from gump.util.mysql import Database
-from webgump.util.log import Logger
 
 def view(req, settings):
     req.content_type = "text/html"
+    bust_cache(req)
+    req.send_http_header()
     
     dblog = Logger(req, name="webgump.db")
     db = Database(dblog,settings["db_host"], settings["db_user"],

Modified: gump/branches/Gump3/webgump/lib/python/webgump/util/__init__.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/webgump/lib/python/webgump/util/__init__.py?rev=202049&r1=202048&r2=202049&view=diff
==============================================================================
--- gump/branches/Gump3/webgump/lib/python/webgump/util/__init__.py (original)
+++ gump/branches/Gump3/webgump/lib/python/webgump/util/__init__.py Mon Jun 27 13:31:58 2005
@@ -0,0 +1,4 @@
+def bust_cache(req):
+    req.headers_out['Cache-Control'] = 'no-cache'
+    req.headers_out['Pragma'] = 'no-cache'
+    req.headers_out['Expires'] = '-1'

Copied: gump/branches/Gump3/webgump/xdocs/index.xml (from r201976, gump/branches/Gump3/dynagump/webapp/index.xml)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/webgump/xdocs/index.xml?p2=gump/branches/Gump3/webgump/xdocs/index.xml&p1=gump/branches/Gump3/dynagump/webapp/index.xml&r1=201976&r2=202049&rev=202049&view=diff
==============================================================================
--- gump/branches/Gump3/dynagump/webapp/index.xml (original)
+++ gump/branches/Gump3/webgump/xdocs/index.xml Mon Jun 27 13:31:58 2005
@@ -1,19 +1,7 @@
-<page>
-
+<?xml version="1.0"?>
+<html>
    <title>Home</title>
-      
-   <path>
-    <current name="Home"/>
-   </path>
-   
-   <tabs>
-    <item name="Results" url="results/"/>
-    <item name="Documentation" url="docs/"/>
-    <item name="Wiki" url="http://wiki.apache.org/gump/"/>
-    <current name="Home"/>
-   </tabs>
-   
-   <content>
+   <body>
      <h1>Welcome to Apache Gump!</h1>
 <p>Gump is Apache's continuous integration tool. It is written in
 python
@@ -42,6 +30,5 @@
 lot of material is still available on
 <a href="http://gump.apache.org/">our main website</a> only. Also make
 sure to take a look at the <a href="http://wiki.apache.org/gump">wiki</a>.</p>
-   </content>
-   
-</page>
+   </body>
+</html>



Mime
View raw message