fix: cmdeploy webdev now works as intended

Before: cmdeploy webdev just kept running non-stop regeneration of the
files with this it truly stop unless there's an actual change.
This commit is contained in:
Maikel Frias Mosquea
2025-11-23 16:57:17 +01:00
committed by holger krekel
parent 8f68672e31
commit 96108bbaba

View File

@@ -140,34 +140,34 @@ def main():
config.webdev = True config.webdev = True
assert config.mail_domain assert config.mail_domain
# start web page generation, open a browser and wait for changes
www_path, src_path, build_dir = get_paths(config) www_path, src_path, build_dir = get_paths(config)
build_dir = build_webpages(src_path, build_dir, config) build_dir = build_webpages(src_path, build_dir, config)
index_path = build_dir.joinpath("index.html") index_path = build_dir.joinpath("index.html")
webbrowser.open(str(index_path)) webbrowser.open(str(index_path))
stats = snapshot_dir_stats(src_path)
print(f"\nOpened URL: file://{index_path.resolve()}\n") print(f"\nOpened URL: file://{index_path.resolve()}\n")
print(f"watching {src_path} directory for changes") print(f"Watching {src_path} directory for changes...")
stats = snapshot_dir_stats(src_path)
changenum = 0 changenum = 0
count = 0 debounce_time = 0.5 # wait 0.5s after detecting a change
while True: while True:
time.sleep(1)
newstats = snapshot_dir_stats(src_path) newstats = snapshot_dir_stats(src_path)
if newstats == stats and count % 60 != 0:
count += 1
time.sleep(1.0)
continue
for key in newstats: if newstats != stats:
if stats[key] != newstats[key]: changed_files = [f for f in newstats if stats.get(f) != newstats[f]]
print(f"*** CHANGED: {key}") for f in changed_files:
changenum += 1 print(f"*** CHANGED: {f}")
stats = newstats stats = newstats
build_webpages(src_path, build_dir, config) changenum += 1
print(f"[{changenum}] regenerated web pages at: {index_path}") build_webpages(src_path, build_dir, config)
print(f"URL: file://{index_path.resolve()}\n\n") print(f"[{changenum}] regenerated web pages at: {index_path}")
count = 0 print(f"URL: file://{index_path.resolve()}\n\n")
time.sleep(debounce_time) # simple debounce
if __name__ == "__main__": if __name__ == "__main__":