Add --port option to gallery.py.
authorW. Trevor King <wking@tremily.us>
Sat, 25 Aug 2012 13:54:17 +0000 (09:54 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 25 Aug 2012 13:54:17 +0000 (09:54 -0400)
Also make the option defaults simpler.

posts/gallery/gallery.py

index 774606129619d5d9b25354f65a77b89f68e0d623..34a51cee71062027b7495cdd4b09189ab583f3d5 100755 (executable)
@@ -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)