update inventory.py

This commit is contained in:
2026-05-07 16:51:51 +02:00
parent d7587ec264
commit bc582a2b39
3 changed files with 57 additions and 18 deletions
+4 -1
View File
@@ -1,3 +1,6 @@
# calcurves
calibration curves (for SEA and Frappy)
calibration curves (for SEA and Frappy)
* inventory.py produces a list about usage of calib files
* external.txt: list of sensors given away (contains lines of <where>: <space separated calib names without extension>
+3
View File
@@ -0,0 +1,3 @@
SwissFEL calib 2024-11/12: X219219 X142475 X149796 X149797 X196718 X196719 X196720 X196721 X196722 X198039 X220790 X220943 X221295 X221296 X221297 X221298 X222481 X225622 X225623 X225624
calib reference until 2026-04-28: X75610
calib reference after 2026-05-04: X240357
+50 -17
View File
@@ -1,10 +1,13 @@
import sys
import time
import re
from pathlib import Path
from glob import glob
from frappy_psi.calcurve import CalCurve
SPECIAL_EXT = {'.md', '.txt', '.py'}
lookup = '~/git', '~'
lookup = '~/git', '~', '/sq_sw/linse'
sea_pat = re.compile(r'\s*(lsc_sensor|mom_sensor|stick_sensors)\s+(\S+)\s+(\S+)\s+(?:.*-(sensor|curve)\s)?(\S+)?')
frappy_pat = re.compile(r'''[^#]*calcurve\s*=\s*('[^']+'|"[^"]+")''')
@@ -19,7 +22,12 @@ def find_dir(dirpath):
sea_dir = find_dir('sea/tcl')
cal_dir = find_dir('calcurves')
frappy_cfg = find_dir('frappy/cfg')
frappy_cfgs = []
for dirs in 'frappy/cfg', 'frappycfg':
try:
frappy_cfgs.append(find_dir(dirs))
except ValueError:
pass
SPECIAL = {'raw', 'manual', 'vacuum', 'code', 'clone', 'undefined', '-sensorname'}
@@ -37,17 +45,17 @@ class Collector:
def lsc_sensor(self, file, _1, _2, kwd, calcurve):
if calcurve not in SPECIAL and kwd in (None, 'sensor'):
self.result.setdefault(calcurve, []).append(file)
self.result.setdefault(calcurve, set()).add(file)
def mom_sensor(self, file, _1, _2, kwd, calcurve):
if calcurve not in FAKECRV and kwd == 'curve':
self.result.setdefault(calcurve, []).append(file)
self.result.setdefault(calcurve, set()).add(file)
def stick_sensors(self, file, calcurve1, calcurve2, _3, _4):
for calcurve in (calcurve1, calcurve2):
if calcurve.startswith('code=') or calcurve in SPECIAL:
continue
self.result.setdefault(calcurve, []).append(Path(file).name)
self.result.setdefault(calcurve, set()).add(Path(file).name)
def collect_sea(self, pattern):
"""treat lines starting with lsc_sensor, mom_sensor and stick_sensors"""
@@ -62,13 +70,14 @@ class Collector:
"""treat lines containing 'calcurve = "<sensor>"
also single quote is allowed, and no hash before
"""
for file in glob(str(frappy_cfg / pattern)):
with open(file) as f:
for line in f:
match = frappy_pat.match(line)
if match:
calcurve = match.group(1)[1:-1]
self.result.setdefault(calcurve, []).append(file)
for frappy_cfg in frappy_cfgs:
for file in glob(str(frappy_cfg / pattern)):
with open(file) as f:
for line in f:
match = frappy_pat.match(line)
if match:
calcurve = match.group(1)[1:-1]
self.result.setdefault(calcurve, set()).add(file)
col = Collector()
@@ -79,7 +88,13 @@ col.collect_sea('*.addon')
col.collect_frappy('*.py')
col.collect_frappy('*/*.py')
all_calibs = {Path(f).stem.lower(): f for f in glob(str(cal_dir / '*.*'))}
if len(sys.argv) > 1:
single_file = sys.argv[1]
all_calibs = {Path(single_file).stem.lower(): cal_dir / single_file}
else:
single_file = None
all_calibs = {Path(f).stem.lower(): f for f in glob(str(cal_dir / '*.*'))}
print(all_calibs)
unused = dict(all_calibs)
found = {}
@@ -103,15 +118,33 @@ for calib, (file, files) in found.items():
head = f'{Path(file).name}:'
except Exception as e:
head = f'{Path(file).name} {e!r}:'
print(head, ' '.join(Path(p).name for p in files))
filenames = set(Path(p).name for p in files)
print(head, ' '.join(filenames))
if notfound:
if notfound and not single_file:
print('\n--- not found:')
for calib, files in notfound.items():
print(f'{calib}:', ' '.join(Path(p).name for p in files))
print('\n--- external:')
with open('external.txt') as f:
for line in f:
comment, _, calibs = line.partition(':')
reduced = list(filter(None, (unused.pop(v.lower(), None) for v in calibs.split())))
if reduced:
print(f'{comment}:', ' '.join(Path(v).name for v in reduced))
print('\n--- unused:')
print(' '.join(Path(p).name for p in unused.values()))
unused_dict = {}
for file in unused.values():
path = Path(file)
if path.suffix in SPECIAL_EXT:
continue
day = time.strftime("%Y-%m-%d", time.localtime(path.stat().st_mtime))
unused_dict.setdefault(day, []).append(path.name)
for day, names in sorted(unused_dict.items()):
print(f'{day}:', ' '.join(names))
print('\nfound', len(found), 'notfound', len(notfound), 'unused', len(unused))