Assorted fixes to work with Python 2.5 and CherryPy 2.3
[cookbook.git] / bin / cook.py
index 2a994712ffd2a76cb4940862bfd67095d4a1306e..ab9f774b11285253f79614bab9fa2be7f214caa8 100755 (executable)
@@ -25,6 +25,7 @@ from cookbook.mom import MomParser
 from cookbook.cookbook import test as test_cookbook
 
 try:
+    import jinja2
     import cherrypy
     from cookbook.server import Server
     from cookbook.server import test as test_server
@@ -81,15 +82,29 @@ if __name__ == '__main__':
         template_dir = os.path.join(module_dir, 'template')
         config = os.path.join(module_dir, 'config')
         s = Server(c, template_dir)
-        cherrypy.config.update({ # http://www.cherrypy.org/wiki/ConfigAPI
-                'server.socket_host': options.address,
-                'server.socket_port': int(options.port),
-                'tools.encode.on': True,
-                'tools.encode.encoding': 'utf8',
-                'tools.staticdir.root': static_dir
-                })
-        app_config = { '/static': { 'tools.staticdir.on': True,
-                                    'tools.staticdir.dir': '', } }
-        cherrypy.quickstart(root=s, config=app_config)
-        sys.stderr.write('Saving cookbook\n')
+        if cherrypy.__version__.startswith('3.'):
+            cherrypy.config.update({ # http://www.cherrypy.org/wiki/ConfigAPI
+                    'server.socket_host': options.address,
+                    'server.socket_port': int(options.port),
+                    'tools.encode.on': True,
+                    'tools.encode.encoding': 'utf8',
+                    'tools.staticdir.root': static_dir,
+                    })
+            app_config = { '/static': { 'tools.staticdir.on': True,
+                                        'tools.staticdir.dir': '', } }
+            cherrypy.quickstart(root=s, config=app_config)
+        elif cherrypy.__version__.startswith('2.'):
+            cherrypy.root = s
+            cherrypy.config.update({
+                    'server.environment': 'production',
+                    'server.socket_host': options.address,
+                    'server.socket_port': int(options.port),
+                    'encoding_filter.on': True,
+                    'encodinf_filter.encoding': 'utf8',
+                    'static_filter.on': True,
+                    'static_filter.dir': static_dir,
+                    })
+            import pprint
+            pprint.pprint(cherrypy.config.configs)
+            cherrypy.server.start()
         s.cleanup()