Skip to content

Instantly share code, notes, and snippets.

@delijati
Created January 27, 2012 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save delijati/1690411 to your computer and use it in GitHub Desktop.
Save delijati/1690411 to your computer and use it in GitHub Desktop.
with selenium
#!/usr/bin/env python
import os
import subprocess
import sys
from urllib import pathname2url
import selenium.webdriver
def run():
watch_command = 'inotifywait -rq -e close_write --exclude \'"*.html"\' .'.split()
make_command = 'make html'.split()
driver = selenium.webdriver.Firefox()
path = os.path.join('_build', 'html', 'index.html')
url = 'file:///' + pathname2url(os.path.abspath(path))
driver.get(url)
while True:
# Perhaps should put notifier access in a mutex - not bothering yet
notifier = subprocess.Popen(watch_command)
notifier.wait()
subprocess.call(make_command)
driver.refresh()
if __name__ == "__main__":
if not os.path.isdir('_build'):
# very simplistic sanity check. Works for me, as I generally use
# sphinx-quickstart defaults
print('You must run this application from a Sphinx directory containing _build')
rc = 1
else:
run()
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment