Merge pull request #565 from GNS3/watch_iou

Monitor IOU NVRAM changes.
This commit is contained in:
Jeremy Grossmann authored and GitHub committed 2016-06-10 22:33:56 -06:00
commit 6cd136b423
4 files changed
+28 -26

No files matched your search

+5 -5
View File
@@ -23,6 +23,7 @@ class FileWatcher:
"""
Watch for file change and call the callback when something happen
"""
def __init__(self, path, callback, delay=1):
if not isinstance(path, str):
path = str(path)
@@ -32,7 +33,7 @@ class FileWatcher:
self._closed = False
try:
self._mtime = os.stat(path).st_mtime
self._mtime = os.stat(path).st_mtime_ns
except OSError:
self._mtime = None
asyncio.get_event_loop().call_later(self._delay, self._check_config_file_change)
@@ -48,9 +49,10 @@ class FileWatcher:
return
changed = False
try:
if os.stat(self._path).st_mtime != self._mtime:
mtime = os.stat(self._path).st_mtime_ns
if mtime != self._mtime:
changed = True
self._mtime = os.stat(self._path).st_mtime
self._mtime = mtime
except OSError:
self._mtime = None
if changed:
@@ -64,5 +66,3 @@ class FileWatcher:
@callback.setter
def callback(self, val):
self._callback = val