Commits

Michael Schurter committed 4bded1e

Add daemon options to start librarypaste on alternate base urls, ports, & ips

Comments (0)

Files changed (1)

librarypaste/daemon.py

 #!/usr/bin/env python
 # encoding: utf-8
+import os
+import optparse
 
-import os
 import cherrypy
+
 from pastebin import BASE, PasteBinPage
 from jsonstore import JsonDataStore
 
+def getopts():
+    repo = os.path.join(os.getcwd(), 'repo')
+
+    parser = optparse.OptionParser()
+    parser.add_option('-p', '--port', dest='port', default=8080, type="int",
+            help='Listen on PORT')
+    parser.add_option('-H', '--host', dest='host', default='0.0.0.0',
+            help='Listen on HOST')
+    parser.add_option('-b', '--base', dest='base', default='',
+            help='Base URL to serve from (aka script_name)')
+    parser.add_option('-r', '--repo', dest='repo', default=repo,
+            help='Path to repository')
+    options, args = parser.parse_args()
+
+    if options.base and options.base[0] != '/':
+        options.base = '/%s' % options.base
+
+    return options
+
 def main():
-    repo = os.path.join(os.getcwd(), 'repo')
-    ds = JsonDataStore(repo)
+    opts = getopts()
+    ds = JsonDataStore(opts.repo)
+
     # Cherrypy configuration here
     app_conf = {
+        'global': {
+            'server.socket_port': opts.port,
+            'server.socket_host': opts.host,
+        },
         '/static' : {
             'tools.staticdir.on' : True,
             'tools.staticdir.dir' : os.path.join(BASE, 'static'),
         },
-        'repo' : {'path' : repo},
+        'repo' : {'path' : opts.repo},
         'datastore' : {'datastore' : ds, 'type' : 'json'},
         'lexers' : {'favorites' : ['python']},
     }
 
-    cherrypy.quickstart(PasteBinPage(), '/paste', config=app_conf)
+    cherrypy.quickstart(PasteBinPage(), opts.base, config=app_conf)
 
 if __name__ == '__main__':
     '''Useful for development mode'''