implement VersionInfo

This commit is contained in:
Maximilian Keßler 2022-02-08 00:33:29 +01:00
parent b53b3be39a
commit e93e69d771
2 changed files with 39 additions and 1 deletions

View file

@ -22,3 +22,5 @@ JSON_REPO_STATUS_INFO = 'repo_info'
NO_RELATIVE_NAME = 'NO_NAME'
NO_BUILD_TIME = 'no_build_time'
JSON_FILE_VERSIONS = 'file_versions'

View file

@ -3,7 +3,7 @@ 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):
@ -88,3 +88,39 @@ class FileVersionInfo(Config):
@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._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