2023-02-16 15:55:23 +00:00
|
|
|
from file_handlers import FileHandler
|
|
|
|
|
|
|
|
class VersionRepository():
|
|
|
|
|
|
|
|
def __init__(self, file):
|
|
|
|
self.file = file
|
2023-02-20 12:33:28 +00:00
|
|
|
self.file_handler = None
|
2023-02-20 12:47:14 +00:00
|
|
|
self.version_list = None
|
2023-02-20 12:33:28 +00:00
|
|
|
self.is_snapshot = None
|
|
|
|
|
|
|
|
def load_file(self):
|
|
|
|
self.file_handler = FileHandler.from_file_path(self.file)
|
|
|
|
return file_handler
|
2023-02-16 15:55:23 +00:00
|
|
|
|
2023-02-20 12:47:14 +00:00
|
|
|
def write_file(self, version_string):
|
2023-02-20 12:33:28 +00:00
|
|
|
if self.file_handler is None:
|
|
|
|
raise Exception('Version was not created by load_file method.')
|
2023-02-20 12:47:14 +00:00
|
|
|
if self.version_list is None or self.is_snapshot is None:
|
2023-02-20 12:33:28 +00:00
|
|
|
raise Exception('Version or is_snapshot attribute not set.')
|
|
|
|
else:
|
2023-02-20 12:47:14 +00:00
|
|
|
self.file_handler.write(version_string)
|
2023-02-20 12:33:28 +00:00
|
|
|
|
|
|
|
def parse_file(self, file_handler):
|
2023-02-20 12:47:14 +00:00
|
|
|
version_list, is_snapshot = file_handler.parse()
|
|
|
|
return version_list, is_snapshot
|
2023-02-20 12:33:28 +00:00
|
|
|
|
|
|
|
@classmethod
|
2023-02-20 15:50:12 +00:00
|
|
|
def get(cls, file):
|
2023-02-20 12:33:28 +00:00
|
|
|
inst = cls(file)
|
|
|
|
|
|
|
|
file_handler= inst.load_file(file)
|
2023-02-20 12:47:14 +00:00
|
|
|
version_list, is_snapshot = inst.parse_file(file_handler)
|
2023-02-20 12:33:28 +00:00
|
|
|
|
2023-02-20 13:07:58 +00:00
|
|
|
inst.version_list = version_list
|
2023-02-20 12:33:28 +00:00
|
|
|
inst.is_snapshot = is_snapshot
|
2023-02-16 15:55:23 +00:00
|
|
|
inst.file_handler = file_handler
|
|
|
|
|
2023-02-20 12:33:28 +00:00
|
|
|
return inst
|