From dd3992d78621899ab0486db1c21d30153b788291 Mon Sep 17 00:00:00 2001 From: npac Date: Wed, 20 Nov 2024 22:17:20 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=2002=5Fupdate=5Fdb.py:=20init,=20s?= =?UTF-8?q?till=20missing=20db=20add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02_update_db.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 02_update_db.py diff --git a/02_update_db.py b/02_update_db.py new file mode 100755 index 00000000..f7ad0df8 --- /dev/null +++ b/02_update_db.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +""" +Add newer scans to DB +""" +import os +import re +from glob import glob + +import acq2sqlite +import dcmmeta2tsv + + +def is_project(pdir: str) -> bool: + """ + Is input a MR project dir? + should have subfolder like ``2024.06.27-09.19.11/`` + + :param pdir: directory to test + :return: True if is a project directory + + #>>> is_project('/disk/mace2/scan_data/WPC-8620/') + #True + #>>> is_project('/disk/mace2/scan_data/7T/') + #False + """ + if not os.path.isdir(pdir): + return False + for sesdir in os.listdir(pdir): + if re.search("^2[0-9.-]{18}$", sesdir): + return True + return False + + +db = acq2sqlite.DBQuery() +for pdir in glob("/disk/mace2/scan_data/W*"): + if not is_project(pdir): + next + project = os.path.basename(pdir) + recent = db.most_recent("%" + project) + print(f"project:'{project}'; res='{recent}'")