2023-02-08 10:22:55 +00:00
|
|
|
from enum import Enum
|
2023-02-09 11:38:04 +00:00
|
|
|
from file_handlers import FileHandler
|
2023-02-08 09:57:40 +00:00
|
|
|
|
|
|
|
def init_project():
|
|
|
|
# validate_values()
|
2023-02-09 12:20:42 +00:00
|
|
|
version = Version.from_file('build.gradle')
|
|
|
|
version.increment(ReleaseLevel.SNAPSHOT)
|
|
|
|
version.to_file()
|
2023-02-09 11:52:58 +00:00
|
|
|
print(version.get())
|
2023-02-08 09:57:40 +00:00
|
|
|
|
|
|
|
def prepare_release():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def release_in_git():
|
|
|
|
pass
|
|
|
|
|
2023-02-08 10:37:41 +00:00
|
|
|
class ReleaseLevel(Enum):
|
2023-02-08 10:52:15 +00:00
|
|
|
MAJOR = 0
|
|
|
|
MINOR = 1
|
|
|
|
PATCH = 2
|
|
|
|
SNAPSHOT = 3
|
2023-02-08 09:57:40 +00:00
|
|
|
|
2023-02-08 10:37:41 +00:00
|
|
|
class Version():
|
2023-02-08 10:22:55 +00:00
|
|
|
|
2023-02-09 11:02:31 +00:00
|
|
|
def __init__(self, version, is_snapshot):
|
|
|
|
self.version = version
|
|
|
|
self.is_snapshot = is_snapshot
|
2023-02-09 11:52:58 +00:00
|
|
|
self.file_handler = None
|
2023-02-09 11:02:31 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_file(cls, config_file_path):
|
2023-02-09 11:38:04 +00:00
|
|
|
file_handler = FileHandler.from_file_path(config_file_path)
|
2023-02-09 11:52:58 +00:00
|
|
|
version, is_snapshot = file_handler.parse()
|
|
|
|
inst = cls(version, is_snapshot)
|
|
|
|
inst.file_handler = file_handler
|
|
|
|
|
|
|
|
return inst
|
2023-02-09 10:43:10 +00:00
|
|
|
|
2023-02-09 12:20:42 +00:00
|
|
|
def to_file(self):
|
|
|
|
if self.file_handler is None:
|
|
|
|
raise Exception('Version was not created by from_file method.')
|
|
|
|
else:
|
|
|
|
self.file_handler.write(self.get())
|
|
|
|
|
2023-02-08 10:22:55 +00:00
|
|
|
def increment(self, level: ReleaseLevel):
|
2023-02-08 11:37:00 +00:00
|
|
|
self.is_snapshot = False
|
|
|
|
match level:
|
|
|
|
case ReleaseLevel.SNAPSHOT:
|
|
|
|
self.is_snapshot = True
|
|
|
|
case ReleaseLevel.PATCH:
|
|
|
|
self.version[ReleaseLevel.PATCH.value] += 1
|
2023-02-08 10:22:55 +00:00
|
|
|
case ReleaseLevel.MINOR:
|
2023-02-08 11:37:00 +00:00
|
|
|
self.version[ReleaseLevel.PATCH.value] = 0
|
|
|
|
self.version[ReleaseLevel.MINOR.value] += 1
|
2023-02-08 10:22:55 +00:00
|
|
|
case ReleaseLevel.MAJOR:
|
2023-02-08 11:37:00 +00:00
|
|
|
self.version[ReleaseLevel.PATCH.value] = 0
|
|
|
|
self.version[ReleaseLevel.MINOR.value] = 0
|
|
|
|
self.version[ReleaseLevel.MAJOR.value] += 1
|
|
|
|
|
2023-02-08 10:37:41 +00:00
|
|
|
def get(self) -> str:
|
2023-02-08 11:37:00 +00:00
|
|
|
version_string = ".".join([str(x) for x in self.version])
|
|
|
|
if self.is_snapshot:
|
|
|
|
version_string += "-SNAPSHOT"
|
|
|
|
return version_string
|