dda-devops-build/version_repository.py

39 lines
1.1 KiB
Python
Raw Normal View History

2023-02-16 15:55:23 +00:00
from file_handlers import FileHandler
class VersionRepository():
def __init__(self, file):
self.file = file
self.file_handler = None
self.version_list = None
self.is_snapshot = None
def load_file(self):
self.file_handler = FileHandler.from_file_path(self.file)
2023-02-21 08:54:18 +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:
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
@classmethod
2023-02-20 15:50:12 +00:00
def get(cls, file):
inst = cls(file)
2023-02-21 08:54:18 +00:00
file_handler = inst.load_file()
version_list, is_snapshot = inst.parse_file(file_handler)
2023-02-20 13:07:58 +00:00
inst.version_list = version_list
inst.is_snapshot = is_snapshot
2023-02-16 15:55:23 +00:00
inst.file_handler = file_handler
return inst