#!/usr/bin/python ##################################################################### # Helper script to release ##################################################################### import sys, os import getopt import signal import time # defines global options enableDryRun = False enableTizenMain = False enablePushTag = False patchVersion = 0 commitId = "" def help(): print (""" Usage: release-webkit [OPTION] [Options] -h, --help : Print this message. -n, --dry-run : Don't actually run any commands; just print them. -i, --tizen : Create Release commit in tizen_2.2 branch and push to Gerrit. (Tizen:2.2:Mobile) -t, --push-tag : Add tag and Send SR(Submit Request). """) def checkRepo(repo): currentRepo = "RSA" os.system("git remote -v > tmp") inputFile = open("tmp", "r") for line in inputFile: if (("origin" in line) and ("magnolia" in line)): print("ERROR : This command can executed only RSA repo.") exit() def checkoutBranch(branch): findBranch = False os.system("git branch > tmp") inputFile = open("tmp", "r") for line in inputFile: if (line.find(branch) > -1): execute("git checkout " + branch) findBranch = True if findBranch == False: execute("git checkout -b " + branch + " origin/" + branch) inputFile.close() os.system("rm tmp") def execute(command): if enableDryRun: print(command) else: os.system(command) def getPath(): path = "" if "TizenScripts" in os.getcwd(): path = "../" return path def getTagMsg(branch): global commitId, patchVersion os.system("git log " + branch + " > tmp") #Find commit id, tag msg inputFile = open("tmp","r") #Find commit Id for line in inputFile: if "commit" in line: commitId = line.replace("commit ","").strip() elif line.find("[Release] Webkit2-efl-123997") == 4: patchVersion = line.replace("[Release] ", "").strip() break inputFile.close() tag = "" os.system("git log " + commitId + " > tmp") inputFile = open("tmp","r") findFirstCommit = False saveTag = False for line in inputFile: if line.find("[") == 4: if "[Release] Webkit2" in line: if findFirstCommit == False: findFirstCommit = True else: break else: if "[Title]" in line: tag +='\n' elif "[Solution]" in line: saveTag = True elif "[Problem]" in line: saveTag = True elif "[Cause]" in line: saveTag = True if line.find("[WK2]") == -1: tag += line.strip() + '\n' else: if "Change-Id" in line: saveTag = False if "commit" in line: saveTag = False if len(line.strip()) < 1: saveTag = False if saveTag: tag += line.strip() + '\n' outputFile = open("tmp_tag","w") outputFile.write(tag) outputFile.close() inputFile.close() os.system("rm tmp") def checkNewPatch(): os.system("git log > tmp_log") isFirst = False noPatch = False inputFile = open("tmp_log", "r") for line in inputFile: if "commit" in line: if isFirst: break else: isFirst = True else: if isFirst: if "[Release] Webkit2" in line: noPatch = True inputFile.close() os.system("rm tmp_log") if noPatch: print "There is no new patch after previous release." exit() def versionUp(minor): global patchVersion path = getPath() # Change version in OptionsTizen.cmake inputFile = open(path + "Source/cmake/OptionsTizen.cmake","r") outputFile = open("tmp","w") for line in inputFile: if "SET(PROJECT_VERSION_PATCH" in line: patchVersion = line.replace("SET(PROJECT_VERSION_PATCH ", "") patchVersion = patchVersion.replace(")", "") patchVersion = int(patchVersion) + 1 tmp = "SET(PROJECT_VERSION_PATCH " + str(patchVersion) +")\n" outputFile.write(tmp) print "Modified PROJECT_VERSION_PATCH in OptionsTizen.cmake to " + tmp.strip() else: outputFile.write(line) inputFile.close() outputFile.close() if enableDryRun: os.system("rm tmp") else: os.system("chmod 644 tmp") os.system("mv tmp " + path + "Source/cmake/OptionsTizen.cmake") # Change version in webkit2-efl.spec inputFile = open(path + "packaging/webkit2-efl.spec","r") outputFile = open("tmp","w") for line in inputFile: if "Version:" in line: tmp = "Version: 123997_0." + str(minor) + "." + str(patchVersion) + "\n" outputFile.write(tmp) print "Modified Version in webkit2-efl.spec to " + tmp.strip() else: outputFile.write(line) inputFile.close() outputFile.close() if enableDryRun: os.system("rm tmp") else: os.system("chmod 644 tmp") os.system("mv tmp " + path + "packaging/webkit2-efl.spec") execute("git add " + path + "Source/cmake/OptionsTizen.cmake " + path + "packaging/webkit2-efl.spec" ) def TizenMain(): global patchVersion branchName = "tizen_2.2" minorVersion = 11 checkRepo("RSA") checkoutBranch(branchName) checkNewPatch() versionUp(minorVersion) execute("git commit -m '[Release] Webkit2-efl-123997_0." + str(minorVersion) + "." + str(patchVersion) + "'" ) execute("git push origin HEAD:refs/for/" + branchName) print "Release commit created." def pushTag(): branchName = "tizen_2.2" getTagMsg(branchName) execute("git tag -a submit/" + branchName + "/`date --utc +%Y%m%d.%H%M%S` -F tmp_tag") execute("git push --tags") print "Release " + branchName + " finished." def release(): count = 0 if enableTizenMain: count = count + 1 if enablePushTag: count = count + 1 if count > 1: print "ERROR : Invalid Options" help() exit() if enableTizenMain: TizenMain() if enablePushTag: pushTag() if count == 0: help() def main(): global enableDryRun, enableTizenMain, enablePushTag optlist, args = getopt.getopt(sys.argv[1:], 'hnit', [ 'help', 'dry-run', 'tizen', 'push-tag' ]) for opt, var in optlist: if opt in ('--help', '-h'): help() exit() if opt in ('--dry-run', '-n'): enableDryRun = True if opt in ('--tizen', '-i'): enableTizenMain = True if opt in ('--push-tag', '-t'): enablePushTag = True release() main()