qmsk/web/args.py
changeset 92 e5799432071c
equal deleted inserted replaced
91:292b26405ee7 92:e5799432071c
       
     1 import werkzeug.serving
       
     2 import argparse
       
     3 
       
     4 import logging; log = logging.getLogger('qmsk.web.args')
       
     5 
       
     6 def options (parser, static=None) :
       
     7     """
       
     8         Command-line options.
       
     9     """
       
    10 
       
    11     parser = parser.add_argument_group("qmsk.web")
       
    12 
       
    13     parser.add_argument('--web-static', metavar='PATH', default=static,
       
    14             help="Path to static files")
       
    15 
       
    16     parser.add_argument('--web-debug', action='store_true',
       
    17             help="Web-based debugger")
       
    18 
       
    19     return parser
       
    20 
       
    21 def apply (options, application_class, *args, **opts):
       
    22     """
       
    23         Build given qmsk.web.Application from options.
       
    24     """
       
    25 
       
    26     return application_class(*args,
       
    27             **opts
       
    28     )
       
    29 
       
    30 def main (options, application) :
       
    31     """
       
    32         Run given WSGI application via the werkzeug development server.
       
    33     """
       
    34 
       
    35     static_files = { }
       
    36 
       
    37     if options.web_static:
       
    38         static_files['/static'] = options.web_static
       
    39 
       
    40     log.info("http://0.0.0.0:8080/")
       
    41     werkzeug.serving.run_simple('0.0.0.0', 8080, application,
       
    42             use_debugger    = options.web_debug,
       
    43             static_files    = static_files,
       
    44     )
       
    45 
       
    46     return 0