From fd84063edc73aede317019dead5549aef2ba6b2e Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 9 Feb 2023 12:52:58 +0100 Subject: [PATCH] Fix file handling and version creation --- devops_test.py | 15 ++++++++++++--- file_handlers.py | 10 +++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/devops_test.py b/devops_test.py index 1a2806b..ec0b2ab 100644 --- a/devops_test.py +++ b/devops_test.py @@ -4,8 +4,12 @@ from file_handlers import FileHandler def init_project(): # validate_values() version = Version.from_file('build.gradle') - version.increment(ReleaseLevel.SNAPSHOT) - version.write() + v2 = Version.from_file('package.json') + print(type(version.file_handler)) + print(type(v2.file_handler)) + # version.increment(ReleaseLevel.SNAPSHOT) + # version.write() + print(version.get()) def prepare_release(): pass @@ -24,11 +28,16 @@ class Version(): def __init__(self, version, is_snapshot): self.version = version self.is_snapshot = is_snapshot + self.file_handler = None @classmethod def from_file(cls, config_file_path): file_handler = FileHandler.from_file_path(config_file_path) - return cls(file_handler.parse()) + version, is_snapshot = file_handler.parse() + inst = cls(version, is_snapshot) + inst.file_handler = file_handler + + return inst def increment(self, level: ReleaseLevel): self.is_snapshot = False diff --git a/file_handlers.py b/file_handlers.py index c7fec26..3543833 100644 --- a/file_handlers.py +++ b/file_handlers.py @@ -63,11 +63,14 @@ class GradleFileHandler(FileHandler): raise Exception("Version not found in gradle file") version_string = version_string.group() + is_snapshot = False if '-SNAPSHOT' in version_string: - self.is_snapshot = True + is_snapshot = True version_string = version_string.replace('-SNAPSHOT', '') - self.version = [int(x) for x in version_string.split('.')] + version = [int(x) for x in version_string.split('.')] + + return version, is_snapshot def write(self): with open(self.config_file_path, 'r+') as gradle_file: @@ -76,6 +79,3 @@ class GradleFileHandler(FileHandler): gradle_file.seek(0) gradle_file.write(version_substitute) gradle_file.truncate() - -a = FileHandler.from_file_path('build.gradle') -print(type(a)) \ No newline at end of file