mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Add option to serve User Manual on localhost after building it
This commit is contained in:
parent
0c98870eff
commit
bad59c4ed7
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user