def serve(): config = Config() config = config.load_config() if not os.path.isdir(config['output_dir']): print('Output files not found...building...') build() port = 8000 host = '0.0.0.0' try: from tornado import ioloop from tornado import web application = web.Application([(r"/(.*)", web.StaticFileHandler, { "path": config['output_dir'], "default_filename": "index.html" })]) application.listen(port=port, address=host) print('Running at: http://{0}:{1}/'.format(host, port)) try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: print('Stopping server...') except: import SimpleHTTPServer import SocketServer os.chdir(config['output_dir']) Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer((host, port), Handler) httpd.allow_reuse_address = True print('Running at: http://{0}:{1}/'.format(host, port)) httpd.serve_forever()
def serve(): config = Config() config = config.load_config() if not os.path.isdir(config['output_dir']): print('Output files not found...building...') build() port = 8000 host = '0.0.0.0' try: from tornado import ioloop from tornado import web application = web.Application([ (r"/(.*)", web.StaticFileHandler, { "path": config['output_dir'], "default_filename": "index.html" }) ]) application.listen(port=port, address=host) print('Running at: http://{0}:{1}/'.format(host, port)) try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: print('Stopping server...') except: import SimpleHTTPServer import SocketServer os.chdir(config['output_dir']) Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer((host, port), Handler) httpd.allow_reuse_address = True print('Running at: http://{0}:{1}/'.format(host, port)) httpd.serve_forever()
def cleanup(): config = Config() config = config.load_config() try: shutil.rmtree(config['output_dir']) except: prt_exit('Can not cleanup directory {0}\n' 'Maybe it does not exist or ' 'we have permission issue'.format(config['output_dir']))