mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2007 IBM Corp. Released under the GPL v2 |
| 3 | # Authors: Ryan Harper <ryanh@us.ibm.com> |
| 4 | # |
| 5 | |
| 6 | """ |
| 7 | This module defines the GitKernel class |
| 8 | """ |
| 9 | |
| 10 | __author__ = """ |
| 11 | ryanh@us.ibm.com (Ryan Harper) |
| 12 | """ |
| 13 | |
| 14 | |
| 15 | import os |
| 16 | import urllib2 |
| 17 | |
mbligh | 313f12c | 2008-05-15 23:33:50 +0000 | [diff] [blame^] | 18 | import git, source_kernel |
mbligh | 3e0eaf1 | 2007-12-04 22:45:03 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | class GitKernel(git.GitRepo): |
| 22 | """ |
| 23 | This class represents a git kernel repo. |
| 24 | |
| 25 | It is used to pull down a local copy of a git repo, check if the local repo |
| 26 | is up-to-date, if not update and then build the kernel from the git repo. |
| 27 | |
| 28 | """ |
| 29 | def __init__(self, repodir, giturl, weburl): |
| 30 | git.GitRepo.__init__(self, repodir, giturl, weburl) |
| 31 | self.__patches = [] |
| 32 | self.__config = None |
| 33 | self.__build = None |
| 34 | |
| 35 | |
| 36 | def configure(self, config): |
| 37 | self.__config = config |
| 38 | |
| 39 | |
| 40 | def patch(self, patch): |
| 41 | self.__patches.append(patch) |
| 42 | |
| 43 | |
| 44 | def install(self, host, build=True, builddir=None): |
| 45 | # use tmpdir if no builddir specified |
| 46 | # NB: pass a builddir to install() method if you |
| 47 | # need to ensure the build remains after the completion |
| 48 | # of a job |
| 49 | if not builddir: |
| 50 | self.__build = os.path.join(host.get_tmp_dir(),"build") |
| 51 | print 'warning: builddir %s is not persistent' %(self.__build) |
| 52 | |
| 53 | # push source to host for install |
| 54 | print 'pushing %s to host' %(self.source_material) |
| 55 | host.send_file(self.source_material, self.__build) |
| 56 | remote_source_material= os.path.join(self.__build, |
| 57 | os.path.basename(self.source_material)) |
| 58 | |
| 59 | # use a source_kernel to configure, patch, build and install. |
| 60 | sk = source_kernel.SourceKernel(remote_source_material) |
| 61 | |
| 62 | if build: |
| 63 | # apply patches |
| 64 | for p in self.__patches: |
| 65 | sk.patch(p) |
| 66 | |
| 67 | # configure |
| 68 | sk.configure(self.__config) |
| 69 | |
| 70 | # build |
| 71 | sk.build(host) |
| 72 | |
| 73 | # install |
| 74 | sk.install(host) |