source: trunk/contrib/test_server.py @ 1361

Last change on this file since 1361 was 1328, checked in by gogo, 6 years ago

Dummy commit to check things are working.

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/python
2
3"""Runs a very basic file server so that we can test Xinha.  By default, the
4server runs on port 8080, but you can pass the -p or --port option to change
5the port used."""
6
7import os
8import SimpleHTTPServer
9import SocketServer
10
11# File server for testing Xinha
12
13def __main():
14    """Use the embed_url.py program from the command-line
15
16    The embed_url.py program downloads files and processes links in the case of
17    HTML files.  See embed_url.py -h for more info.  This procedure has the
18    sole purpose of reading in and verifying the command-line arguments before
19    passing them to the embed_url funtion."""
20
21    from getopt import getopt, GetoptError
22    from sys import argv, exit, stderr
23
24    try:
25        options, arguments = getopt(argv[1:], "p:", ["port="])
26    except GetoptError:
27        print "Invalid option"
28        __usage()
29        exit(2)
30
31    PORT = 8080
32    for option, value in options:
33        if option in ("-p", "--port"):
34            try:
35                PORT = int(value)
36            except ValueError:
37                print "'%s' is not a valid port number" % value
38                __usage()
39                exit(2)
40
41    # SimpleHTTPRequestHandler serves data from the current directory, so if we
42    # are running from inside contrib, we have to change our current working
43    # directory
44    if os.path.split(os.getcwd())[1] == 'contrib':
45        os.chdir('..')
46
47    Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
48
49    httpd = SocketServer.TCPServer(("", PORT), Handler)
50
51    print "Serving at port %s" % PORT
52    print "Try viewing the example at http://localhost:%s/examples/Newbie.html" % PORT
53    httpd.serve_forever()
54
55def __usage():
56    """
57    Print the usage information contained in the module docstring
58    """
59    print __doc__
60
61if __name__ == '__main__':
62    __main()
Note: See TracBrowser for help on using the repository browser.