terraformDummyRepo/version_repository.py

38 lines
1.1 KiB
Python

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)
return self.file_handler
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
def get(cls, file):
inst = cls(file)
file_handler = inst.load_file()
version_list, is_snapshot = inst.parse_file(file_handler)
inst.version_list = version_list
inst.is_snapshot = is_snapshot
inst.file_handler = file_handler
return inst