4141STYLESHEET = "odmlTerms.xsl"
4242
4343
44- def fetch_stylesheet ( ):
44+ def download_file ( repo , filename ):
4545 try :
46- data = urllib2 .urlopen ("%s%s" % (REPOSITORY , STYLESHEET )).read ()
46+ data = urllib2 .urlopen ("%s%s" % (repo , filename )).read ()
4747 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 ))
5050 return
5151
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 ))
5454
5555
5656def run (port = PORT ):
5757 handler = hs .SimpleHTTPRequestHandler
58+
5859 # files with odML extensions should be interpreted as XML
5960 handler .extensions_map .update ({'.odml' : 'application/xml' })
6061
@@ -63,10 +64,10 @@ def run(port=PORT):
6364 with socketserver .TCPServer (server_address , handler ) as httpd :
6465 webbrowser .open_new_tab ('http://localhost:%s' % port )
6566 try :
66- print ("You can end the server by pressing Ctrl+C" )
67+ print ("[Info] The server can be stopped by pressing Ctrl+C" )
6768 httpd .serve_forever ()
6869 except KeyboardInterrupt :
69- print ("Received Keyboard interrupt, shutting down" )
70+ print ("[Info] Received Keyboard interrupt, shutting down" )
7071 httpd .server_close ()
7172
7273
@@ -75,7 +76,8 @@ def main(args=None):
7576
7677 # Fetch stylesheet
7778 if parser ['--fetch' ] and not os .path .exists (STYLESHEET ):
78- fetch_stylesheet ()
79+ print ("[Info] Downloading stylesheet '%s'" % STYLESHEET )
80+ download_file (REPOSITORY , STYLESHEET )
7981
8082 server_port = int (parser ['-p' ]) if parser ['-p' ] else PORT
8183
0 commit comments