Commits

Robert Brewer committed 43f277b

New scaffold folder. See #771.

Comments (0)

Files changed (4)

cherrypy/scaffold/__init__.py

+"""<MyProject>, a CherryPy application."""
+
+import cherrypy
+from cherrypy import tools, url
+
+import os
+local_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
+
+
+class Root:
+    
+    _cp_config = {'tools.log_tracebacks.on': True,
+                  }
+    
+    def index(self):
+        return """<html>
+<body>Try some <a href='%s?a=7'>other</a> path,
+or a <a href='%s?n=14'>default</a> path.<br />
+Or, just look at the pretty picture:<br />
+<img src='%s' />
+</body></html>""" % (url("other"), url("else"),
+                     url("files/made_with_cherrypy_small.png"))
+    index.exposed = True
+    
+    def default(self, *args, **kwargs):
+        return "args: %s kwargs: %s" % (args, kwargs)
+    default.exposed = True
+    
+    def other(self, a=2, b='bananas', c=None):
+        cherrypy.response.headers['Content-Type'] = 'text/plain'
+        if c is None:
+            return "Have %d %s." % (int(a), b)
+        else:
+            return "Have %d %s, %s." % (int(a), b, c)
+    other.exposed = True
+    
+    files = cherrypy.tools.staticdir.handler(
+                section="/files",
+                dir=os.path.join(local_dir, "static"),
+                # Ignore .php files, etc.
+                match=r'\.(css|gif|html?|ico|jpe?g|js|png|swf|xml)$',
+                )
+
+
+root = Root()
+
+# Uncomment the following to use your own favicon instead of CP's default.
+#favicon_path = os.path.join(local_dir, "favicon.ico")
+#root.favicon_ico = tools.staticfile.handler(filename=favicon_path)

cherrypy/scaffold/cpdeploy.py

+#! /usr/bin/env python
+"""Deployment script for <MyProject> (a CherryPy application)."""
+
+import os
+local_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
+
+import cherrypy
+from cherrypy.restsrv.plugins import Daemonizer, PIDFile
+
+# TODO: Change this to import your project root.
+from cherrypy import scaffold
+
+
+if __name__ == "__main__":
+    from optparse import OptionParser
+    
+    p = OptionParser()
+    p.add_option('-c', '--config', dest='config_file',
+                 help="specify a config file")
+    p.add_option('-D', '--daemonize', action="store_true", dest='daemonize',
+                 help="run the server as a daemon")
+    options, args = p.parse_args()
+    cherrypy.config.update(options.config_file)
+    
+    # Only daemonize if asked to.
+    if options.daemonize:
+        # Don't print anything to stdout/sterr.
+        cherrypy.config.update({'log.screen': False})
+        
+        d = Daemonizer(cherrypy.engine)
+        d.subscribe()
+    
+    pidfile = cherrypy.config.get('pidfile')
+    if pidfile:
+        PIDFile(cherrypy.engine, pidfile).subscribe()
+    
+    # You can replace the next 4 lines with:
+    # cherrypy.quickstart(scaffold.root, "/", options.config_file)
+    cherrypy.signal_handler.subscribe()
+    cherrypy.tree.mount(scaffold.root, "/", options.config_file)
+    cherrypy.engine.start()
+    cherrypy.engine.block()
+

cherrypy/scaffold/example.conf

+[global]
+# Uncomment this when you're done developing
+#environment: "production"
+
+server.socket_host: "0.0.0.0"
+server.socket_port: 8088
+
+
+[/]
+log.error_file: "error.log"
+log.access_file: "access.log"

cherrypy/scaffold/static/made_with_cherrypy_small.png

Added
New image