From ef7197ee178adfc795dff6c6f4b0e17769bd8f95 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 30 Apr 2018 23:00:55 +0200 Subject: [PATCH] Add file to help generation of new library version --- GenerateNewVersion.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 GenerateNewVersion.py diff --git a/GenerateNewVersion.py b/GenerateNewVersion.py new file mode 100644 index 00000000..ec0c9e91 --- /dev/null +++ b/GenerateNewVersion.py @@ -0,0 +1,51 @@ +# ----- Imports ----- # +import os +import fnmatch +import re +from datetime import date + +# ----- Methods ----- # + +# Method to find and replace some text in files inside a directory +def findReplaceText(directory, findRegex, substituteExpr, filePattern): + for path, dirs, files in os.walk(os.path.abspath(directory)): + for filename in fnmatch.filter(files, filePattern): + filepath = os.path.join(path, filename) + with open(filepath) as f: + s = f.read() + s = re.sub(findRegex, substituteExpr, s) + with open(filepath, "w") as f: + f.write(s) + +# ----- Code ----- # + +# Read new version number from user +oldVersion = raw_input("Enter the old version string: ") + +# Read new version number from user +newVersion = raw_input("Enter the new version string: ") +print("ReactPhysics3D will be updated from version " + oldVersion + " to version " + newVersion) + +# Replace the RP3D version number in the VERSION file +file = open("VERSION", "w") +file.write(newVersion + "\n") +file.close() +print("Version number has been updated in VERSION file") + +# Update the RP3D version number in the documentation/API/Doxyfile +findReplaceText("documentation/API/", r'(PROJECT_NUMBER[ \t]+=[ \t]+)"[\d\.]+"', r'\g<1>"' + newVersion + '"', "Doxyfile") +print("Version number has been updated in documentation/API/Doxyfile file") + +# Update the RP3D version number in the src/configuration.h file +findReplaceText("src/", r'(RP3D_VERSION[ \t]+=[ \t]+std::string\()"[\d\.]+"', r'\g<1>"' + newVersion + '"', "configuration.h") +print("Version number has been updated in src/configuration.h file") + +# Update the copyright date in LICENSE file +findReplaceText("./", '(Copyright ' + re.escape("(c)") + r' 2010-)[\d]+', r'\g<1>' + str(date.today().year), "LICENSE") +print("Copyright date has been updated in LICENSE file") + +# Update the copyright date of the license in every source code files +findReplaceText("src/", '(Copyright ' + re.escape("(c)") + r' 2010-)[\d]+', r'\g<1>' + str(date.today().year), "*.h") +findReplaceText("src/", '(Copyright ' + re.escape("(c)") + r' 2010-)[\d]+', r'\g<1>' + str(date.today().year), "*.cpp") +print("Copyright date in license has been updated in all source code files") +