2022-02-07 21:18:03 +01:00
|
|
|
from typing import Optional, Dict
|
2022-02-06 15:09:49 +01:00
|
|
|
|
2022-02-07 21:18:03 +01:00
|
|
|
from PyTeX.build.versioning.version_info.constants import *
|
|
|
|
from .config import Config
|
2022-02-06 15:09:49 +01:00
|
|
|
|
|
|
|
|
2022-02-07 22:24:14 +01:00
|
|
|
class RepoStatusInfo(Config):
|
2022-02-07 21:18:03 +01:00
|
|
|
def __init__(self):
|
2022-02-06 15:09:49 +01:00
|
|
|
|
2022-02-07 21:18:03 +01:00
|
|
|
self._dirty: Optional[bool] = None
|
|
|
|
self._commit_hash: Optional[str] = None
|
|
|
|
self._branch: Optional[str] = None
|
|
|
|
self._version: Optional[str] = None
|
|
|
|
|
2022-02-07 21:42:31 +01:00
|
|
|
def set_from_json(self, content: Optional[Dict]):
|
2022-02-07 21:18:03 +01:00
|
|
|
content = self._fill_keys(content)
|
|
|
|
self._branch = content[JSON_BRANCH]
|
|
|
|
self._dirty = content[JSON_DIRTY]
|
|
|
|
self._commit_hash = content[JSON_COMMIT_HASH]
|
|
|
|
self._version = content[JSON_VERSION]
|
|
|
|
|
|
|
|
def to_json(self) -> Dict:
|
|
|
|
return {
|
|
|
|
JSON_VERSION: self._version,
|
|
|
|
JSON_DIRTY: self._version,
|
|
|
|
JSON_COMMIT_HASH: self._commit_hash,
|
|
|
|
JSON_BRANCH: self._branch
|
|
|
|
}
|
2022-02-06 15:09:49 +01:00
|
|
|
|
|
|
|
@property
|
2022-02-07 21:18:03 +01:00
|
|
|
def dirty(self) -> bool:
|
|
|
|
if self._dirty is None:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return self._dirty
|
|
|
|
|
|
|
|
@dirty.setter
|
|
|
|
def dirty(self, dirty: bool):
|
|
|
|
self._dirty = dirty
|
2022-02-06 15:09:49 +01:00
|
|
|
|
|
|
|
@property
|
2022-02-07 21:18:03 +01:00
|
|
|
def version(self) -> str:
|
|
|
|
if self._version is None:
|
|
|
|
return DEFAULT_VERSION
|
2022-02-06 15:09:49 +01:00
|
|
|
return self._version
|
|
|
|
|
2022-02-07 21:18:03 +01:00
|
|
|
@version.setter
|
|
|
|
def version(self, version: str):
|
|
|
|
self._version = version
|
|
|
|
|
2022-02-06 15:09:49 +01:00
|
|
|
@property
|
2022-02-07 21:18:03 +01:00
|
|
|
def commit_hash(self) -> str:
|
|
|
|
if self._commit_hash is None:
|
|
|
|
return DEFAULT_HASH
|
|
|
|
else:
|
|
|
|
return self._commit_hash
|
|
|
|
|
|
|
|
@commit_hash.setter
|
|
|
|
def commit_hash(self, commit_hash: str):
|
|
|
|
self._commit_hash = commit_hash
|
2022-02-06 15:09:49 +01:00
|
|
|
|
|
|
|
@property
|
2022-02-07 21:18:03 +01:00
|
|
|
def branch(self) -> str:
|
|
|
|
if self._branch is None:
|
|
|
|
return DEFAULT_BRANCH
|
|
|
|
else:
|
|
|
|
return self._branch
|
|
|
|
|
|
|
|
@branch.setter
|
|
|
|
def branch(self, branch: str):
|
|
|
|
self._branch = branch
|