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
|
2023-02-20 12:33:28 +00:00
|
|
|
|
|
|
|
def load_file(self):
|
|
|
|
self.file_handler = FileHandler.from_file_path(self.file)
|
2023-02-21 15:14:47 +00:00
|
|
|
return self.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:
|
2023-02-21 15:14:47 +00:00
|
|
|
raise Exception('Version was not created by load_file method.')
|
2023-02-20 12:33:28 +00:00
|
|
|
else:
|
2023-02-20 12:47:14 +00:00
|
|
|
self.file_handler.write(version_string)
|
2023-02-20 12:33:28 +00:00
|
|
|
|
2023-02-21 15:14:47 +00:00
|
|
|
def parse_file(self):
|
|
|
|
version_list, is_snapshot = self.file_handler.parse()
|
2023-02-20 12:47:14 +00:00
|
|
|
return version_list, is_snapshot
|
2023-02-21 14:52:09 +00:00
|
|
|
|
2023-02-23 13:38:54 +00:00
|
|
|
def get_version(self):
|
2023-02-20 12:33:28 +00:00
|
|
|
|
2023-02-21 15:14:47 +00:00
|
|
|
self.file_handler = self.load_file()
|
|
|
|
version_list, is_snapshot = self.parse_file()
|
2023-02-23 13:38:54 +00:00
|
|
|
version = Version(version_list)
|
2023-02-21 15:14:47 +00:00
|
|
|
version.is_snapshot = is_snapshot
|
|
|
|
|
|
|
|
return version
|
2023-02-16 15:55:23 +00:00
|
|
|
|