File: dot.py

package info (click to toggle)
python-path-and-address 2.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 124 kB
  • sloc: python: 214; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (4)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""\
Usage:
  dot.py [options] [<path>] [<address>]
  dot.py -h | --help
  dot.py --version

Where:
  <path> is the file to serve
  <address> is what to listen on, of the form <host>[:<port>], or just <port>
"""

import sys
from docopt import docopt
from path_and_address import resolve, split_address


def main(args=None):
    """The entry point of the application."""
    if args is None:
        args = sys.argv[1:]

    # Parse command-line
    args = docopt(__doc__, argv=args)

    # Parse arguments
    path, address = resolve(args['<path>'], args['<address>'])
    host, port = split_address(address)

    # Validate arguments
    if address and not (host or port):
        print 'Error: Invalid address', repr(address)
        return

    # Default values
    if path is None:
        path = '.'
    if host is None:
        host = 'localhost'
    if port is None:
        port = 5000

    # Run server
    print ' * Serving %s on http://%s:%s/' % (path, host, port)


if __name__ == '__main__':
    main()