2022-02-04 11:39:15 +01:00
|
|
|
from typing import Optional
|
|
|
|
from .constants import *
|
|
|
|
|
|
|
|
|
|
|
|
class GitVersionInfo:
|
|
|
|
def __init__(self, dictionary: dict):
|
|
|
|
if not all(
|
|
|
|
x in dictionary.keys() for
|
|
|
|
x in [JSON_BRANCH, JSON_COMMIT_HASH]
|
|
|
|
):
|
2022-02-05 19:05:50 +01:00
|
|
|
raise NotImplementedError
|
2022-02-04 11:39:15 +01:00
|
|
|
|
|
|
|
self._dirty: bool = dictionary[JSON_DIRTY]
|
|
|
|
self._commit_hash: str = dictionary[JSON_COMMIT_HASH]
|
|
|
|
self._branch: Optional[str] = \
|
|
|
|
dictionary[JSON_BRANCH] if JSON_BRANCH in dictionary.keys() \
|
|
|
|
else None
|
|
|
|
self._version: Optional[str] = \
|
|
|
|
dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \
|
|
|
|
else None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_dirty(self) -> bool:
|
|
|
|
return self._dirty
|
|
|
|
|
|
|
|
@property
|
|
|
|
def version(self) -> Optional[str]:
|
|
|
|
return self._version
|
|
|
|
|
|
|
|
@property
|
|
|
|
def commit_hash(self) -> Optional[str]:
|
|
|
|
return self._commit_hash
|
|
|
|
|
|
|
|
@property
|
|
|
|
def branch(self) -> Optional[str]:
|
|
|
|
return self._branch
|
|
|
|
|
|
|
|
|
|
|
|
class FileVersionInfo:
|
|
|
|
def __init__(self, dictionary: dict):
|
|
|
|
if JSON_MD5_CHECKSUM not in dictionary.keys():
|
2022-02-05 19:05:50 +01:00
|
|
|
raise NotImplementedError
|
2022-02-04 11:39:15 +01:00
|
|
|
else:
|
|
|
|
self._md5_checksum = dictionary[JSON_MD5_CHECKSUM]
|
|
|
|
|
|
|
|
self._source_repository_version: Optional[GitVersionInfo] = \
|
|
|
|
GitVersionInfo(dictionary[JSON_REPOSITORY]) if JSON_REPOSITORY in dictionary.keys() \
|
|
|
|
else None
|
|
|
|
self._pytex_repository_version: Optional[GitVersionInfo] = \
|
|
|
|
GitVersionInfo(dictionary[JSON_PYTEX]) if JSON_PYTEX in dictionary.keys() \
|
|
|
|
else None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def md5_checksum(self) -> str:
|
|
|
|
return self._md5_checksum
|
|
|
|
|
|
|
|
@property
|
|
|
|
def source_repository_version(self) -> Optional[GitVersionInfo]:
|
|
|
|
return self._source_repository_version
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pytex_repository_version(self) -> Optional[GitVersionInfo]:
|
|
|
|
return self._pytex_repository_version
|