diff --git a/setup/publish.py b/setup/publish.py index 5c4b25a2e3..5d28aa3c6b 100644 --- a/setup/publish.py +++ b/setup/publish.py @@ -84,6 +84,8 @@ class Manual(Command): def add_options(self, parser): parser.add_option('-l', '--language', action='append', default=[], help='Build translated versions for only the specified languages (can be specified multiple times)') + parser.add_option('--serve', action='store_true', default=False, + help='Run a webserver on the built manual files') def run(self, opts): tdir = self.j(tempfile.gettempdir(), 'user-manual-build') @@ -121,6 +123,26 @@ class Manual(Command): finally: os.chdir(cwd) + if opts.serve: + self.serve_manual(self.j(tdir, 'en', 'html')) + + def serve_manual(self, root): + os.chdir(root) + import BaseHTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler + HandlerClass = SimpleHTTPRequestHandler + ServerClass = BaseHTTPServer.HTTPServer + Protocol = "HTTP/1.0" + server_address = ('127.0.0.1', 8000) + + HandlerClass.protocol_version = Protocol + httpd = ServerClass(server_address, HandlerClass) + + print ("Serving User Manual on localhost:8000") + from calibre.gui2 import open_url + open_url('http://localhost:8000') + httpd.serve_forever() + def replace_with_symlinks(self, lang_dir): ' Replace all identical files with symlinks to save disk space/upload bandwidth ' from calibre import walk