71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
from typing import Optional, Dict
|
|
|
|
from PyTeX.build.versioning.version_info.constants import *
|
|
from .config import Config
|
|
|
|
|
|
class RepoStatusInfo(Config):
|
|
def __init__(self):
|
|
|
|
self._dirty: Optional[bool] = None
|
|
self._commit_hash: Optional[str] = None
|
|
self._branch: Optional[str] = None
|
|
self._version: Optional[str] = None
|
|
|
|
def set_from_json(self, content: Optional[Dict]):
|
|
filled_content: Dict = self._fill_keys(content)
|
|
self._branch = filled_content[JSON_BRANCH]
|
|
self._dirty = filled_content[JSON_DIRTY]
|
|
self._commit_hash = filled_content[JSON_COMMIT_HASH]
|
|
self._version = filled_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
|
|
}
|
|
|
|
@property
|
|
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
|
|
|
|
@property
|
|
def version(self) -> str:
|
|
if self._version is None:
|
|
return DEFAULT_VERSION
|
|
return self._version
|
|
|
|
@version.setter
|
|
def version(self, version: str):
|
|
self._version = version
|
|
|
|
@property
|
|
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
|
|
|
|
@property
|
|
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
|