Loading csst_common/file_recorder.py +15 −9 Original line number Diff line number Diff line import os from collections import namedtuple from astropy import table import os File = namedtuple( FileRecord = namedtuple( "FileRecord", ["filepath", "db", "comment", "existence"] ) Loading @@ -10,7 +11,7 @@ File = namedtuple( class FileRecorder(list): """ File Recorder, inherited from the built-in ``list``. FileRecord Recorder, inherited from the built-in ``list``. This recorder is used to record files generated by functional modules. In principle, a CSST pipeline module should return a status (CsstStatus) Loading Loading @@ -62,22 +63,19 @@ class FileRecorder(list): super(FileRecorder, self).__init__(*args, **kwargs) @staticmethod def Record(filepath: str = "", db: bool = False, comment: str = ""): return File(filepath=filepath, db=db, comment=comment, existence=os.path.exists(filepath)) def FileRecord(filepath: str = "", db: bool = False, comment: str = ""): 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(File(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]) def __repr__(self): return self.to_table().__repr__() def pprint(self, *args, **kwargs): print("<FileRecorder length={}>".format(len(self))) return self.to_table().pprint(*args, **kwargs) Loading @@ -85,3 +83,11 @@ class FileRecorder(list): def pprint_all(self, *args, **kwargs): print("<FileRecorder length={}>".format(len(self))) return self.to_table().pprint_all(*args, **kwargs) 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=None) if outs['show_length']: lines.append(f'Length = {len(self)} rows') return "\n".join(lines) Loading
csst_common/file_recorder.py +15 −9 Original line number Diff line number Diff line import os from collections import namedtuple from astropy import table import os File = namedtuple( FileRecord = namedtuple( "FileRecord", ["filepath", "db", "comment", "existence"] ) Loading @@ -10,7 +11,7 @@ File = namedtuple( class FileRecorder(list): """ File Recorder, inherited from the built-in ``list``. FileRecord Recorder, inherited from the built-in ``list``. This recorder is used to record files generated by functional modules. In principle, a CSST pipeline module should return a status (CsstStatus) Loading Loading @@ -62,22 +63,19 @@ class FileRecorder(list): super(FileRecorder, self).__init__(*args, **kwargs) @staticmethod def Record(filepath: str = "", db: bool = False, comment: str = ""): return File(filepath=filepath, db=db, comment=comment, existence=os.path.exists(filepath)) def FileRecord(filepath: str = "", db: bool = False, comment: str = ""): 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(File(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]) def __repr__(self): return self.to_table().__repr__() def pprint(self, *args, **kwargs): print("<FileRecorder length={}>".format(len(self))) return self.to_table().pprint(*args, **kwargs) Loading @@ -85,3 +83,11 @@ class FileRecorder(list): def pprint_all(self, *args, **kwargs): print("<FileRecorder length={}>".format(len(self))) return self.to_table().pprint_all(*args, **kwargs) 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=None) if outs['show_length']: lines.append(f'Length = {len(self)} rows') return "\n".join(lines)