Fix file handling and version creation
This commit is contained in:
parent
d50b8bd95b
commit
fd84063edc
2 changed files with 17 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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))
|
Loading…
Reference in a new issue