# HG changeset patch # User Jeff Hammel # Date 1350494308 25200 # Node ID 5babc2ae6c27e0b8e93df0e23cb2608c8b43c29a # Parent 235738f81a3d9f543f96b9d26544a2ff00e532e4 more stubbing diff -r 235738f81a3d -r 5babc2ae6c27 dogdish/dispatcher.py --- a/dogdish/dispatcher.py Wed Oct 17 10:08:14 2012 -0700 +++ b/dogdish/dispatcher.py Wed Oct 17 10:18:28 2012 -0700 @@ -10,9 +10,21 @@ from urlparse import urlparse from webob import Request from webob import Response, exc +from ConfigParser import RawConfigParser as ConfigParser here = os.path.dirname(os.path.abspath(__file__)) + +class Application(object): + """class for storing application.ini data""" + + def __init__(self, filename): + """ + - filename : path to an application.ini file + """ + +### request handlers + class Handler(object): """abstract handler object for a request""" @@ -75,12 +87,20 @@ defaults = {'directory': here} def __init__(self, **kw): + + # set defaults for key in self.defaults: setattr(self, key, kw.get(key, self.defaults[key])) self.handlers = [ Get ] + self.updates = {} + self.current_update = None - ### methods dealing with HTTP + # scan directory + self.scan() + def __call__(self, environ, start_response): + """WSGI application""" + request = Request(environ) for h in self.handlers: if h.match(request): @@ -91,21 +111,32 @@ res = handler() return res(environ, start_response) + def scan(self): + """scan the directory for updates""" + contents = os.listdir(self.directory) + + def main(args=sys.argv[1:]): """CLI entry point""" + # imports for CLI import optparse from wsgiref import simple_server + # parse CLI options parser = optparse.OptionParser() - parser.add_option('-p', '--port', dest='port', default=8080, type='int', help="port to serve on") + parser.add_option('-d', '--directory', dest='directory', + default=os.getcwd(), + help="directory of update files") options, args = parser.parse_args() - app = Dispatcher() + # create the app + app = Dispatcher(directory=options.directory) + # serve the app print "http://localhost:%s/" % options.port server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app) server.serve_forever()