forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepareReview.py
242 lines (202 loc) · 6.89 KB
/
prepareReview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import os.path
import optparse
from modules.Config import Config
from modules.SpecParser import SpecParser
import shutil
from os.path import expanduser
from modules.Utils import runCommand
from glob import glob
if __name__ == "__main__":
parser = optparse.OptionParser("%prog")
parser.add_option(
"", "-u", "--user", dest="user", default = "",
help = "FAS username"
)
parser.add_option(
"", "", "--skip-koji", dest="skipkoji", action = "store_true", default = False,
help = "don't run koji build"
)
parser.add_option(
"", "", "--skip-rpmlint-errors", dest="skiprpmlint", action = "store_true", default = False,
help = "skip rpmlint errors if any"
)
options, args = parser.parse_args()
if len(args) != 1:
print "Synopsis: [--user=USER|-u USER] [--skip-koji] SPEC"
exit(1)
specfile = args[0]
user = options.user
if user == "":
user = Config().getFASUsername()
if not os.path.exists(specfile):
print "Spec file %s not found" % specfile
exit(1)
obj = SpecParser(specfile)
if not obj.parse():
print obj.getError()
exit(1)
provider = obj.getMacro("provider")
repo = obj.getMacro("repo")
if provider == "google":
commit = obj.getMacro("rev")
else:
commit = obj.getMacro("commit")
summary = obj.getTag("summary")
name = obj.getTag("name")
print "Parsing %s file" % specfile
print " Provider: %s" % provider
print " Repo: %s" % repo
print " Commit: %s" % commit
print " Name: %s" % name
print " Summary: %s" % summary
print ""
if provider == "":
print "Provider macro is missing"
exit(1)
if repo == "":
print "Repo macro is missing"
exit(1)
if commit == "":
print "Commit macro is missing"
exit(1)
if name == "":
print "Name tag is missing"
exit(1)
if summary == "":
print "Summary tag is missing"
exit(1)
if provider == "bitbucket":
tarball = "%s.zip" % commit[:12]
elif provider == "google":
tarball = "%s.tar.gz" % (commit)
else:
tarball = "%s-%s.tar.gz" % (repo, commit[:7])
spec_dir = os.path.dirname(specfile);
if spec_dir == "":
spec_dir = "."
# copy tarball to ~/rpmbuild/SOURCES
print "Copying tarball %s to %s/rpmbuild/SOURCES" % ("%s/%s" % (spec_dir, tarball), expanduser("~"))
try:
shutil.copyfile("%s/%s" % (spec_dir, tarball), '%s/rpmbuild/SOURCES/%s' % (expanduser("~"), tarball))
except IOError, e:
print "Unable to copy tarball %s: %s" % (tarball, e)
exit(1)
# copy patches if available
for patch in glob("%s/*.patch" % spec_dir):
print "Copying patch %s to %s/rpmbuild/SOURCES" % (patch, expanduser("~"))
try:
shutil.copyfile(patch, '%s/rpmbuild/SOURCES/%s' % (expanduser("~"), patch))
except IOError, e:
print "Unable to copy patch %s: %s" % (patch, e)
exit(1)
print ""
# build spec file
print "Building spec file using rpmbuild"
so, se, rc = runCommand("rpmbuild -ba %s" % specfile)
if rc != 0:
print " Build failed. Check build.log."
print " Error: %s" % se
exit(1)
# line with builds end with .rpm sufix and consists of two columns seperated by whitespace
# in a form "text: pathtorpm.rpm"
builds = filter(lambda l: l.endswith(".rpm") and len(l.split(" ")) == 2, so.split("\n"))
builds = map(lambda l: l.split(" ")[1], builds)
srpm = filter(lambda l: l.endswith("src.rpm"), builds)[0]
for build in builds:
print " %s" % build
print ""
# rpmlint
print "Running rpmlint %s" % " ".join(builds)
so, se, rc = runCommand("rpmlint %s" % " ".join(builds))
rpmlint = so
print so
if rc != 0 and not options.skiprpmlint:
print "Unable to run rpmlint: %s" % se
exit(1)
# build in koji
if not options.skipkoji:
print "Running koji scratch build on srpm"
print "koji build --scratch rawhide %s --nowait" % srpm
so, se, rc = runCommand("koji build --scratch rawhide %s --nowait" % srpm)
if rc != 0:
print "Unable to run scratch build: %s" % se
exit(1)
task = filter(lambda l: l.startswith("Created task: "), so.split("\n"))
if task == []:
print "Unable to get task id"
exit(1)
task_id = task[0].split("Created task: ")[1]
print " Watching rawhide build, http://koji.fedoraproject.org/koji/taskinfo?taskID=%s" % task_id
print "koji watch-task %s --quiet" % task_id
_, _, rc = runCommand("koji watch-task %s --quiet" % task_id)
if rc != 0:
print "Koji watch task failed"
exit(1)
so, se, rc = runCommand("koji taskinfo %s" % task_id)
if rc != 0:
print "Unable to get task info: %s" % se
exit(1)
state = filter(lambda l: l.startswith("State"), so.split("\n"))
if state == []:
print "Unable to get task state"
exit(1)
state = state[0].split("State: ")[1].lower()
if state != "closed":
print " koji scratch build failed"
exit(1)
# parse data for review request for bugzilla
so, se, rc = runCommand("rpm -qpi %s" % srpm)
if rc != 0:
print "Unable to get info from srpm: %s" % se
exit(1)
# description is the last item
index = 0
lines = so.split("\n")
for line in lines:
if not line.startswith("Description"):
index +=1
continue
break
description = "\n".join(lines[index+1:-1])
# upload the srpm to my fedora account
rc = 0
print "Uploading srpm and spec file to @fedorapeople.org"
print '%[email protected] "mkdir -p public_html/reviews/%s"' % (user, name)
so, se, rc = runCommand('ssh %[email protected] "mkdir -p public_html/reviews/%s"' % (user, name))
if rc != 0:
print "Unable to create public_html/reviews/%s dir: %s" % (name, se)
exit(1)
print "scp %s %[email protected]:public_html/reviews/%s/." % (srpm, user, name)
so, se, rc = runCommand("scp %s %[email protected]:public_html/reviews/%s/." % (srpm, user, name))
if rc != 0:
print "Unable to copy srpm to fedorapeople.org: %s" % se
exit(1)
print "scp %s %[email protected]:public_html/reviews/%s/." % (specfile, user, name)
so, se, rc = runCommand("scp %s %[email protected]:public_html/reviews/%s/." % (specfile, user, name))
if rc != 0:
print "Unable to copy spec file to fedorapeople: %s" % se
exit(1)
print ""
print ""
# generate summary and header information
print "Generating Review Request"
print "###############################################################"
print "Review Request: %s - %s" % (name, summary)
print "###############################################################"
print "Spec URL: https://%s.fedorapeople.org/reviews/%s/%s" % (user, name, os.path.basename(specfile))
print ""
print "SRPM URL: https://%s.fedorapeople.org/reviews/%s/%s" % (user, name, os.path.basename(srpm))
print ""
print "Description: %s" % description
print ""
print "Fedora Account System Username: %s" % user
print ""
if not options.skipkoji:
print "Koji: http://koji.fedoraproject.org/koji/taskinfo?taskID=%s" % task_id
print ""
print "$ rpmlint %s" % " ".join(map(lambda l: os.path.basename(l), builds))
print rpmlint
print "###############################################################"
print ""
print ""
print "Enter values at: https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora&format=fedora-review"