diff options
author | sotech117 <michael_foiani@brown.edu> | 2025-07-31 17:27:24 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2025-07-31 17:27:24 -0400 |
commit | 5bf22fc7e3c392c8bd44315ca2d06d7dca7d084e (patch) | |
tree | 8dacb0f195df1c0788d36dd0064f6bbaa3143ede /venv/lib/python3.8/site-packages/dash/_watch.py | |
parent | b832d364da8c2efe09e3f75828caf73c50d01ce3 (diff) |
add code for analysis of data
Diffstat (limited to 'venv/lib/python3.8/site-packages/dash/_watch.py')
-rw-r--r-- | venv/lib/python3.8/site-packages/dash/_watch.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/venv/lib/python3.8/site-packages/dash/_watch.py b/venv/lib/python3.8/site-packages/dash/_watch.py new file mode 100644 index 0000000..c13d70f --- /dev/null +++ b/venv/lib/python3.8/site-packages/dash/_watch.py @@ -0,0 +1,36 @@ +import collections +import os +import re +import time + + +def watch(folders, on_change, pattern=None, sleep_time=0.1): + pattern = re.compile(pattern) if pattern else None + watched = collections.defaultdict(lambda: -1.0) + + def walk(): + walked = [] + for folder in folders: + for current, _, files in os.walk(folder): + for f in files: + if pattern and not pattern.search(f): + continue + path = os.path.join(current, f) + + info = os.stat(path) + new_time = info.st_mtime + + if new_time > watched[path] > 0: + on_change(path, new_time, False) + + watched[path] = new_time + walked.append(path) + + # Look for deleted files + for w in [x for x in watched.keys() if x not in walked]: + del watched[w] + on_change(w, -1, True) + + while True: + walk() + time.sleep(sleep_time) |