#!/usr/local/bin/python """This is the main aspen callable. It configures and starts an HTTP server. Roadmap: 0.3 -- WSGI 0.x -- alpha quality, no 0.x.x, just 0.x, as many as we need 1.0c1 -- release candidate 1.0.0 -- final """ import logging import os import sys from optparse import OptionError from os.path import join from aspen.server import CherryPyWSGIServer as Server from aspen.config import ConfigError, Configuration, usage from aspen.website import Website log = logging.getLogger('aspen') def main(argv): # Configure. # ========== try: config = Configuration(argv) website = Website(config) except ConfigError, err: print >> sys.stderr, usage print >> sys.stderr, err.msg raise SystemExit(2) # Wrap the website in a WSGI stack and serve it. # ============================================== for app in config.middleware: website = app(website) server = Server(config.address, website) try: print "aspen starting on %s" % str(config.address) #log.info("aspen starting on %s" % str(config.address)) server.start() except KeyboardInterrupt: print "stopping server" #log.info("stopping server") server.stop() # Stuff that needs to be (re-)implemented # ======================================= # # if config.daemonize: # raise NotImplementedError("No daemonization yet") # import daemon # daemon.become(workdir=config.paths.root) # # if config.log_access is not None: # raise NotImplementedError("Sorry, no access logging yet :(") # # if config.log_error is not None: # d,f = os.path.split(config.log_error) # if not os.path.isdir(d): # os.makedirs(d) # sys.stdout = sys.stderr = open(config.log_error, 'a+', 0) # # if config.uid: # raise NotImplementedError("Need to reimplement user switching") # For profiling # ============= # # import hotshot, hotshot.stats # prof = hotshot.Profile("bench.prof") # # try: # prof.runcall(server.start) # except KeyboardInterrupt: # server.stop() # # prof.close() # stats = hotshot.stats.load("bench.prof") # stats.strip_dirs() # stats.sort_stats('time', 'calls') # stats.print_stats(20) if __name__ == '__main__': main(sys.argv[1:])