# HG changeset patch # User Jeff Hammel # Date 1322208075 28800 # Node ID 8729685a2cf6d3602c77a1e9401c07e81b7c6dbd # Parent d3e3a506dd29645645afe5a35c195e83296a0168 stub web interface diff -r d3e3a506dd29 -r 8729685a2cf6 licenser/licenses.py --- a/licenser/licenses.py Thu Nov 24 15:29:05 2011 -0800 +++ b/licenser/licenses.py Fri Nov 25 00:01:15 2011 -0800 @@ -74,7 +74,7 @@ if self.isempty(): return # you're done lines = self.lines() - + # open the file for writing f = file(self.filename, 'w') @@ -138,6 +138,12 @@ filetypes = [HashCommentsFile, AsteriskCommentsFile] +def filetypes_string(filetypes=filetypes[:]): + extensions = set() + for filetype in filetypes: + extensions.update(filetype.extensions) + return ', '.join([i for i in extensions]) + class License(object): """Abstract base class for a license""" @@ -151,7 +157,7 @@ self.template) assert os.path.exists(self.template) self.filetypes = filetypes - + def license(self): return file(self.template).read() diff -r d3e3a506dd29 -r 8729685a2cf6 licenser/web.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/licenser/web.py Fri Nov 25 00:01:15 2011 -0800 @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +""" +web handler for MPL licenser +""" + +import licenses +from webob import Request, Response, exc + +class Handler(object): + + required = set(['name', 'email', 'url']) + + template = """ +MPL licenser + +

MPL Licenser

+
license your files with MPL. Currently works for files of type: %(filetypes)s
+
+

Enter a file:

+

or a URL:

+

And enter your name:

+

and email:

+ + +""" + + def __init__(self, **kw): + self.methods = {'GET': self.GET, + 'POST': self.POST} + + def __call__(self, environ, start_response): + request = Request(environ) + if request.method in self.methods: + response = self.methods[request.method](request) + else: + response = exc.HTTPMethodNotAllowed() + return response(environ, start_response) + + def GET(self, request): + variables = {} + for i in self.required: + if i in request.GET: + variables[i] = request.GET[i] + if set(variables.keys()) == self.required: + try: + pass + except: + pass + return self.render(**variables) + + def render(self, **variables): + for i in self.required: + if i not in variables: + variables[i] = '' + variables['filetypes'] = licenses.filetypes_string() + return Response(content_type='text/html', body=(self.template % variables)) + + def POST(self, request): + pass + +if __name__ == '__main__': + from wsgiref import simple_server + app = Handler() + server = simple_server.make_server(host='0.0.0.0', port=8080, app=app) + server.serve_forever() +