#!/usr/bin/env python

import hf, cherrypy
import os, logging
import ConfigParser

logger = logging.getLogger(__name__)

if __name__ == '__main__':
    hf.hf_dir = os.path.dirname(os.path.abspath(__file__))
    hf.configtools.readConfigurationAndEnv()
    hf.configtools.setupLogging('render_logging_cfg')
    cp_config = {}
    for section in hf.config.sections():
        if section == "global" or section.startswith("/"):
            config = dict(hf.config.items(section))
            for key,val in config.iteritems():
                try:
                    config[key] = eval(val)
                except ValueError:
                    pass
            cp_config[section] = config
    cherrypy.config.update(cp_config)
    
    hf.configtools.importModules()
    
    hf.database.connect(implicit_execution = True)
    
    cherrypy.quickstart(root=hf.dispatcher.CategoryDispatcher(), script_name="/", config=cp_config)
    hf.database.disconnect()
    
@@ -16,16 +16,143 @@
 python%0A%0A
+import os,sys%0Aprint sys.path%0Aprint os.getcwd()%0Aos.chdir(os.path.dirname(__file__))%0Asys.path.append(os.path.dirname(__file__))%0A%0A
 import h
@@ -162,26 +162,16 @@
 cherrypy
-%0Aimport os
 , loggin
@@ -191,16 +191,30 @@
 igParser
+%0Aimport atexit
 %0A%0Alogger
@@ -249,39 +249,9 @@
 _)%0A%0A
-if __name__ == '__main__':%0A    
+%0A
 hf.h
@@ -301,20 +301,16 @@
 ile__))%0A
-    
 hf.confi
@@ -342,20 +342,16 @@
 ndEnv()%0A
-    
 hf.confi
@@ -392,20 +392,16 @@
 g_cfg')%0A
-    
 cp_confi
@@ -407,20 +407,16 @@
 ig = %7B%7D%0A
-    
 for sect
@@ -440,28 +440,24 @@
 sections():%0A
-    
     if secti
@@ -503,28 +503,24 @@
 %22):%0A        
-  
-  
 config = dic
@@ -555,20 +555,16 @@
         
-    
 for key,
@@ -606,21 +606,13 @@
     
- 
-   
 try:%0A
-    
     
@@ -659,20 +659,16 @@
         
-    
 except V
@@ -678,20 +678,16 @@
 eError:%0A
-    
         
@@ -707,20 +707,16 @@
         
-    
 cp_confi
@@ -735,20 +735,16 @@
  config%0A
-    
 cherrypy
@@ -769,25 +769,17 @@
 config)%0A
-    %0A    
+%0A
 hf.confi
@@ -801,25 +801,17 @@
 dules()%0A
-    %0A    
+%0A
 hf.datab
@@ -849,20 +849,43 @@
 = True)%0A
-    
+%0Aif __name__ == '__main__':
 %0A    che
@@ -1006,12 +1006,355 @@
 nnect()%0A
-    
+else:%0A    cherrypy.config.update(%7B'environment': 'embedded'%7D)%0A    if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:%0A        cherrypy.engine.start(blocking=False)%0A        atexit.register(cherrypy.engine.stop)%0A    application = cherrypy.Application(root=hf.dispatcher.CategoryDispatcher(), script_name=%22/%22, config=cp_config)%0A

Make render.py compatible for apache mod_wsgi