41
41
STYLESHEET = "odmlTerms.xsl"
42
42
43
43
44
- def fetch_stylesheet ( ):
44
+ def download_file ( repo , filename ):
45
45
try :
46
- data = urllib2 .urlopen ("%s%s" % (REPOSITORY , STYLESHEET )).read ()
46
+ data = urllib2 .urlopen ("%s%s" % (repo , filename )).read ()
47
47
data = data .decode ("utf-8" )
48
- except Exception as e :
49
- print ("failed loading '%s%s': %s" % (REPOSITORY , STYLESHEET , e ))
48
+ except Exception as err :
49
+ print ("[Warning] Failed loading '%s%s': %s" % (repo , filename , err ))
50
50
return
51
51
52
- with open (STYLESHEET , "w" ) as fp :
53
- fp .write (str (data ))
52
+ with open (filename , "w" ) as local_file :
53
+ local_file .write (str (data ))
54
54
55
55
56
56
def run (port = PORT ):
57
57
handler = hs .SimpleHTTPRequestHandler
58
+
58
59
# files with odML extensions should be interpreted as XML
59
60
handler .extensions_map .update ({'.odml' : 'application/xml' })
60
61
@@ -63,10 +64,10 @@ def run(port=PORT):
63
64
with socketserver .TCPServer (server_address , handler ) as httpd :
64
65
webbrowser .open_new_tab ('http://localhost:%s' % port )
65
66
try :
66
- print ("You can end the server by pressing Ctrl+C" )
67
+ print ("[Info] The server can be stopped by pressing Ctrl+C" )
67
68
httpd .serve_forever ()
68
69
except KeyboardInterrupt :
69
- print ("Received Keyboard interrupt, shutting down" )
70
+ print ("[Info] Received Keyboard interrupt, shutting down" )
70
71
httpd .server_close ()
71
72
72
73
@@ -75,7 +76,8 @@ def main(args=None):
75
76
76
77
# Fetch stylesheet
77
78
if parser ['--fetch' ] and not os .path .exists (STYLESHEET ):
78
- fetch_stylesheet ()
79
+ print ("[Info] Downloading stylesheet '%s'" % STYLESHEET )
80
+ download_file (REPOSITORY , STYLESHEET )
79
81
80
82
server_port = int (parser ['-p' ]) if parser ['-p' ] else PORT
81
83
0 commit comments