terraformDummyRepo/version_repository.py

32 lines
1 KiB
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 14:52:09 +00:00
return file_handler
2023-02-16 15:55:23 +00:00
def write_file(self, version_string):
if self.file_handler is None:
raise Exception('Version was not created by load_file method.')
if self.version_list is None or self.is_snapshot is None:
raise Exception('Version or is_snapshot attribute not set.')
else:
self.file_handler.write(version_string)
def parse_file(self, file_handler):
version_list, is_snapshot = 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 14:52:09 +00:00
self.file_handler = self.load_file(self.file)
version_list, is_snapshot = self.parse_file(file_handler)
2023-02-16 15:55:23 +00:00
2023-02-21 14:52:09 +00:00
return Version(version_list, release_type)