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
|
|
|
|
self.version = None
|
|
|
|
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:33:28 +00:00
|
|
|
def write_file(self):
|
|
|
|
if self.file_handler is None:
|
|
|
|
raise Exception('Version was not created by load_file method.')
|
|
|
|
if self.version is None or self.is_snapshot is None:
|
|
|
|
raise Exception('Version or is_snapshot attribute not set.')
|
|
|
|
else:
|
|
|
|
self.file_handler.write(self.version)
|
|
|
|
|
|
|
|
def parse_file(self, file_handler):
|
2023-02-16 15:55:23 +00:00
|
|
|
version, is_snapshot = file_handler.parse()
|
2023-02-20 12:33:28 +00:00
|
|
|
return version, is_snapshot
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_current_version(cls, file):
|
|
|
|
inst = cls(file)
|
|
|
|
|
|
|
|
file_handler= inst.load_file(file)
|
|
|
|
version, is_snapshot = inst.parse_file(file_handler)
|
|
|
|
|
|
|
|
inst.version = version
|
|
|
|
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
|