From: W. Trevor King Date: Sat, 25 Aug 2012 13:54:17 +0000 (-0400) Subject: Add --port option to gallery.py. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5e859fdb4efe51bc31db6ecef294aa325519a982;p=blog.git Add --port option to gallery.py. Also make the option defaults simpler. --- diff --git a/posts/gallery/gallery.py b/posts/gallery/gallery.py index 7746061..34a51ce 100755 --- a/posts/gallery/gallery.py +++ b/posts/gallery/gallery.py @@ -187,7 +187,7 @@ class CGIGalleryServer (object): self._error(404, stream=stream) path = _os_path.join(self._base_path, url) if _os_path.exists(path) and not _os_path.isdir(path): - LOG.error('nonexstand directory') + LOG.error('nonexistent directory') self._error(404, stream=stream) def serve(self, url=None, page=0, stream=None): @@ -201,7 +201,7 @@ class CGIGalleryServer (object): elif self.is_cached(url=url): self.cached(url=url, stream=stream) elif url.endswith('.png'): - self.thumb(url=url, stream=stream) + self._thumb(url=url, stream=stream) else: self.validate_url(url=url, stream=stream) self.page(url=url, page=page, stream=stream) @@ -628,7 +628,7 @@ def serve_cgi(server): pass server.serve(url=url, page=page, stream=sys.stdout) -def serve_scgi(server, port=4000): +def serve_scgi(server, host='localhost', port=4000): import scgi import scgi.scgi_server import urlparse @@ -655,23 +655,28 @@ def serve_scgi(server, port=4000): server.serve(url=url, page=page, stream=output) s = scgi.scgi_server.SCGIServer( - handler_class=GalleryHandler, host='localhost', port=port) - LOG.info('serving SCGI') + handler_class=GalleryHandler, host=host, port=port) + LOG.info('serving SCGI on {}:{}'.format(host, port)) s.serve() if __name__ == '__main__': import argparse as _argparse - parser = _argparse.ArgumentParser(description=__doc__, version=__version__) + parser = _argparse.ArgumentParser( + description=__doc__, version=__version__, + formatter_class=_argparse.RawDescriptionHelpFormatter) parser.add_argument( '--scgi', default=False, action='store_const', const=True, help='Run as a SCGI server (vs. serving a single CGI call)') parser.add_argument( - '--base-path', default='/var/www/localhost/htdocs/gallery/', + '--port', default=4000, type=int, + help='Port to listen to (if runing as a SCGI server)') + parser.add_argument( + '--base-path', default='.', help='Path to the root gallery source') parser.add_argument( - '--base-url', default='/gallery/', + '--base-url', default='/', help='URL for the root gallery source') parser.add_argument( '--shared-path', default=None, @@ -692,6 +697,6 @@ if __name__ == '__main__': s.footer = [open(_os_path.join(shared, 'footer.shtml'), 'r').read()] if args.scgi: - serve_scgi(server=s) + serve_scgi(server=s, port=args.port) else: serve_cgi(server=s)