Add option to serve User Manual on localhost after building it

This commit is contained in:
Kovid Goyal 2014-11-26 12:38:44 +05:30
parent 0c98870eff
commit bad59c4ed7

View File

@ -84,6 +84,8 @@ class Manual(Command):
def add_options(self, parser): def add_options(self, parser):
parser.add_option('-l', '--language', action='append', default=[], parser.add_option('-l', '--language', action='append', default=[],
help='Build translated versions for only the specified languages (can be specified multiple times)') 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): def run(self, opts):
tdir = self.j(tempfile.gettempdir(), 'user-manual-build') tdir = self.j(tempfile.gettempdir(), 'user-manual-build')
@ -121,6 +123,26 @@ class Manual(Command):
finally: finally:
os.chdir(cwd) 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): def replace_with_symlinks(self, lang_dir):
' Replace all identical files with symlinks to save disk space/upload bandwidth ' ' Replace all identical files with symlinks to save disk space/upload bandwidth '
from calibre import walk from calibre import walk