Clear selection when back key is called from picker popup
[framework/web/webkit-efl.git] / TizenScripts / release-webkit
1 #!/usr/bin/python
2 #####################################################################
3 # Helper script to release
4 #####################################################################
5 import sys, os
6 import getopt
7 import signal
8 import time
9
10 # defines global options
11 enableDryRun = False
12 enableTizenMain = False
13 enablePushTag = False
14
15 patchVersion = 0
16 commitId = ""
17
18 def help():
19     print ("""
20 Usage: release-webkit [OPTION]
21
22 [Options]
23    -h, --help        : Print this message.
24    -n, --dry-run     : Don't actually run any commands; just print them.
25    -i, --tizen       : Create Release commit in tizen_2.2 branch and push to Gerrit. (Tizen:2.2:Mobile)
26    -t, --push-tag    : Add tag and Send SR(Submit Request).
27 """)
28
29 def checkRepo(repo):
30
31     currentRepo = "RSA"
32     os.system("git remote -v > tmp")
33     inputFile = open("tmp", "r")
34
35     for line in inputFile:
36         if (("origin" in line) and ("magnolia" in line)):
37             print("ERROR : This command can executed only RSA repo.")
38             exit()
39
40 def checkoutBranch(branch):
41     findBranch = False
42     os.system("git branch > tmp")
43     inputFile = open("tmp", "r")
44
45     for line in inputFile:
46         if (line.find(branch) > -1):
47             execute("git checkout " + branch)
48             findBranch = True
49
50     if findBranch == False:
51         execute("git checkout -b " + branch + " origin/" + branch)
52
53     inputFile.close()
54     os.system("rm tmp")
55
56 def execute(command):
57     if enableDryRun:
58         print(command)
59     else:
60         os.system(command)
61
62 def getPath():
63     path = ""
64     if "TizenScripts" in os.getcwd():
65         path = "../"
66     return path
67
68 def getTagMsg(branch):
69     global commitId, patchVersion
70
71     os.system("git log " + branch + " > tmp")
72     #Find commit id, tag msg
73
74     inputFile = open("tmp","r")
75
76     #Find commit Id
77     for line in inputFile:
78         if "commit" in line:
79             commitId = line.replace("commit ","").strip()
80         elif line.find("[Release] Webkit2-efl-123997") == 4:
81             patchVersion = line.replace("[Release] ", "").strip()
82             break
83     inputFile.close()
84
85     tag = ""
86     os.system("git log " + commitId + " > tmp")
87     inputFile = open("tmp","r")
88
89     findFirstCommit = False
90     saveTag = False
91
92     for line in inputFile:
93         if line.find("[") == 4:
94             if "[Release] Webkit2" in line:
95                 if findFirstCommit == False:
96                     findFirstCommit = True
97                 else:
98                    break
99             else:
100                 if "[Title]" in line:
101                     tag +='\n'
102                 elif "[Solution]" in line:
103                     saveTag = True
104                 elif "[Problem]" in line:
105                     saveTag = True
106                 elif "[Cause]" in line:
107                     saveTag = True
108
109             if line.find("[WK2]") == -1:
110                     tag += line.strip() + '\n'
111         else:
112             if "Change-Id" in line:
113                 saveTag = False
114             if "commit" in line:
115                 saveTag = False
116             if len(line.strip()) < 1:
117                 saveTag = False
118             if saveTag:
119                 tag += line.strip() + '\n'
120     outputFile = open("tmp_tag","w")
121     outputFile.write(tag)
122     outputFile.close()
123     inputFile.close()
124
125     os.system("rm tmp")
126
127 def checkNewPatch():
128     os.system("git log > tmp_log")
129     isFirst = False
130     noPatch = False
131
132     inputFile = open("tmp_log", "r")
133     for line in inputFile:
134         if "commit" in line:
135             if isFirst:
136                 break
137             else:
138                 isFirst = True
139         else:
140             if isFirst:
141                 if "[Release] Webkit2" in line:
142                     noPatch = True
143
144     inputFile.close()
145     os.system("rm tmp_log")
146
147     if noPatch:
148         print "There is no new patch after previous release."
149         exit()
150
151 def versionUp(minor):
152     global patchVersion
153     path = getPath()
154
155     # Change version in OptionsTizen.cmake
156     inputFile = open(path + "Source/cmake/OptionsTizen.cmake","r")
157     outputFile = open("tmp","w")
158
159     for line in inputFile:
160         if "SET(PROJECT_VERSION_PATCH" in line:
161             patchVersion = line.replace("SET(PROJECT_VERSION_PATCH ", "")
162             patchVersion = patchVersion.replace(")", "")
163
164             patchVersion = int(patchVersion) + 1
165
166             tmp = "SET(PROJECT_VERSION_PATCH " + str(patchVersion) +")\n"
167             outputFile.write(tmp)
168             print "Modified PROJECT_VERSION_PATCH in OptionsTizen.cmake to " + tmp.strip()
169         else:
170             outputFile.write(line)
171
172     inputFile.close()
173     outputFile.close()
174
175     if enableDryRun:
176         os.system("rm tmp")
177     else:
178         os.system("chmod 644 tmp")
179         os.system("mv tmp " + path + "Source/cmake/OptionsTizen.cmake")
180
181     # Change version in webkit2-efl.spec
182     inputFile = open(path + "packaging/webkit2-efl.spec","r")
183     outputFile = open("tmp","w")
184
185     for line in inputFile:
186         if "Version:" in line:
187             tmp = "Version: 123997_0." + str(minor) + "." + str(patchVersion) + "\n"
188             outputFile.write(tmp)
189             print "Modified Version in webkit2-efl.spec to " + tmp.strip()
190         else:
191             outputFile.write(line)
192
193     inputFile.close()
194     outputFile.close()
195
196     if enableDryRun:
197         os.system("rm tmp")
198     else:
199         os.system("chmod 644 tmp")
200         os.system("mv tmp " + path + "packaging/webkit2-efl.spec")
201
202     execute("git add " + path + "Source/cmake/OptionsTizen.cmake " + path + "packaging/webkit2-efl.spec" )
203
204 def TizenMain():
205     global patchVersion
206     branchName = "tizen_2.2"
207     minorVersion = 11
208     checkRepo("RSA")
209     checkoutBranch(branchName)
210     checkNewPatch()
211
212     versionUp(minorVersion)
213     execute("git commit -m '[Release] Webkit2-efl-123997_0." + str(minorVersion) + "." + str(patchVersion) + "'" )
214     execute("git push origin HEAD:refs/for/" + branchName)
215
216     print "Release commit created."
217
218 def pushTag():
219     branchName = "tizen_2.2"
220
221     getTagMsg(branchName)
222     execute("git tag -a submit/" + branchName + "/`date --utc +%Y%m%d.%H%M%S` -F tmp_tag")
223     execute("git push --tags")
224
225     print "Release " + branchName + " finished."
226
227 def release():
228     count = 0
229
230     if enableTizenMain:
231         count = count + 1
232     if enablePushTag:
233         count = count + 1
234
235     if count > 1:
236         print "ERROR : Invalid Options"
237         help()
238         exit()
239
240     if enableTizenMain:
241         TizenMain()
242     if enablePushTag:
243         pushTag()
244
245     if count == 0:
246         help()
247
248 def main():
249     global enableDryRun, enableTizenMain, enablePushTag
250     optlist, args = getopt.getopt(sys.argv[1:], 'hnit', [ 'help', 'dry-run', 'tizen', 'push-tag' ])
251     for opt, var in optlist:
252         if opt in ('--help', '-h'):
253             help()
254             exit()
255         if opt in ('--dry-run', '-n'):
256             enableDryRun = True
257         if opt in ('--tizen', '-i'):
258             enableTizenMain = True
259         if opt in ('--push-tag', '-t'):
260             enablePushTag = True
261     release()
262 main()