-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlivereload-docs.py
executable file
·36 lines (32 loc) · 1.14 KB
/
livereload-docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# This starts a web server on http://localhost:5500/ where doc files are automatically recompiled.
#
# If you need to create the docs from scratch, run:
# cd docs
# make html
#
from livereload import Server
from subprocess import Popen, PIPE
# livereload's run_shell doesn't encode errors right (leaves them bytes)
import logging
logger = logging.getLogger('livereload')
class Runner:
def __init__(self, cmd, cwd):
self.cmd = cmd
self.cwd = cwd
def __str__(self):
return ' '.join(self.cmd)
def __call__(self):
p = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=self.cwd, shell=False)
stdout, stderr = p.communicate()
if stderr:
logger.error('\n' + stderr.decode())
return stderr
if stdout:
logger.info('\n' + stdout.decode())
return stdout
server = Server()
server.watch('docs-src/*.rst', Runner(['make', 'html', '--always-make' ], cwd='docs-src'))
server.watch('docs-src/_static/*.css', Runner(['make', 'html', '--always-make' ], cwd='docs-src'))
print('PORT IS 5500')
server.serve(root='docs/', restart_delay=1)