AareScripts: updated Knife_edge_scan and added watch_correct_lp (untested)
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-07-09T12:31:15.585676Z",
|
||||
"start_time": "2025-07-09T12:31:15.374087Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"sys.path.append('/home/leonarski_f/aaredaqlib')\n",
|
||||
"sys.path.append('/home/leonarski_f/aaredaq')\n",
|
||||
"from aaredaq.devices import BeamlineDevices\n",
|
||||
"from aaredaqlib.beamline import MXBeamline"
|
||||
],
|
||||
"id": "d2efa08de2dbd46b"
|
||||
"id": "d2efa08de2dbd46b",
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ModuleNotFoundError",
|
||||
"evalue": "No module named 'aaredaq'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001B[31m---------------------------------------------------------------------------\u001B[39m",
|
||||
"\u001B[31mModuleNotFoundError\u001B[39m Traceback (most recent call last)",
|
||||
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[1]\u001B[39m\u001B[32m, line 1\u001B[39m\n\u001B[32m----> \u001B[39m\u001B[32m1\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01maaredaq\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mdevices\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m BeamlineDevices\n\u001B[32m 2\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01maaredaqlib\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mbeamline\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m MXBeamline\n",
|
||||
"\u001B[31mModuleNotFoundError\u001B[39m: No module named 'aaredaq'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 1
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
|
||||
71
watch_correct_lp.py
Normal file
71
watch_correct_lp.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
|
||||
# --- CONFIG ---
|
||||
WATCH_DIR = "/das/work/units/mx/p22601/aareproc/" # <-- Set this to your directory
|
||||
TARGET_FILENAME = "CORRECT.LP"
|
||||
EXCLUDE_RE = re.compile(r"/(autoproc|man_proc)(/|$)")
|
||||
NANO_RE = re.compile(r"SigAno\s+ Nano")
|
||||
LINES_AFTER_NANO = 12
|
||||
|
||||
|
||||
def is_excluded(path):
|
||||
"""Return True if path matches any excluded directory pattern"""
|
||||
return bool(EXCLUDE_RE.search(path))
|
||||
|
||||
|
||||
class LPFileHandler(FileSystemEventHandler):
|
||||
def on_created(self, event):
|
||||
if not event.is_directory and os.path.basename(event.src_path) == TARGET_FILENAME:
|
||||
if not is_excluded(event.src_path):
|
||||
print(f"\n[CREATE] {event.src_path}")
|
||||
self.process_file(event.src_path)
|
||||
|
||||
def on_modified(self, event):
|
||||
if not event.is_directory and os.path.basename(event.src_path) == TARGET_FILENAME:
|
||||
if not is_excluded(event.src_path):
|
||||
print(f"\n[MODIFY] {event.src_path}")
|
||||
self.process_file(event.src_path)
|
||||
|
||||
def process_file(self, filepath):
|
||||
try:
|
||||
with open(filepath, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# 1. Look for ERROR lines
|
||||
error_lines = [line for line in lines if "ERROR" in line]
|
||||
if error_lines:
|
||||
print("\033[91mERROR lines found:\033[0m")
|
||||
for line in error_lines:
|
||||
print(f"\033[91m{line.strip()}\033[0m")
|
||||
|
||||
# 2. Look for "Nano" and following lines
|
||||
for idx, line in enumerate(lines):
|
||||
if NANO_RE.search(line):
|
||||
print("\033[92mMatch: 'Nano' found. Showing following 12 lines:\033[0m")
|
||||
block = lines[idx:idx + 1 + LINES_AFTER_NANO]
|
||||
print("".join(block))
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error reading {filepath}: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
event_handler = LPFileHandler()
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, path=WATCH_DIR, recursive=True)
|
||||
observer.start()
|
||||
|
||||
print(f"Watching '{WATCH_DIR}' for '{TARGET_FILENAME}'...\n(Excluding dirs: {EXCLUDE_RE.pattern})")
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("Stopping watcher...")
|
||||
observer.stop()
|
||||
observer.join()
|
||||
Reference in New Issue
Block a user