From 5d274f01fd82424266985293370476affe21c92d Mon Sep 17 00:00:00 2001 From: BO ZHANG Date: Sat, 9 Dec 2023 12:40:00 +0800 Subject: [PATCH] deprecate FileRecorder --- csst_common/file_recorder.py | 55 ++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/csst_common/file_recorder.py b/csst_common/file_recorder.py index 5fe2b60..086f995 100644 --- a/csst_common/file_recorder.py +++ b/csst_common/file_recorder.py @@ -1,12 +1,21 @@ +""" +Identifier: KSC-SJ4-csst_common/__init__.py +Name: __init__.py +Description: csst_common package +Author: Bo Zhang +Created: 2022-09-13 +Modified-History: + 2022-09-13, Bo Zhang, created + 2022-09-13, Bo Zhang, fixed a bug + 2023-12-39, Bo Zhang, deprecated +""" + import os from collections import namedtuple from astropy import table -FileRecord = namedtuple( - "FileRecord", - ["filepath", "db", "comment", "existence"] -) +FileRecord = namedtuple("FileRecord", ["filepath", "db", "comment", "existence"]) class FileRecorder(list): @@ -64,14 +73,21 @@ class FileRecorder(list): @staticmethod def FileRecord(filepath: str = "", db: bool = False, comment: str = ""): - return FileRecord(filepath=filepath, db=db, comment=comment, existence=os.path.exists(filepath)) + return FileRecord( + filepath=filepath, + db=db, + comment=comment, + existence=os.path.exists(filepath), + ) def add_record(self, filepath: str = "", db: bool = False, comment: str = ""): existence = os.path.exists(filepath) assert isinstance(filepath, str) assert isinstance(db, bool) assert isinstance(comment, str) - super().append(FileRecord(filepath=filepath, db=db, comment=comment, existence=existence)) + super().append( + FileRecord(filepath=filepath, db=db, comment=comment, existence=existence) + ) def to_table(self): return table.Table([_._asdict() for _ in self]) @@ -87,20 +103,29 @@ class FileRecorder(list): def __repr__(self): t = self.to_table() lines, outs = t.formatter._pformat_table( - t, max_lines=-1, max_width=-1, show_name=True, show_unit=None, show_dtype=False, align="<") - if outs['show_length']: - lines.append(f'Length = {len(self)} rows') + t, + max_lines=-1, + max_width=-1, + show_name=True, + show_unit=None, + show_dtype=False, + align="<", + ) + if outs["show_length"]: + lines.append(f"Length = {len(self)} rows") return "\n".join(lines) @property def summary(self): if len(self) == 0: - return '0 alleged, 0 missing, 0 to db' + return "0 alleged, 0 missing, 0 to db" else: - return f"{len(self)} alleged, " \ - f"{len(self) - sum(self.to_table()['existence'])} missing, " \ - f"{sum(self.to_table()['existence'])} to db" + return ( + f"{len(self)} alleged, " + f"{len(self) - sum(self.to_table()['existence'])} missing, " + f"{sum(self.to_table()['existence'])} to db" + ) def is_good(self): - """ Check if all alleged files exist. """ - return all(self.to_table()['existence']) + """Check if all alleged files exist.""" + return all(self.to_table()["existence"]) -- GitLab