Skip to content

Instantly share code, notes, and snippets.

@ajkaanbal
Created July 9, 2013 22:02
Show Gist options
  • Save ajkaanbal/5961693 to your computer and use it in GitHub Desktop.
Save ajkaanbal/5961693 to your computer and use it in GitHub Desktop.
Guarfile for python-livereload. Enable livereload when web server is available.
#!/usr/bin/env python
from livereload.task import Task
def check_web_server():
"""
Enable livereload when web server is avaiable.
"""
import httplib
import time
host = 'localhost'
port = '8000'
path = '/'
status = False
while (not status):
try:
print 'Check connection to %s:%s%s' % (host, port, path)
conn = httplib.HTTPConnection(host, port)
conn.request('HEAD', path)
status = conn.getresponse().status
except StandardError:
status = False
time.sleep(1)
return True
Task.add('.', check_web_server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment