from typing import Optional, List, Dict from PyTeX.format.repo_status_info import RepoStatusInfo from .constants import * from ....format.config import Config from ...build.enums import * class FileVersionInfo(Config): def __init__(self): self._relative_name: Optional[str] = None self._file_hash: Optional[str] = None self._sources_hash: Optional[str] = None # Meta properties actually not needed for build itself self._repo_status_info: Optional[RepoStatusInfo] = None self._build_time: Optional[str] = None def set_from_json(self, content: Optional[Dict]): filled_content = self._fill_keys(content) self._relative_name = filled_content[JSON_RELATIVE_NAME] self._file_hash = filled_content[JSON_FILE_HASH] self._sources_hash = filled_content[JSON_SOURCES_HASH] self._build_time = filled_content[JSON_BUILD_TIME] self._repo_status_info = RepoStatusInfo.from_json( filled_content[JSON_REPO_STATUS_INFO] ) def to_json(self) -> Dict: return { JSON_RELATIVE_NAME: self._relative_name, JSON_FILE_HASH: self._file_hash, JSON_SOURCES_HASH: self._sources_hash, JSON_BUILD_TIME: self._build_time, JSON_REPO_STATUS_INFO: self.repo_status_info.to_json() } @property def file_hash(self) -> str: if self._file_hash is None: return DEFAULT_HASH else: return self._file_hash @file_hash.setter def file_hash(self, file_hash: str): self._file_hash = file_hash @property def sources_hash(self) -> str: if self._sources_hash is None: return DEFAULT_HASH else: return self._sources_hash @sources_hash.setter def sources_hash(self, sources_hash: str): self._sources_hash = sources_hash @property def relative_name(self) -> str: if self._relative_name is None: return NO_RELATIVE_NAME else: return self._relative_name @relative_name.setter def relative_name(self, relative_name: str): self._relative_name = relative_name @property def repo_status_info(self) -> RepoStatusInfo: if self._repo_status_info is None: return RepoStatusInfo() else: return self._repo_status_info @repo_status_info.setter def repo_status_info(self, repo_status_info: RepoStatusInfo): self._repo_status_info = repo_status_info @property def build_time(self) -> str: if self._build_time is None: return NO_BUILD_TIME else: return self._build_time @build_time.setter def build_time(self, build_time: str): self._build_time = build_time class VersionInfo(Config): def __init__(self): self._pytex_dir_type: Optional[PyTeXRootDirType] = None self._files: Optional[List[FileVersionInfo]] = None def set_from_json(self, content: Optional[Dict]): filled_content: Dict = self._fill_keys(content) self._pytex_dir_type = None # TODO self._files = [ FileVersionInfo.from_json(entry) for entry in filled_content[JSON_FILE_VERSIONS] ] def to_json(self) -> Dict: return { JSON_FILE_VERSIONS: [ file_version_info.to_json() for file_version_info in self.files ] } @property def pytex_dir_type(self) -> PyTeXRootDirType: if self._pytex_dir_type is None: return PyTeXRootDirType.PYTEX_SOURCE else: return self._pytex_dir_type @pytex_dir_type.setter def pytex_dir_type(self, pytex_dir_type: PyTeXRootDirType): self._pytex_dir_type = pytex_dir_type @property def files(self) -> List[FileVersionInfo]: if self._files is None: return [] else: return self._files @files.setter def files(self, files: List[FileVersionInfo]): self._files = files