Work on fixing bugs and reformat
This commit is contained in:
@@ -24,12 +24,13 @@ management command), you can "touch" any file under the watched path:
|
||||
The watcher ignores `__pycache__`, `.pyc` files and `.git` paths.
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from watchdog.observers import Observer
|
||||
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from watchdog.observers import Observer
|
||||
|
||||
|
||||
class ChangeHandler(FileSystemEventHandler):
|
||||
@@ -48,7 +49,7 @@ class ChangeHandler(FileSystemEventHandler):
|
||||
|
||||
def _check_and_restart(self, path):
|
||||
# Ignore pycache and compiled files
|
||||
if '__pycache__' in path or '.pyc' in path or '.git' in path:
|
||||
if "__pycache__" in path or ".pyc" in path or ".git" in path:
|
||||
return
|
||||
|
||||
now = time.time()
|
||||
@@ -62,13 +63,16 @@ class ChangeHandler(FileSystemEventHandler):
|
||||
|
||||
def _restart_ur(self):
|
||||
# Determine target container from environment (default `ur_gia`)
|
||||
target = os.environ.get('TARGET_CONTAINER', 'ur_gia')
|
||||
target = os.environ.get("TARGET_CONTAINER", "ur_gia")
|
||||
print(f'[{time.strftime("%H:%M:%S")}] Restarting {target}...', flush=True)
|
||||
# Try podman first (preferred in this setup), then docker
|
||||
cmd = f"podman restart {target} 2>/dev/null || docker restart {target} 2>/dev/null"
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True)
|
||||
if result.returncode == 0:
|
||||
print(f'[{time.strftime("%H:%M:%S")}] {target} restarted successfully', flush=True)
|
||||
print(
|
||||
f'[{time.strftime("%H:%M:%S")}] {target} restarted successfully',
|
||||
flush=True,
|
||||
)
|
||||
else:
|
||||
print(f'[{time.strftime("%H:%M:%S")}] {target} restart failed', flush=True)
|
||||
time.sleep(1)
|
||||
@@ -80,17 +84,20 @@ def main():
|
||||
|
||||
# Allow overriding watched paths via environment variable `WATCH_PATHS`.
|
||||
# Default is `/code/core,/code/app` but you can set e.g. `WATCH_PATHS=/code/core`
|
||||
watch_paths_env = os.environ.get('WATCH_PATHS', '/code/core,/code/app')
|
||||
watch_paths = [p.strip() for p in watch_paths_env.split(',') if p.strip()]
|
||||
watch_paths_env = os.environ.get("WATCH_PATHS", "/code/core,/code/app")
|
||||
watch_paths = [p.strip() for p in watch_paths_env.split(",") if p.strip()]
|
||||
for path in watch_paths:
|
||||
if os.path.exists(path):
|
||||
observer.schedule(handler, path, recursive=True)
|
||||
print(f'Watching: {path}', flush=True)
|
||||
print(f"Watching: {path}", flush=True)
|
||||
else:
|
||||
print(f'Not found (will not watch): {path}', flush=True)
|
||||
print(f"Not found (will not watch): {path}", flush=True)
|
||||
|
||||
observer.start()
|
||||
print(f'[{time.strftime("%H:%M:%S")}] File watcher started. Monitoring for changes...', flush=True)
|
||||
print(
|
||||
f'[{time.strftime("%H:%M:%S")}] File watcher started. Monitoring for changes...',
|
||||
flush=True,
|
||||
)
|
||||
|
||||
try:
|
||||
while True:
|
||||
@@ -100,5 +107,5 @@ def main():
|
||||
observer.join()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user