I've written simple script to update my CSS styles (from less to css) every time when i change less file. I have now:
import time
import hashlib
from subprocess import call
def md5_checksum(filePath):
fh = open(filePath, 'rb')
m = hashlib.md5()
m.update(fh.read())
fh.close()
return m.hexdigest()
md5 = md5_checksum('styles.less')
while True:
newmd5 = md5_checksum('styles.less')
if md5 != newmd5:
sh = open('styles.css', 'w')
call(['lessc', 'styles.less'], stdout=sh)
md5 = newmd5
sh.close()
print 'Changed'
time.sleep(0.2)
And what is strange, script is working for some time:
Changed
Changed
Changed
Changed
Traceback (most recent call last):
File "watcher.py", line 16, in <module>
newmd5 = md5_checksum('styles.less')
File "watcher.py", line 7, in md5_checksum
fh = open(filePath, 'rb')
IOError: [Errno 2] No such file or directory: 'styles.less'
Whats going on? File is still there for 100%. What am i doing wrong?