Skip to content

Instantly share code, notes, and snippets.

@vsajip
Forked from delijati/doc-watch-selenium.py
Created January 27, 2012 22:04
Show Gist options
  • Save vsajip/1691174 to your computer and use it in GitHub Desktop.
Save vsajip/1691174 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