[cvs] / gkb / gkb.py  

cvs: gkb/gkb.py


1 : tmcnulty 1.1 #!/usr/bin/python
2 :     #
3 :     # GKB - GNU Kernel Builder
4 : tmcnulty 1.2 # Copyright (C) 2003-2004 Tobias McNulty, Mark Guertin
5 : tmcnulty 1.1 #
6 :     # This program is free software; you can redistribute it and/or modify
7 :     # it under the terms of the GNU General Public License as published by
8 :     # the Free Software Foundation; either version 2 of the License, or
9 :     # (at your option) any later version.
10 :     #
11 :     # This program is distributed in the hope that it will be useful,
12 :     # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 :     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 :     # GNU General Public License for more details.
15 :     #
16 :     # You should have received a copy of the GNU General Public License
17 :     # along with this program; if not, write to the Free Software
18 :     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 :     #
20 :     # Ported from PHP version Copyright (c) Tobias McNulty 2000-2003
21 :    
22 : tmcnulty 1.20 import sys, os, ConfigParser, popen2
23 : tmcnulty 1.1 import xml.parsers.expat
24 : tmcnulty 1.21 import md5, string
25 : tmcnulty 1.1 from ftplib import FTP
26 :     from commands import getoutput
27 :     from shutil import copy, move
28 :     from string import split
29 :     from urllib2 import urlopen
30 :     from ClientForm import ParseResponse
31 :    
32 : tmcnulty 1.29
33 : tmcnulty 1.1 debug=0
34 : tmcnulty 1.22 clean=1
35 :     dont_build=0
36 : tmcnulty 1.1 verbose=1
37 :    
38 :     # parse host-specific configuration information from gkb.cfg
39 :     config = ConfigParser.ConfigParser()
40 :     config.readfp(open('gkb-host.cfg'))
41 :     buildroot=config.get("options","buildroot")
42 :     host=config.get("options","host")
43 :     passwd=config.get("options","passwd")
44 :    
45 :     # this one is passed verbatim before the make command. might be useful for alternate toolchains, etc
46 :     # example: premake="HOST=powerpc-unknown-linux-gnu"
47 :     premake=config.get("options","premake")
48 :     # make options, passed verbatim after make command
49 :     makeopts=config.get("options","makeopts")
50 :    
51 :     # parse manager-related configuration from gkb-manager.cfg
52 :     config.readfp(open('gkb-manager.cfg'))
53 :     msite=config.get('options','msite')
54 :    
55 :     # these values will likely stay fairly static across different builds
56 :     patchdir="%s/patches" % buildroot # full path to patch file dir
57 :     configdir="%s/configs" % buildroot # path to where configs are to be stored
58 :     logdir="%s/logs" % buildroot # the logs will go here
59 :     bindir="%s/bin" % buildroot # the directory that binaries built will be sent for pkging
60 :     workdir="%s/work" % buildroot # work directory, where builds take place
61 :    
62 :     # setup the global dicts to hold build data, imported from xml
63 :     mastertrees={}
64 :     builds={}
65 :    
66 : tmcnulty 1.7 class Error(Exception):
67 :     """Base class for exceptions in this module."""
68 :     pass
69 :    
70 :     class BuildError(Error):
71 :     """Exception raised for build-level errors.
72 :    
73 :     Attributes:
74 :     message -- explanation of the error
75 :     """
76 :    
77 :     def __init__(self, message):
78 :     self.message = message
79 :    
80 :     class FatalError(Error):
81 :     """Exception for fatal errors that prevent program continuation.
82 :    
83 :     Attributes:
84 :     message -- explanation of why the specific transition is not allowed
85 :     """
86 :    
87 : tmcnulty 1.12 def __init__(self, message):
88 : tmcnulty 1.7 self.message = message
89 :    
90 : tmcnulty 1.1 def printverbose(myoutput):
91 :     """Supporting method to output info to stdout if verbosity level is set"""
92 :     if verbose==1:
93 :     print myoutput
94 :    
95 : tmcnulty 1.28 def cleantext(text):
96 : tmcnulty 1.21 """clean a string of passwords, etc. to make it suitable for logging"""
97 :     result = string.replace(text,passwd,"XXXXXXXX")
98 :     return result
99 :    
100 : tmcnulty 1.16 def linkpipes(input, output):
101 : tmcnulty 1.21 """link two pipes together, writing all the data from input to output"""
102 : tmcnulty 1.16 data = input.read(2048)
103 :     while data:
104 :     output.write(data)
105 : tmcnulty 1.18 data = input.read(2048)
106 :    
107 : tmcnulty 1.22 def runcmd(cmd, kinfo=None, outfile=None, append=False, infile=None):
108 : tmcnulty 1.21 """run the specified command, with the optional input and output documents"""
109 : tmcnulty 1.28 log(" \_ running " + cleantext(cmd), kinfo)
110 : tmcnulty 1.16
111 : tmcnulty 1.20 p4obj = popen2.Popen4(cmd)
112 : tmcnulty 1.19
113 :     pin = p4obj.tochild
114 :     pouterr = p4obj.fromchild
115 : tmcnulty 1.16
116 :     if infile != None:
117 :     inobj = open(infile, "r")
118 :     linkpipes(inobj, pin)
119 :     inobj.close()
120 :    
121 :     if outfile != None:
122 :     if append:
123 :     mode = "a"
124 :     else:
125 :     mode = "w"
126 :    
127 :     outobj = open(outfile, mode)
128 : tmcnulty 1.18 linkpipes(pouterr,outobj)
129 : tmcnulty 1.16 outobj.close()
130 :    
131 : tmcnulty 1.19 err = p4obj.wait()
132 : tmcnulty 1.16
133 :     if err == None:
134 :     err = 0
135 : tmcnulty 1.17
136 : tmcnulty 1.25 log(" \_ exit code: %i" % err, kinfo)
137 : tmcnulty 1.21
138 : tmcnulty 1.14 return err
139 :    
140 : tmcnulty 1.1 def log(text,kinfo=0):
141 :     if kinfo:
142 :     printverbose(kinfo["name"] + " : " + text)
143 :     else:
144 :     printverbose("gkb : " + text)
145 :    
146 :     def verifydir(mydir,kinfo=0):
147 :     """Supporting method to verify a given exists, if not it will create it"""
148 :     log("verifying directory " + mydir,kinfo)
149 :     if not os.path.isdir(mydir):
150 : tmcnulty 1.25 log(" \_ %s doesn't exist, creating" % mydir,kinfo)
151 : tmcnulty 1.1 os.mkdir(mydir)
152 :     return mydir
153 :    
154 :     def chdir(mydir,kinfo):
155 :     verifydir(mydir,kinfo)
156 :     log("entering "+mydir,kinfo)
157 :     os.chdir(mydir)
158 :    
159 :     def verifyfile(myfile,kinfo):
160 :     """Supporting method to verify file exists, if not it will exit with error"""
161 :     if not os.path.isfile(myfile):
162 : tmcnulty 1.7 raise BuildError("cannot find file expected at %s, exiting" % myfile)
163 : tmcnulty 1.1 return myfile
164 :    
165 :     def md5sum(fileobj):
166 :     """calculates the md5sum for fileobj and returns it in hexadecimal"""
167 :     md = md5.new()
168 :     data = fileobj.read(8192)
169 :     while (data):
170 :     md.update(data)
171 :     data = fileobj.read(8192)
172 :    
173 :     digest = md.hexdigest()
174 :     return digest
175 :    
176 : tmcnulty 1.31 def krn_querymgr(command,kinfo,extra=""):
177 : tmcnulty 1.1 """queries the build host manager with a variety of commands, such as checkout, checkin, etc."""
178 :     version=krn_localversion(kinfo)
179 :     log("querying distribution site manager with command '%s' (kernel version=%s)" % (command,version),kinfo)
180 : tmcnulty 1.31 result=getoutput("wget --quiet --output-document=- \"%s/manager.php?cmd=%s&host=%s&pass=%s&build=%s&version=%s%s\"" % (msite,command,host,passwd,kinfo["name"],version,extra))
181 : tmcnulty 1.25 log(" \_ result: '"+result+"'",kinfo)
182 : tmcnulty 1.1 return result=="1"
183 :    
184 : tmcnulty 1.31 def krn_modulesenabled(kinfo):
185 :     """Checks the source to see if modules are enabled"""
186 :     output=getoutput("""awk -F '=' '/^CONFIG_MODULES/{v=$2} END { printf("%s\\n", v) }' """ + kinfo["workdir"] + """.config | sed "s/ //g" """)
187 :     if (output=='y'):
188 :     result=True
189 :     else:
190 :     result=False
191 :     return result
192 :    
193 : tmcnulty 1.1 def krn_localversion(kinfo):
194 :     """Checks the version of the local source tree specified in kinfo"""
195 :     version=getoutput("""awk -F '=' '/^VERSION/{v=$2} /^PATCHLEVEL/{p=$2} /^SUBLEVEL/{s=$2} /^EXTRAVERSION/{e=$2} END { printf("%s.%s.%s%s\\n", v, p, s, e) }' """ + kinfo["workdir"] + """/Makefile | sed "s/ //g" """)
196 :     return version
197 :    
198 :     def gkb_build(root,kinfo):
199 :     """performs actual kernel builds given root, kinfo (tuple containing relevant data) , premake and makeopts"""
200 :    
201 :     # make sure needed directoriess (for this build) exist, if not create them
202 :    
203 :     verifydir("%s/%s" % (logdir, kinfo["name"]),kinfo)
204 :     verifydir("%s/%s" % (patchdir, kinfo["name"]),kinfo)
205 :    
206 :     # sync the source to make sure we are up to date ...
207 : tmcnulty 1.25 log("fetching latest source",kinfo)
208 : tmcnulty 1.1 gkb_getsource(kinfo)
209 :    
210 : tmcnulty 1.10 # go into the work directory
211 : tmcnulty 1.27 #chdir(workdir, kinfo)
212 : tmcnulty 1.10
213 :     # archive the clean source for later uploading
214 : tmcnulty 1.27 #log("archiving source to " + kinfo["mastertree"] + ".tar.bz2", kinfo)
215 :     #runcmd("tar cjf " + kinfo["mastertree"] + ".tar.bz2 " + kinfo["mastertree"], kinfo)
216 : tmcnulty 1.10
217 :     # now we'll go into the tree's work dir
218 : tmcnulty 1.1 chdir(kinfo["workdir"],kinfo)
219 :    
220 :     # check for patches and apply if necessary
221 :     gkb_patch(kinfo)
222 :    
223 :     if kinfo["type"] == "kernel24":
224 :     krn_build24(kinfo)
225 :     elif kinfo["type"] == "kernel26":
226 :     krn_build24(kinfo) #run kernel24 for now, change later
227 :    
228 :     # Gerk comment:
229 :     # Do we need to change this with 24/26? we probably don't ... I'd rather see us define the list of make targets
230 :     # i.e. "dep","clean","vmlinux","modules","modules_install" or "clean","all","modules_install" for 2.6
231 :     # also of note, make all is not what we will always want with 2.6 kernels ... i.e. zImage.prep, zImage.chrp, etc
232 :     # also for backward compat they will continue to support calling things individual .. the makefile just does
233 :     # this for us with 'all'
234 :    
235 :    
236 :     def krn_build24(kinfo):
237 :     """build a kernel, version 2.4.x"""
238 :    
239 :     if krn_querymgr("checkout",kinfo):
240 : tmcnulty 1.7 try:
241 :     myversion=krn_localversion(kinfo)
242 :    
243 :     # fetch and cp the config file to work/.config
244 :     krn_config(kinfo)
245 :    
246 :     # **Note** : we set the preprocessing command to premake inline instead
247 :     # of globally as it is only needed in this target
248 :     if dont_build==0:
249 :     gkb_runmake("oldconfig",kinfo,premake+" /bin/cat %s/newlines | " % buildroot,makeopts)
250 :    
251 :     # give option to only repackage for testing purposes, comment out clean=1 at top of this file to use this feature
252 :     if (clean==1 and dont_build==0):
253 :     gkb_runmake("clean", kinfo, premake, makeopts)
254 :    
255 :     if dont_build==0:
256 :     gkb_runmake("dep", kinfo, premake, makeopts)
257 :     gkb_runmake(kinfo["binname"], kinfo, premake, makeopts)
258 :    
259 :     # We should check to see if binary built ok, if not bail out
260 :     mybindir=bindir+"/linux-"+kinfo["name"]+"-"+myversion
261 :     verifydir(mybindir,kinfo)
262 :     verifydir(mybindir+"/boot",kinfo)
263 :    
264 :     kbinloc=kinfo["workdir"]+"/"+kinfo["binpath"]+"/"+kinfo["binname"]
265 :     if verifyfile(kbinloc,kinfo):
266 :     # the binary exists, so let's cp it to bin...
267 :     copy(kbinloc,mybindir+"/boot/"+kinfo["binname"]+"-"+myversion)
268 :     else:
269 :     # the binary is not there, inform user and bail out with error
270 :     raise BuildError("%s is not present, assuming build failure and exiting. See log for details." % kbinloc)
271 : tmcnulty 1.31
272 :     if krn_modulesenabled(kinfo):
273 :     # now that we know he binary built, let's continue
274 :     if dont_build==0:
275 :     gkb_runmake("modules",kinfo, premake, makeopts)
276 :    
277 :     # **Note** : we prepend the INSTALL_MOD_PATH to the makeopts inline instead
278 :     # of globally as it is only needed in this target
279 :     gkb_runmake("modules_install", kinfo, premake, "INSTALL_MOD_PATH=%s %s" % (mybindir, makeopts))
280 :     else:
281 :     log("skipping make modules (disabled in .config)",kinfo)
282 :    
283 : tmcnulty 1.10 # compress and upload source archive
284 :     chdir(kinfo["workdir"]+"/..",kinfo)
285 :     archive_name = "src-%s.tar.bz2" % kinfo["mastertree"],
286 :    
287 :     # compress and upload kernel binary
288 : tmcnulty 1.7 chdir(bindir,kinfo)
289 :     archive_name = "linux-%s-%s.tar.bz2" % (kinfo["name"], myversion)
290 :    
291 :     log("compressing binary archive "+archive_name,kinfo)
292 :    
293 : tmcnulty 1.21 if runcmd("tar cjf "+archive_name+" "+os.path.basename(mybindir), kinfo):
294 : tmcnulty 1.7 raise BuildError("failed to `tar cjf %s`" % archive_name)
295 :    
296 : tmcnulty 1.21 runcmd("rm -rf %s" % mybindir, kinfo)
297 : tmcnulty 1.7
298 : tmcnulty 1.10 krn_upload(archive_name,"kernel",myversion,kinfo)
299 :     krn_querymgr("checkin",kinfo)
300 :    
301 : tmcnulty 1.28 if os.fork() == 0:
302 : tmcnulty 1.10 #in child
303 : tmcnulty 1.28 try:
304 :     # sync the source to make sure we are up to date ...
305 :     log("re-fetching latest source",kinfo)
306 :     gkb_getsource(kinfo)
307 :    
308 :     # go into the work directory
309 :     chdir(workdir, kinfo)
310 :    
311 :     # archive the clean source for later uploading
312 :     log("archiving source to " + kinfo["mastertree"] + ".tar.bz2", kinfo)
313 :     runcmd("tar cjf " + kinfo["mastertree"] + ".tar.bz2 " + kinfo["mastertree"], kinfo)
314 :    
315 :     krn_upload(workdir + "/" + kinfo["mastertree"] + ".tar.bz2", "source", myversion, kinfo)
316 :     finally:
317 :     sys.exit(0)
318 : tmcnulty 1.10
319 : tmcnulty 1.7 except BuildError, e:
320 :     log(e.message, kinfo)
321 : tmcnulty 1.31 krn_querymgr("checkin",kinfo,"&failed=%s" % krn_localversion(kinfo))
322 : tmcnulty 1.8 except:
323 : tmcnulty 1.31 krn_querymgr("checkin",kinfo,"&failed=%s" % krn_localversion(kinfo))
324 : tmcnulty 1.8 raise
325 :    
326 : tmcnulty 1.1 def krn_build26(kinfo):
327 :     """build a kernel, version 2.6"""
328 :    
329 :     # source get routines
330 :     def gkb_getsource(kinfo):
331 :     """method to perform source sync on demand, currenty only supports rsync, but others can be added"""
332 :    
333 :     method=mastertrees[kinfo["mastertree"]]["method"]
334 :    
335 :     if method == "rsync":
336 :     get_rsync(kinfo)
337 :     elif method == "wget":
338 :     get_wget(kinfo)
339 :     elif method == "vanilla":
340 :     get_vanilla(kinfo)
341 :    
342 :     def get_rsync(kinfo):
343 :     """sync the source using rsync"""
344 :     args=mastertrees[kinfo["mastertree"]]["args"]
345 :    
346 :     if clean==1:
347 :     syncoptions="rsync -azv --delete"
348 :     else:
349 :     syncoptions="rsync -azv"
350 :    
351 :     syncline=args+" "+kinfo["workdir"]
352 :    
353 : tmcnulty 1.23 #logging now in runcmd
354 :     #log("running rsync : %s %s" % (syncoptions, syncline),kinfo)
355 : tmcnulty 1.21 if runcmd("%s %s" % (syncoptions, syncline), kinfo, "%s/%s/rsync.log" % (logdir, kinfo["name"])):
356 : tmcnulty 1.7 raise BuildError("sync failed, tried %s. See log for details." % syncline)
357 : tmcnulty 1.1
358 :     def get_wget(kinfo):
359 :     #needs work
360 :     """sync the source using wget and a tar.bz2"""
361 :     args=mastertrees[kinfo["mastertree"]]["args"]
362 :    
363 :     log("fetching source archive " % args,kinfo)
364 :     mysourcefile="%s/%s.tar.bz2" % (kinfo["workdir"],kinfo["name"])
365 :    
366 : tmcnulty 1.21 if runcmd("wget --quiet --output-document=%s %s/configs/%s" % (myconfigfile,msite,kinfo["name"]), kinfo):
367 : tmcnulty 1.7 raise BuildError("unable to download configfile, aborting.")
368 : tmcnulty 1.1
369 :     log("decompressing source file",kinfo)
370 : tmcnulty 1.21 if runcmd("tar xjf " % (myconfigfile,msite,kinfo["name"]), kinfo):
371 : tmcnulty 1.7 raise BuildError("unable to decompress source file, aborting.")
372 : tmcnulty 1.1
373 :     def get_vanilla(kinfo):
374 :     args=mastertrees[kinfo["mastertree"]]["args"]
375 :    
376 :     log("fetching source archive %s" % args)
377 :     mysourcefile="%s/%s.tar.bz2" % (workdir,kinfo["name"])
378 :    
379 : tmcnulty 1.21 if runcmd("wget -c --output-document=%s %s" % (mysourcefile,args), kinfo):
380 : tmcnulty 1.7 raise BuildError("unable to download source file %s, aborting." % args)
381 : tmcnulty 1.1
382 :     log("decompressing source file %s" % mysourcefile,kinfo)
383 :    
384 :     #save the current working ectory
385 :     cwd=getoutput("pwd")
386 :    
387 :     chdir(workdir,kinfo)
388 :     pfd=os.popen("tar vxjf %s" % mysourcefile,"r")
389 :     trash=data=pfd.read(255)
390 :    
391 :     while trash:
392 :     trash=pfd.read(4096)
393 :    
394 :     if pfd.close():
395 : tmcnulty 1.7 raise BuildError("unable to decompress source file, aborting.")
396 : tmcnulty 1.1
397 :     fnames=split(data)
398 :     name=fnames[0]
399 :    
400 : tmcnulty 1.21 runcmd("rm -rf %s" % kinfo["workdir"], kinfo)
401 : tmcnulty 1.1 move(work + "/" + dirname, kinfo["workdir"])
402 :    
403 :     #restore the previous working ectory
404 :     chdir(cwd,kinfo)
405 :    
406 :     def gkb_patch(kinfo):
407 :     """method that applies patch found in kinfo config files for running kernel build"""
408 :     if kinfo["patches"]:
409 :     patches=split(kinfo["patches"],";")
410 :    
411 :     for patch in patches:
412 :     log("downloading patch %s" % patch,kinfo)
413 :    
414 :     #set a name for this patch file
415 :     mypatchfile="%s/%s/%s.patch" % (patchdir,kinfo["name"],patch)
416 :    
417 :     # download pathfile or bail
418 : tmcnulty 1.21 if runcmd("wget --quiet --output-document=%s %s/patches/%s/%s" % (mypatchfile,msite,kinfo["name"],patch), kinfo):
419 : tmcnulty 1.7 raise BuildError("unable to download patchfile %s, aborting." % patch)
420 : tmcnulty 1.1
421 :     # we have a patch file, apply it or bail
422 :     log("perfoming patch with %s" % patch,kinfo)
423 : tmcnulty 1.16
424 :     # former patchcommand was:
425 :     #patchcommand="patch -p1 < %s > %s/%s/patch-%s.log 2>&1" % (mypatchfile,logdir,kinfo["name"],patch)
426 :     #log("using %s from %s" % (patchcommand,kinfo["workdir"]),kinfo)
427 :    
428 : tmcnulty 1.1 chdir(kinfo["workdir"],kinfo)
429 : tmcnulty 1.21 if runcmd("patch -p1", kinfo, "%s/%s/patch-%s.log" % (logdir,kinfo["name"],patch), False, mypatchfile):
430 : tmcnulty 1.7 raise BuildError("patchfile %s failed, aborting. See patch log for details." % patch)
431 : tmcnulty 1.1 else:
432 :     log("no patchfiles, continuing",kinfo)
433 :    
434 :     def krn_config(kinfo):
435 :     """method to fetch and place config file for running kernel build"""
436 :    
437 :     if kinfo["config"]==1:
438 :     log("fetching config file",kinfo)
439 :     myconfigfile="%s/%s.config" % (configdir,kinfo["name"])
440 :    
441 : tmcnulty 1.21 if runcmd("wget --quiet --output-document=%s %s/configs/%s" % (myconfigfile,msite,kinfo["name"]), kinfo):
442 : tmcnulty 1.7 raise BuildError("unable to download configfile, aborting.")
443 : tmcnulty 1.1
444 :     log("copying config file to %s/.config" % kinfo["workdir"],kinfo)
445 :     copy(verifyfile(myconfigfile,kinfo),"%s/.config" % kinfo["workdir"])
446 :    
447 :     # Methods to support build()
448 :     def gkb_runmake(command, kinfo, premake, makeopts):
449 :     """Supporting method for build() ... a stub to run a make target and auto log it, given make target (command) and name (kernel name)"""
450 :     log("running make %s" % command,kinfo)
451 : tmcnulty 1.31
452 :     # check to see if we need to run a simple make
453 :     # for some reason 2.2 kernels can't handle premake, makeopts, etc.
454 :     localversion = krn_localversion(kinfo)
455 :    
456 :     if (string.find(localversion,"2.2") == 0):
457 :     if runcmd("%s make %s" % (premake,command), kinfo, "%s/%s/make-%s.log" % (logdir, kinfo["name"], command)):
458 :     raise BuildError("unable to run make %s, aborting." % command)
459 :     else:
460 :     if runcmd("%s make %s %s" % (premake, makeopts, command), kinfo, "%s/%s/make-%s.log" % (logdir, kinfo["name"], command)):
461 :     raise BuildError("unable to run make %s, aborting." % command)
462 : tmcnulty 1.1
463 :     def gkb_parsexml(name):
464 :     """parse the xml build file into mastertrees and builds"""
465 :     def start_element(name, attrs):
466 :     #print "In start_element: %s %s" % (name, attrs)
467 :     if name=="mastertree":
468 :     mastertrees[attrs["name"]]=attrs
469 :     elif name=="build":
470 :     builds[attrs["name"]]=attrs
471 :    
472 :     p = xml.parsers.expat.ParserCreate()
473 :     p.StartElementHandler = start_element
474 :     p.ParseFile(open(name))
475 : tmcnulty 1.3
476 : tmcnulty 1.10 def krn_upload(file, type, version, kinfo):
477 : tmcnulty 1.3 """upload the indicated file to the distribution site (kernel archives)"""
478 : tmcnulty 1.10
479 :     if type=="kernel":
480 :     log("uploading kernel version "+version+" to "+msite,kinfo)
481 :     elif type=="source":
482 :     log("uploading source "+kinfo["mastertree"]+" to "+msite,kinfo)
483 :     else:
484 :     raise BuildException, "invalid file upload type: " + type
485 :    
486 :     forms = ParseResponse(urlopen(msite+"/upload.html"))
487 : tmcnulty 1.3 form = forms[0]
488 :    
489 :     form["host"] = host
490 :     form["pass"] = passwd
491 : tmcnulty 1.10 form["type"] = type
492 :     form["tree"] = kinfo["mastertree"]
493 : tmcnulty 1.3 form["build"] = kinfo["name"]
494 :     form["version"] = version
495 :    
496 : tmcnulty 1.5 form.add_file(open(file), "application/x-bzip2", os.path.basename(file))
497 : tmcnulty 1.10
498 : tmcnulty 1.3 # form.click() returns a urllib2.Request object
499 :     # (see HTMLForm.click.__doc__ if you don't have urllib2)
500 : tmcnulty 1.10 response = urlopen(form.click("cmd"))
501 : tmcnulty 1.3
502 : tmcnulty 1.10 if debug:
503 :     print response.geturl()
504 :     print response.info() # headers
505 :     print response.read() # body
506 :    
507 : tmcnulty 1.30 log(" \_ response: " + response.read(),kinfo)
508 : tmcnulty 1.3
509 : tmcnulty 1.10 response.close()
510 :    
511 : tmcnulty 1.1 def main():
512 :     """ main program gets executed here """
513 :    
514 :     # get our working ectory
515 :     root=getoutput("pwd")
516 :    
517 :     today=getoutput("date +%D")
518 :     buildtime=getoutput("date +'%R:%S %Z'")
519 :    
520 : tmcnulty 1.25 print "GNU Kernel Builder started %s %s" % (today,buildtime)
521 : tmcnulty 1.1
522 :     # verify the existence important directories, and create if necessary
523 :     verifydir(logdir)
524 :     verifydir(configdir)
525 :     verifydir(patchdir)
526 :     verifydir(bindir)
527 :     verifydir("%s/work" % buildroot) # build dir, make sure it exists
528 :    
529 :     # download the build jobs from the master site
530 : tmcnulty 1.25 log("fetching build jobs from master site")
531 : tmcnulty 1.22 if runcmd("wget --quiet --output-document=gkb.xml \"%s/manager.php?cmd=getjobs&host=%s&pass=%s\"" % (msite,host,passwd)):
532 : tmcnulty 1.25 raise FatalError, "Unable to download build jobs from master site %s, aborting." % msite
533 : tmcnulty 1.1
534 :     # sets up 'mastertrees' and 'builds' dicts
535 :     gkb_parsexml('gkb.xml')
536 :    
537 :     for bdict in builds.values():
538 :     myworkdir="%s/%s" % (workdir,bdict["mastertree"])
539 :     bdict["workdir"]=myworkdir
540 :    
541 : tmcnulty 1.9 try:
542 :     # for now just call the build
543 :     gkb_build(root, bdict)
544 :     except BuildError, e:
545 :     log(e.message, bdict)
546 : tmcnulty 1.12 except KeyboardInterrupt, e:
547 :     log("Caught keyboard interrupt, exiting...")
548 :     break
549 : tmcnulty 1.13
550 : tmcnulty 1.1 endtime=getoutput("date +'%R:%S %Z'")
551 :    
552 :     print "GKB finished %s %s" % (today,endtime)
553 :    
554 :     # and finally, call the mainloop to execute
555 :     main()

Tobias McNulty

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help