csvpath.managers.results.result_metadata

  1from uuid import UUID
  2from csvpath.managers.metadata import Metadata
  3
  4
  5class ResultMetadata(Metadata):
  6    """@private"""
  7    def __init__(self, config):
  8        super().__init__(config)
  9        # these we know right away
 10        self._named_paths_uuid = None
 11        self.named_results_name: str = None
 12        #
 13        # in a non-source-mode = preceding situation the
 14        # named-file name is all we need. however, for source-mode
 15        # and by_lines runs we need the namespace + name of the
 16        # preceding data
 17        #
 18        self.named_file_name: str = None
 19        #
 20        # the real input file path. this may not match the named-file path
 21        #
 22        self.actual_data_file: str = None
 23        #
 24        # the input file path we would use if all instances used the named-file
 25        #
 26        self.origin_data_file: str = None
 27        #
 28        # if true actual data file is the preceding instance's data.csv
 29        #
 30        self.source_mode_preceding = None
 31        #
 32        # self if we're source mode preceding we need to know the instance
 33        # before us so we can construct the instancename/data.cvs ID
 34        #
 35        self.preceding_instance_identity = None
 36        self.run: str = None
 37        self.run_home: str = None
 38        self.instance_home: str = None
 39        self.instance_identity: str = None
 40        self.instance_index: int = None
 41
 42        # these we only know at the end
 43        self.file_count: int = -1
 44        self.file_fingerprints: dict[str, str] = None
 45        self.valid: bool = None
 46        self.completed: bool = None
 47        self.files_expected: bool = None
 48        self.error_count: int = -1
 49        self.by_line: bool = False
 50        #
 51        # transfer tuples:
 52        # 1: filename, no extension needed: data | unmatched
 53        # 2: variable name containing the path to write to
 54        # 3: path of source file
 55        # 3: path to write to
 56        #
 57        self.transfers: tuple[str, str, str, str] = None
 58
 59    def __str__(self) -> str:
 60        return f"""
 61ResultMetadata(
 62  {self.uuid}{self.named_paths_uuid},
 63  {self.named_results_name},{self.named_file_name},{self.run},{self.instance_identity},{self.by_line},
 64  {self.run_home},{self.instance_home},
 65  {self.input_data_file},
 66  {self.file_fingerprints},
 67  {self.valid},{self.completed},{self.files_expected},{self.error_count},{self.file_count},
 68  {self.transfers}
 69)"""
 70
 71    def from_manifest(self, m) -> None:
 72        if m is None:
 73            return
 74        super().from_manifest(m)
 75        self.named_paths_uuid_string = m.get("named_paths_uuid")
 76        self.named_results_name = m.get("named_results_name")
 77        self.named_file_name = m.get("named_file_name")
 78        self.run = m.get("run")
 79        self.run_home = m.get("run_home")
 80        self.instance_home = m.get("instance_home")
 81        self.instance_identity = m.get("instance_identity")
 82        self.input_data_file = m.get("input_data_file")
 83        self.file_count = m.get("file_count")
 84        self.file_fingerprints = m.get("file_fingerprints")
 85        self.valid = m.get("valid")
 86        self.completed = m.get("completed")
 87        self.files_expected = m.get("files_expected")
 88        self.error_count = m.get("error_count")
 89        self.transfers = m.get("transfers")
 90
 91    @property
 92    def named_paths_uuid(self) -> UUID:
 93        return self._named_paths_uuid
 94
 95    @named_paths_uuid.setter
 96    def named_paths_uuid(self, u: UUID) -> None:
 97        if u and not isinstance(u, UUID):
 98            raise ValueError("Must be a UUID")
 99        self._named_paths_uuid = u
100
101    @property
102    def named_paths_uuid_string(self) -> str:
103        if self._named_paths_uuid is None:
104            return None
105        return str(self._named_paths_uuid)
106
107    @named_paths_uuid_string.setter
108    def named_paths_uuid_string(self, u: str) -> None:
109        #
110        # this is seen in testing
111        #
112        if u is None:
113            return
114        if u and not isinstance(u, str):
115            raise ValueError("Must be a string")
116        self._named_paths_uuid = UUID(u)