From a20a178effcc56fa4fe0b7d40c5f4e3b816cae21 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 6 Apr 2026 11:17:16 +0200 Subject: [PATCH] Codewars_Aufgabe:_VersionManager --- src/Codewars_Exercises/Versions_manager.py | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Codewars_Exercises/Versions_manager.py diff --git a/src/Codewars_Exercises/Versions_manager.py b/src/Codewars_Exercises/Versions_manager.py new file mode 100644 index 0000000..31e3af7 --- /dev/null +++ b/src/Codewars_Exercises/Versions_manager.py @@ -0,0 +1,47 @@ +class VersionManager: + + def __init__(self, version="0.0.1"): + self.version = version + if self.version == "": + self.version = "0.0.1" + self.digits = self.version.split(sep=".") + while len(self.digits) < 3: + self.digits.append("0") + if not ( + self.digits[0].isdecimal() + and self.digits[1].isdecimal() + and self.digits[2].isdecimal() + ): + raise Exception("Error occured while parsing version!") + self.MAJOR = int(self.digits[0]) + self.MINOR = int(self.digits[1]) + self.PATCH = int(self.digits[2]) + self.history = [] + + def major(self): + self.history.append((self.MAJOR, self.MINOR, self.PATCH)) + self.MAJOR += 1 + self.MINOR = 0 + self.PATCH = 0 + return self + + def minor(self): + self.history.append((self.MAJOR, self.MINOR, self.PATCH)) + self.MINOR += 1 + self.PATCH = 0 + return self + + def patch(self): + self.history.append((self.MAJOR, self.MINOR, self.PATCH)) + self.PATCH += 1 + return self + + def rollback(self): + if len(self.history) < 1: + raise Exception("Cannot rollback!") + else: + self.MAJOR, self.MINOR, self.PATCH = self.history.pop() + return self + + def release(self): + return f"{self.MAJOR}.{self.MINOR}.{self.PATCH}"