import re class BlenderVersion: def __init__(self, version: str = '5.1.0'): """ Need an object like 'X.Y.Z' to work correctly, build a pythonic object about a blender version. :param version: """ self._check_pattern(version) self.major : str = '' self.minor : str = '' self.hotfix : str = '' self.version_object(version) def version_object(self, version: str): """Set all version properties to a string""" version = version.split('.') self.major = version[0] self.minor = version[1] self.hotfix = version[2] def format_to_tag(self, repository: str) -> str: """From version information, format to return a string""" return f'{repository}:{self.major}.{self.minor}.{self.hotfix}' def tag_name(self) -> str: """Return the tag name 'latest', 'X.Y.Z'...""" return f'{self.major}.{self.minor}.{self.hotfix}' def tag_name_slugify(self): return f'{self.major}-{self.minor}-{self.hotfix}' @staticmethod def _check_pattern(tested: str): """Simple test to look if the string give can be a blender version name.""" test = re.match(r'^[0-9]{1}.[0-9]+.[0-9]+$', tested) if test is None: print(f'Bad version name set: {tested}') exit(1) def __str__(self): return str(self.major + '.' + self.minor + '.' + self.hotfix)