From 2e4acab09a98628d7a4003e25d8051ad4b199869 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 28 May 2018 18:46:35 -0400 Subject: [PATCH] patch.py now includes the jar hash --- patch.py | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/patch.py b/patch.py index b836f72b..b19ce837 100644 --- a/patch.py +++ b/patch.py @@ -1,19 +1,40 @@ import json import subprocess +from hashlib import sha256 # This script will: # - read current version # - increment patch version # - update version in a few places # - insert new line in ripme.json with message +# - build ripme +# - add the hash of the lastest binary to ripme.json message = input('message: ') -with open('ripme.json') as dataFile: - ripmeJson = json.load(dataFile) -currentVersion = ripmeJson["latestVersion"] +def get_ripme_json(): + with open('ripme.json') as dataFile: + ripmeJson = json.load(dataFile) + return ripmeJson -print ('Current version ' + currentVersion) +def update_hash(current_hash): + ripmeJson = get_ripme_json() + with open('ripme.json', 'w') as dataFile: + ripmeJson["currentHash"] = current_hash + print(ripmeJson["currentHash"]) + json.dump(ripmeJson, dataFile, indent=4) + +def update_change_list(message): + ripmeJson = get_ripme_json() + with open('ripme.json', 'w') as dataFile: + ripmeJson["changeList"] = ripmeJson["changeList"].insert(0, message) + print(ripmeJson["currentHash"]) + json.dump(ripmeJson, dataFile, indent=4) + + +currentVersion = get_ripme_json()["latestVersion"] + +print('Current version ' + currentVersion) versionFields = currentVersion.split('.') patchCur = int(versionFields[2]) @@ -22,14 +43,14 @@ majorMinor = versionFields[:2] majorMinor.append(str(patchNext)) nextVersion = '.'.join(majorMinor) -print ('Updating to ' + nextVersion) +print('Updating to ' + nextVersion) substrExpr = 's/' + currentVersion + '/' + nextVersion + '/' subprocess.call(['sed', '-i', '-e', substrExpr, 'src/main/java/com/rarchives/ripme/ui/UpdateUtils.java']) subprocess.call(['git', 'grep', 'DEFAULT_VERSION.*' + nextVersion, 'src/main/java/com/rarchives/ripme/ui/UpdateUtils.java']) -substrExpr = 's/\\\"latestVersion\\\": \\\"' + currentVersion + '\\\"/\\\"latestVersion\\\": \\\"' +\ +substrExpr = 's/\\\"latestVersion\\\": \\\"' + currentVersion + '\\\"/\\\"latestVersion\\\": \\\"' + \ nextVersion + '\\\"/' subprocess.call(['sed', '-i', '-e', substrExpr, 'ripme.json']) subprocess.call(['git', 'grep', 'latestVersion', 'ripme.json']) @@ -51,6 +72,15 @@ dataFile = open("ripme.json", "w") dataFile.write(outputContent) dataFile.close() -subprocess.call(['git', 'add', '-u']) -subprocess.call(['git', 'commit', '-m', commitMessage]) -subprocess.call(['git', 'tag', nextVersion]) +# subprocess.call(['git', 'add', '-u']) +# subprocess.call(['git', 'commit', '-m', commitMessage]) +# subprocess.call(['git', 'tag', nextVersion]) +print("Building ripme") +subprocess.call(["mvn", "clean", "compile", "assembly:single"]) +print("Hashing .jar file") +openedFile = open("./target/ripme-{}-jar-with-dependencies.jar".format(nextVersion), "rb") +readFile = openedFile.read() +file_hash = sha256(readFile).hexdigest() +print("Hash is: {}".format(file_hash)) +print("Updating hash") +update_hash(file_hash) \ No newline at end of file