comparison requestdumpster/dumpster.py @ 7:83c51f45b82d

optparse -> argparse and the like
author Jeff Hammel <k0scist@gmail.com>
date Wed, 16 Dec 2015 10:31:00 -0800
parents aa19f80caa63
children eb260393caef
comparison
equal deleted inserted replaced
6:aa19f80caa63 7:83c51f45b82d
3 """ 3 """
4 dump HTTP requests 4 dump HTTP requests
5 """ 5 """
6 6
7 # imports 7 # imports
8 import optparse 8 import argparse
9 import os 9 import os
10 import sys 10 import sys
11 import time 11 import time
12 import wsgiref 12 import wsgiref
13 13
28 28
29 def main(args=sys.argv[1:]): 29 def main(args=sys.argv[1:]):
30 """CLI""" 30 """CLI"""
31 31
32 # parse command line arguments 32 # parse command line arguments
33 parser = optparse.OptionParser(description=__doc__) 33 parser = argparse.ArgumentParser(description=__doc__)
34 parser.add_option('-p', '--port', dest='port', 34 parser.add_argument('-p', '--port', dest='port',
35 type='int', default=9555, 35 type=int, default=9555,
36 help="port to serve on") 36 help="port to serve on")
37 parser.add_option('-d', '--directory', dest='directory', 37 parser.add_argument('-d', '--directory', dest='directory',
38 help="directory to output requests to") 38 help="directory to output requests to")
39 options = parser.parse_args() 39 options = parser.parse_args()
40 40
41 # instantiate WSGI app 41 # instantiate WSGI app
42 app = RequestDumpster(directory=options.directory) 42 app = RequestDumpster(directory=options.directory)
43 43
44 # construct url 44 # construct url
45 url = 'http://localhost:{port}/'.format(port=options.port) 45 url = 'http://localhost:{port}/'.format(port=options.port)
46 46
47 # serve some web 47 # serve some web
48 server = simple_server.make_server(host=host, port=int(port), app=app) 48 server = simple_server.make_server(host=host, port=int(port), app=app)
49 server.serve_forever() 49 print url
50 try:
51 server.serve_forever()
52 except KeyboardInterrupt:
53 pass
54
50 55
51 if __name__ == '__main__': 56 if __name__ == '__main__':
52 main() 57 main()