erik
ecdea88a6b
Avoid ambiguous variable names. We are handling a version list and a version string.
48 lines
No EOL
1.4 KiB
Python
48 lines
No EOL
1.4 KiB
Python
from enum import Enum
|
|
from file_handlers import FileHandler
|
|
|
|
def init_project():
|
|
# validate_values()
|
|
version = Version.from_file('build.gradle')
|
|
version.increment(ReleaseLevel.SNAPSHOT)
|
|
version.to_file()
|
|
print(version.get())
|
|
|
|
def prepare_release():
|
|
pass
|
|
|
|
def release_in_git():
|
|
pass
|
|
|
|
class ReleaseLevel(Enum):
|
|
MAJOR = 0
|
|
MINOR = 1
|
|
PATCH = 2
|
|
SNAPSHOT = 3
|
|
|
|
class Version():
|
|
|
|
def __init__(self, version_list, is_snapshot):
|
|
self.version_list = version_list
|
|
self.is_snapshot = is_snapshot
|
|
|
|
def increment(self, level: ReleaseLevel):
|
|
self.is_snapshot = False
|
|
match level:
|
|
case ReleaseLevel.SNAPSHOT:
|
|
self.is_snapshot = True
|
|
case ReleaseLevel.PATCH:
|
|
self.version[ReleaseLevel.PATCH.value] += 1
|
|
case ReleaseLevel.MINOR:
|
|
self.version[ReleaseLevel.PATCH.value] = 0
|
|
self.version[ReleaseLevel.MINOR.value] += 1
|
|
case ReleaseLevel.MAJOR:
|
|
self.version[ReleaseLevel.PATCH.value] = 0
|
|
self.version[ReleaseLevel.MINOR.value] = 0
|
|
self.version[ReleaseLevel.MAJOR.value] += 1
|
|
|
|
def get_version_string(self) -> str:
|
|
version_string = ".".join([str(x) for x in self.version_list])
|
|
if self.is_snapshot:
|
|
version_string += "-SNAPSHOT"
|
|
return version_string |