|
|
@ -1,7 +1,6 @@ |
|
|
|
"""Helper to watch a (set) of directories for modifications.""" |
|
|
|
"""Helper to watch a (set) of directories for modifications.""" |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
|
import threading |
|
|
|
|
|
|
|
import time |
|
|
|
import time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -11,7 +10,6 @@ class DirWatcher(object): |
|
|
|
def __init__(self, paths): |
|
|
|
def __init__(self, paths): |
|
|
|
if isinstance(paths, basestring): |
|
|
|
if isinstance(paths, basestring): |
|
|
|
paths = [paths] |
|
|
|
paths = [paths] |
|
|
|
self._mu = threading.Lock() |
|
|
|
|
|
|
|
self._done = False |
|
|
|
self._done = False |
|
|
|
self.paths = list(paths) |
|
|
|
self.paths = list(paths) |
|
|
|
self.lastrun = time.time() |
|
|
|
self.lastrun = time.time() |
|
|
@ -35,12 +33,8 @@ class DirWatcher(object): |
|
|
|
return most_recent_change |
|
|
|
return most_recent_change |
|
|
|
|
|
|
|
|
|
|
|
def most_recent_change(self): |
|
|
|
def most_recent_change(self): |
|
|
|
self._mu.acquire() |
|
|
|
if time.time() - self.lastrun > 1: |
|
|
|
try: |
|
|
|
self._cache = self._calculate() |
|
|
|
if time.time() - self.lastrun > 1: |
|
|
|
self.lastrun = time.time() |
|
|
|
self._cache = self._calculate() |
|
|
|
return self._cache |
|
|
|
self.lastrun = time.time() |
|
|
|
|
|
|
|
return self._cache |
|
|
|
|
|
|
|
finally: |
|
|
|
|
|
|
|
self._mu.release() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|