Created
July 9, 2013 22:02
-
-
Save ajkaanbal/5961693 to your computer and use it in GitHub Desktop.
Guarfile for python-livereload. Enable livereload when web server is available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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