Simplify set/get version functions
This commit is contained in:
parent
6399a1dfeb
commit
07cf837ac6
1 changed files with 2 additions and 22 deletions
|
@ -62,11 +62,7 @@ class BuildFile(Validateable):
|
||||||
match build_file_type:
|
match build_file_type:
|
||||||
case BuildFileType.JS:
|
case BuildFileType.JS:
|
||||||
version_str = json.loads(self.content)["version"]
|
version_str = json.loads(self.content)["version"]
|
||||||
case BuildFileType.JAVA_GRADLE:
|
case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE:
|
||||||
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
|
||||||
case BuildFileType.PYTHON:
|
|
||||||
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
|
||||||
case BuildFileType.JAVA_CLOJURE:
|
|
||||||
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
||||||
except:
|
except:
|
||||||
raise RuntimeError(f"Version not found in file {self.file_path}")
|
raise RuntimeError(f"Version not found in file {self.file_path}")
|
||||||
|
@ -88,23 +84,7 @@ class BuildFile(Validateable):
|
||||||
json_data = json.loads(self.content)
|
json_data = json.loads(self.content)
|
||||||
json_data["version"] = new_version.to_string()
|
json_data["version"] = new_version.to_string()
|
||||||
self.content = json.dumps(json_data, indent=4)
|
self.content = json.dumps(json_data, indent=4)
|
||||||
case BuildFileType.JAVA_GRADLE:
|
case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE:
|
||||||
substitute = re.sub(
|
|
||||||
self.__get_file_type_regex_str(build_file_type),
|
|
||||||
fr'\g<pre_version>"{new_version.to_string()}"',
|
|
||||||
self.content,
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
self.content = substitute
|
|
||||||
case BuildFileType.PYTHON:
|
|
||||||
substitute = re.sub(
|
|
||||||
self.__get_file_type_regex_str(build_file_type),
|
|
||||||
fr'\g<pre_version>"{new_version.to_string()}"',
|
|
||||||
self.content,
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
self.content = substitute
|
|
||||||
case BuildFileType.JAVA_CLOJURE:
|
|
||||||
substitute = re.sub(
|
substitute = re.sub(
|
||||||
self.__get_file_type_regex_str(build_file_type),
|
self.__get_file_type_regex_str(build_file_type),
|
||||||
fr'\g<pre_version>"{new_version.to_string()}"',
|
fr'\g<pre_version>"{new_version.to_string()}"',
|
||||||
|
|
Loading…
Reference in a new issue