Permalink
Browse files

Added Cherry Py Webserver

  • Loading branch information...
1 parent f125ade commit 2695224904a299933b55795609d3ec8a070d6a30 Lakshmi Vyasarajan committed Feb 2, 2009
Showing with 70 additions and 27 deletions.
  1. +1 −0 .gitignore
  2. +12 −3 hyde.py
  3. +56 −23 hydeengine/__init__.py
  4. +1 −1 templates/default/settings.py
View
@@ -4,3 +4,4 @@
deploy/*
*.cprof
*.profile
+*.log
View
@@ -1,8 +1,8 @@
#!/usr/bin/env python2
import os, sys
from optparse import OptionParser
-from hydeengine import Generator
-from hydeengine import Initializer
+from hydeengine import Generator, Initializer, Server
+
#import cProfile
PROG_ROOT = os.path.dirname(os.path.abspath( __file__ ))
@@ -21,7 +21,9 @@ def main(argv):
dest = "generate", default = False)
parser.add_option("-d", "--deploy_to",
dest = "deploy_to")
-
+ parser.add_option("-w", "--webserve", action = "store_true",
+ dest = "webserve", default = False)
+
(options, args) = parser.parse_args()
if len(args):
@@ -43,6 +45,13 @@ def main(argv):
generator.generate(options.deploy_to)
except ValueError, err:
parser.error(err)
+ if options.webserve:
+ server = Server(options.site_path)
+ try:
+ server.serve(options.deploy_to)
+ except ValueError, err:
+ parser.error(err)
+
if __name__ == "__main__":
main(sys.argv[1:])
@@ -8,36 +8,69 @@
from folders import MediaFolder, ContentFolder, TempFolder
from renderer import build_sitemap, render_pages
+def setup_env(site_path):
+ try:
+ imp.load_source("hyde_site_settings",
+ os.path.join(site_path,"settings.py"))
+ except Exception, err:
+ print "Cannot Import Site Settings"
+ print err
+ raise ValueError(
+ "The given site_path [%s] does not contain a hyde site. \
+ Give a valid path or run -init to create a new site."
+ % site_path
+ )
+
+ try:
+ os.environ['DJANGO_SETTINGS_MODULE'] = u"hyde_site_settings"
+ except Exception, err:
+ print "Site settings are not defined properly"
+ print err
+ raise ValueError(
+ "The given site_path [%s] has invalid settings. \
+ Give a valid path or run -init to create a new site."
+ % site_path
+ )
+
+class Server(object):
+ def __init__(self, site_path):
+ super(Server, self).__init__()
+ self.site_path = os.path.abspath(os.path.expandvars(
+ os.path.expanduser(site_path)))
+ def serve(self, deploy_path):
+ setup_env(self.site_path)
+ deploy_folder = Folder(
+ (deploy_path, settings.DEPLOY_DIR)
+ [not deploy_path])
+ import cherrypy
+ from cherrypy.lib.static import serve_file
+
+ class WebRoot:
+ @cherrypy.expose
+ def index(self):
+ if not 'site' in settings.CONTEXT:
+ build_sitemap()
+ page = settings.CONTEXT['site'].listing_page
+ return serve_file(deploy_folder.child(page.name))
+
+ cherrypy.config.update({'environment': 'production',
+ 'log.error_file': 'site.log',
+ 'log.screen': True})
+ conf = {'/': {
+ 'tools.staticdir.dir': deploy_folder.path,
+ 'tools.staticdir.on':True
+ }}
+ cherrypy.quickstart(WebRoot(), '/', config = conf)
+
+
class Generator(object):
def __init__(self, site_path):
super(Generator, self).__init__()
self.site_path = os.path.abspath(os.path.expandvars(
os.path.expanduser(site_path)))
def generate(self, deploy_path):
- try:
- imp.load_source("hyde_site_settings",
- os.path.join(self.site_path,"settings.py"))
- except Exception, err:
- print "Cannot Import Site Settings"
- print err
- raise ValueError(
- "The given site_path [%s] does not contain a hyde site. \
- Give a valid path or run -init to create a new site."
- % self.site_path
- )
-
- try:
- os.environ['DJANGO_SETTINGS_MODULE'] = u"hyde_site_settings"
- except Exception, err:
- print "Site settings are not defined properly"
- print err
- raise ValueError(
- "The given site_path [%s] has invalid settings. \
- Give a valid path or run -init to create a new site."
- % self.site_path
- )
-
+ setup_env(self.site_path)
tmp_folder = Folder(settings.TMP_DIR)
deploy_folder = Folder(
(deploy_path, settings.DEPLOY_DIR)
@@ -26,7 +26,7 @@
# should specify css/ie for the folder name. css/* is not supported (yet).
# Extensions do not support wildcards.
-GENERATE_ABSOLUTE_FS_URLS = True
+GENERATE_ABSOLUTE_FS_URLS = False
MEDIA_PROCESSORS = {
'*':{

0 comments on commit 2695224

Please sign in to comment.