Mercurial > hg > decoupage
comparison decoupage/cli.py @ 107:450aff4c97e3
py35 compat
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 31 Mar 2017 17:06:59 -0700 |
parents | c382bdd01751 |
children |
comparison
equal
deleted
inserted
replaced
106:1f84c6def8bd | 107:450aff4c97e3 |
---|---|
16 from .formatters import Datestamp, Sort, Up, DirectoryIndicator | 16 from .formatters import Datestamp, Sort, Up, DirectoryIndicator |
17 from .web import Decoupage | 17 from .web import Decoupage |
18 from wsgiref import simple_server | 18 from wsgiref import simple_server |
19 | 19 |
20 here = os.path.dirname(os.path.realpath(__file__)) | 20 here = os.path.dirname(os.path.realpath(__file__)) |
21 | |
21 | 22 |
22 class DecoupageServer(Decoupage): | 23 class DecoupageServer(Decoupage): |
23 """serve locally with decoupage""" | 24 """serve locally with decoupage""" |
24 # TODO: deprecate; move Decoupage to a few classes | 25 # TODO: deprecate; move Decoupage to a few classes |
25 # with more flexible formatters | 26 # with more flexible formatters |
79 | 80 |
80 # create server | 81 # create server |
81 # TODO: allow choice amongst server classes | 82 # TODO: allow choice amongst server classes |
82 printable_address = '127.0.0.1' if options.address == '0.0.0.0' else options.address | 83 printable_address = '127.0.0.1' if options.address == '0.0.0.0' else options.address |
83 server = simple_server.make_server(options.address, options.port, app) | 84 server = simple_server.make_server(options.address, options.port, app) |
84 print 'serving directory %s ( %s ) at \nhttp://%s:%d/' % (directory, | 85 print("""serving directory {directory} ( file://{directory} ) at |
85 'file://' + directory, # XXX | 86 http://{hostname}:{port}/'""".format(directory=directory, |
86 printable_address, | 87 hostname=printable_address, |
87 options.port) | 88 port=options.port)) |
89 | |
88 if options.print_ip: | 90 if options.print_ip: |
89 # from http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib | 91 # from http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib |
90 hostname = "google.com" | 92 hostname = "google.com" |
91 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | 93 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
92 s.connect((hostname,80)) | 94 s.connect((hostname,80)) |
93 hostname = s.getsockname()[0] | 95 hostname = s.getsockname()[0] |
94 print "http://%s:%s/" % (hostname, options.port) | 96 print ("http://{hostname}:{port}/".format(hostname=hostname, port=options.port)) |
95 s.close() | 97 s.close() |
96 | 98 |
97 # serve directory contents via decoupage | 99 # serve directory contents via decoupage |
98 try: | 100 try: |
99 server.serve_forever() | 101 server.serve_forever() |
100 except KeyboardInterrupt: | 102 except KeyboardInterrupt: |
101 pass | 103 pass |
102 | 104 |
105 | |
103 if __name__ == '__main__': | 106 if __name__ == '__main__': |
104 main() | 107 main() |