From bc582a2b39ef66b227a9885e5449aa04a5ff7e50 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Thu, 7 May 2026 16:51:51 +0200 Subject: [PATCH] update inventory.py --- README.md | 5 +++- external.txt | 3 +++ inventory.py | 67 +++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 external.txt diff --git a/README.md b/README.md index 4d3ca41..209b9b3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # calcurves -calibration curves (for SEA and Frappy) \ No newline at end of file +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 : diff --git a/external.txt b/external.txt new file mode 100644 index 0000000..7598e51 --- /dev/null +++ b/external.txt @@ -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 diff --git a/inventory.py b/inventory.py index 955a0a2..25872ec 100644 --- a/inventory.py +++ b/inventory.py @@ -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 = "" 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)) -