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-08 00:33:29 +01:00
|
|
|
from ...build.enums import *
|
2022-02-04 11:39:15 +01:00
|
|
|
|
2022-02-08 00:33:45 +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
|
2022-02-08 00:33:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
class VersionInfo(Config):
|
|
|
|
def __init__(self):
|
|
|
|
self._pytex_dir_type: Optional[PyTeXRootDirType] = None
|
|
|
|
self._file_versions: Optional[List[FileVersionInfo]] = None
|
|
|
|
|
|
|
|
def set_from_json(self, content: Optional[Dict]):
|
|
|
|
content = self._fill_keys(content)
|
|
|
|
self._pytex_dir_type = None # TODO
|
|
|
|
self._file_versions = [
|
|
|
|
FileVersionInfo.from_json(entry)
|
|
|
|
for entry in content[JSON_FILE_VERSIONS]
|
|
|
|
]
|
|
|
|
|
|
|
|
def to_json(self) -> Dict:
|
|
|
|
return {
|
|
|
|
JSON_FILE_VERSIONS: [
|
|
|
|
file_version_info.to_json()
|
|
|
|
for file_version_info in self._file_versions
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pytex_dir_type(self) -> PyTeXRootDirType:
|
|
|
|
if self._pytex_dir_type is None:
|
|
|
|
return PyTeXRootDirType.PYTEX_SOURCE
|
|
|
|
else:
|
|
|
|
return self._pytex_dir_type
|
|
|
|
|
|
|
|
@property
|
|
|
|
def file_versions(self) -> List[FileVersionInfo]:
|
|
|
|
if self._file_versions is None:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
return self._file_versions
|