61 lines
No EOL
1.8 KiB
Python
61 lines
No EOL
1.8 KiB
Python
from enum import Enum
|
|
from file_handlers import FileHandler
|
|
|
|
def init_project():
|
|
# validate_values()
|
|
version = Version.from_file('build.gradle')
|
|
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
|
|
|
|
def release_in_git():
|
|
pass
|
|
|
|
class ReleaseLevel(Enum):
|
|
MAJOR = 0
|
|
MINOR = 1
|
|
PATCH = 2
|
|
SNAPSHOT = 3
|
|
|
|
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)
|
|
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
|
|
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(self) -> str:
|
|
version_string = ".".join([str(x) for x in self.version])
|
|
if self.is_snapshot:
|
|
version_string += "-SNAPSHOT"
|
|
return version_string |