2022-02-09 12:06:15 +01:00
|
|
|
from typing import Optional, Dict
|
|
|
|
|
|
|
|
from PyTeX.format.config import Config
|
|
|
|
from PyTeX.format.constants import YAML_REPO, YAML_PYTEX
|
|
|
|
from PyTeX.format.repo_status_info import RepoStatusInfo
|
2022-02-09 12:26:24 +01:00
|
|
|
from .repo_status_info import RepoStatusInfo
|
2022-02-09 12:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GitVersionInfo(Config):
|
|
|
|
def __init__(self):
|
|
|
|
self._repo_version: Optional[RepoStatusInfo] = None
|
|
|
|
self._pytex_version: Optional[RepoStatusInfo] = None
|
|
|
|
|
|
|
|
def set_from_json(self, content: Optional[Dict]):
|
|
|
|
filled_content = self._fill_keys(content)
|
|
|
|
self._repo_version = RepoStatusInfo.from_json(
|
|
|
|
filled_content[YAML_REPO]
|
|
|
|
)
|
|
|
|
self._pytex_version = RepoStatusInfo.from_json(
|
|
|
|
filled_content[YAML_PYTEX]
|
|
|
|
)
|
|
|
|
|
|
|
|
def to_json(self) -> Dict:
|
|
|
|
return {
|
|
|
|
YAML_PYTEX: self.pytex_version.to_json(),
|
|
|
|
YAML_REPO: self.repo_version.to_json()
|
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pytex_version(self) -> RepoStatusInfo:
|
|
|
|
if self._pytex_version is None:
|
|
|
|
return RepoStatusInfo()
|
|
|
|
else:
|
|
|
|
return self._pytex_version
|
|
|
|
|
2022-02-09 13:35:38 +01:00
|
|
|
@pytex_version.setter
|
|
|
|
def pytex_version(self, pytex_version: RepoStatusInfo):
|
|
|
|
self._pytex_version = pytex_version
|
|
|
|
|
2022-02-09 12:06:15 +01:00
|
|
|
@property
|
|
|
|
def repo_version(self) -> RepoStatusInfo:
|
|
|
|
if self._repo_version is None:
|
|
|
|
return RepoStatusInfo()
|
|
|
|
else:
|
|
|
|
return self._repo_version
|
|
|
|
|
2022-02-09 13:35:38 +01:00
|
|
|
@repo_version.setter
|
|
|
|
def repo_version(self, repo_version: RepoStatusInfo):
|
|
|
|
self._repo_version = repo_version
|
|
|
|
|
2022-02-09 12:06:15 +01:00
|
|
|
@property
|
|
|
|
def has_pytex_version(self) -> bool:
|
2022-02-09 12:26:24 +01:00
|
|
|
return self._pytex_version is not None
|
2022-02-09 12:06:15 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def has_repo_version(self) -> bool:
|
2022-02-09 12:26:24 +01:00
|
|
|
return self._repo_version is not None
|