dda-devops-build/version_repository.py

33 lines
976 B
Python
Raw Normal View History

2023-02-16 15:55:23 +00:00
from file_handlers import FileHandler
2023-02-21 14:52:09 +00:00
from version import Version
2023-02-16 15:55:23 +00:00
class VersionRepository():
def __init__(self, file):
self.file = file
2023-02-21 14:52:09 +00:00
self.file_handler = None
def load_file(self):
self.file_handler = FileHandler.from_file_path(self.file)
2023-02-21 15:14:47 +00:00
return self.file_handler
2023-02-16 15:55:23 +00:00
def write_file(self, version_string):
if self.file_handler is None:
2023-02-21 15:14:47 +00:00
raise Exception('Version was not created by load_file method.')
else:
self.file_handler.write(version_string)
2023-02-21 15:14:47 +00:00
def parse_file(self):
version_list, is_snapshot = self.file_handler.parse()
return version_list, is_snapshot
2023-02-21 14:52:09 +00:00
def get_version(self, release_type):
2023-02-21 15:14:47 +00:00
self.file_handler = self.load_file()
version_list, is_snapshot = self.parse_file()
version = Version(version_list, release_type)
version.is_snapshot = is_snapshot
return version
2023-02-16 15:55:23 +00:00