#!/usr/bin/env python3 import time import logging import sys from watchdog.observers import Observer from pathlib import Path from config import * from helpers import export_all_zones from DebouncedHandler import DebouncedHandler logging.basicConfig( level=getattr(logging, LOG_LEVEL, logging.INFO), format="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S", ) def main(): # sanity checks if not Path(WATCH_DIR).exists(): logging.error(f"Watch directory does not exist: {WATCH_DIR}") sys.exit(1) if not Path(GIT_REPO_DIR).exists(): logging.error(f"Git repo directory does not exist: {GIT_REPO_DIR}") sys.exit(1) logging.info(f"Watching {WATCH_DIR} for changes; exports will be written to {GIT_REPO_DIR}") event_handler = DebouncedHandler(ignore_directories=False) observer = Observer() observer.schedule(event_handler, WATCH_DIR, recursive=True) observer.start() # initial export on startup try: export_all_zones(trigger_path="startup") except Exception as e: logging.exception(f"Initial export failed: {e}") try: while True: time.sleep(1) except KeyboardInterrupt: logging.info("Stopping watcher...") finally: observer.stop() observer.join() if __name__ == "__main__": main()