File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ """odmlView
2
+
3
+ odmlView sets up a minimal webserver and serves
4
+ and renders odml files locally from the directory
5
+ the server is started in.
6
+
7
+ Usage: odmlView [-d DIRECTORY] [-p PORT]
8
+
9
+ Options:
10
+ -p PORT Port the server will use.
11
+ Default is port 8000.
12
+ -h --help Show this screen.
13
+ --version Show version.
14
+ """
15
+
16
+ import http .server as hs
17
+ import socketserver
18
+ import sys
19
+ import webbrowser
20
+
21
+ from docopt import docopt
22
+
23
+ PORT = 8000
24
+
25
+
26
+ def run (port = PORT ):
27
+ handler = hs .SimpleHTTPRequestHandler
28
+ # files with odML extensions should be interpreted as XML
29
+ handler .extensions_map .update ({'.odml' : 'application/xml' })
30
+
31
+ server_address = ('' , port )
32
+
33
+ with socketserver .TCPServer (server_address , handler ) as httpd :
34
+ webbrowser .open_new_tab ('http://localhost:%s' % port )
35
+ try :
36
+ httpd .serve_forever ()
37
+ except KeyboardInterrupt :
38
+ print ("Received Keyboard interrupt, shutting down" )
39
+ httpd .server_close ()
40
+
41
+
42
+ def main (args = None ):
43
+ parser = docopt (__doc__ , argv = args , version = "0.1.0" )
44
+
45
+ server_port = int (parser ['-p' ]) if parser ['-p' ] else PORT
46
+
47
+ run (server_port )
48
+
49
+
50
+ if __name__ == "__main__" :
51
+ main (sys .argv [1 :])
You can’t perform that action at this time.
0 commit comments