pytex/PyTeX/build/versioning/version_info/version_info.py

91 lines
2.7 KiB
Python
Raw Normal View History

2022-02-07 22:24:14 +01:00
from typing import Optional, List, Dict
2022-02-04 11:39:15 +01:00
2022-02-07 22:24:14 +01:00
from PyTeX.format.repo_status_info import RepoStatusInfo
2022-02-06 15:09:49 +01:00
from .constants import *
2022-02-07 22:24:14 +01:00
from ....format.config import Config
2022-02-04 11:39:15 +01:00
2022-02-07 22:24:14 +01:00
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]):
content = self._fill_keys(content)
self._relative_name = content[JSON_RELATIVE_NAME]
self._file_hash = content[JSON_FILE_HASH]
self._sources_hash = content[JSON_SOURCES_HASH]
self._build_time = content[JSON_BUILD_TIME]
self._repo_status_info = RepoStatusInfo.from_json(
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
2022-02-04 11:39:15 +01:00
else:
2022-02-07 22:24:14 +01:00
return self._file_hash
2022-02-04 11:39:15 +01:00
2022-02-07 22:24:14 +01:00
@file_hash.setter
def file_hash(self, file_hash: str):
self._file_hash = file_hash
2022-02-04 11:39:15 +01:00
@property
2022-02-07 22:24:14 +01:00
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
2022-02-04 11:39:15 +01:00
@property
2022-02-07 22:24:14 +01:00
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
2022-02-04 11:39:15 +01:00
@property
2022-02-07 22:24:14 +01:00
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