Mercurial > mozilla > hg > dogfood
changeset 11:5babc2ae6c27
more stubbing
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 17 Oct 2012 10:18:28 -0700 |
parents | 235738f81a3d |
children | 234c2427e52b |
files | dogdish/dispatcher.py |
diffstat | 1 files changed, 34 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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()