File: util.py

package info (click to toggle)
quixote 2.4-5.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,016 kB
  • ctags: 1,078
  • sloc: python: 5,707; ansic: 1,418; makefile: 86; sh: 78
file content (32 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/quixote/server/util.py $
$Id: util.py 26427 2005-03-30 18:03:32Z dbinger $

Miscellaneous utility functions shared by servers.
"""

from optparse import OptionParser
from quixote.util import import_object

def get_server_parser(doc):
    parser = OptionParser()
    parser.set_description(doc)
    default_host = 'localhost'
    parser.add_option(
        '--host', dest="host", default=default_host, type="string",
        help="Host interface to listen on. (default=%s)" % default_host)
    default_port = 8080
    parser.add_option(
        '--port', dest="port", default=default_port, type="int",
        help="Port to listen on. (default=%s)" % default_port)
    default_factory = 'quixote.demo.create_publisher'
    parser.add_option(
        '--factory', dest="factory",
        default=default_factory,
        help="Path to factory function to create the site Publisher. "
             "(default=%s)" % default_factory)
    return parser

def main(run):
    parser = get_server_parser(run.__doc__)
    (options, args) = parser.parse_args()
    run(import_object(options.factory), host=options.host, port=options.port)