OLD | NEW |
| 1 # |
| 2 # Copyright 2007 IBM Corp. Released under the GPL v2 |
| 3 # Authors: Ryan Harper <ryanh@us.ibm.com> |
| 4 # |
| 5 |
1 """ | 6 """ |
2 This module defines the GitKernel class | 7 This module defines the GitKernel class |
3 | |
4 @author: Ryan Harper (ryanh@us.ibm.com) | |
5 @copyright: IBM 2007 | |
6 """ | 8 """ |
7 | 9 |
8 import os, logging | 10 __author__ = """ |
| 11 ryanh@us.ibm.com (Ryan Harper) |
| 12 """ |
| 13 |
| 14 |
| 15 import os |
9 import git, source_kernel | 16 import git, source_kernel |
10 | 17 |
11 | 18 |
12 class GitKernel(git.InstallableGitRepo): | 19 class GitKernel(git.GitRepo): |
13 """ | 20 """ |
14 This class represents an installable git kernel repo. | 21 This class represents a git kernel repo. |
15 | 22 |
16 It is used to pull down a local copy of a git repo, check if the local repo | 23 It is used to pull down a local copy of a git repo, check if the local repo |
17 is up-to-date, if not update and then build the kernel from the git repo. | 24 is up-to-date, if not update and then build the kernel from the git repo. |
| 25 |
18 """ | 26 """ |
19 def __init__(self, repodir, giturl, weburl): | 27 def __init__(self, repodir, giturl, weburl): |
20 super(GitKernel, self).__init__(repodir, giturl, weburl) | 28 git.GitRepo.__init__(self, repodir, giturl, weburl) |
21 self._patches = [] | 29 self.__patches = [] |
22 self._config = None | 30 self.__config = None |
23 self._build = None | 31 self.__build = None |
24 self._branch = None | |
25 self._revision = None | |
26 | 32 |
27 | 33 |
28 def configure(self, config): | 34 def configure(self, config): |
29 self._config = config | 35 self.__config = config |
30 | 36 |
31 | 37 |
32 def patch(self, patch): | 38 def patch(self, patch): |
33 self._patches.append(patch) | 39 self.__patches.append(patch) |
34 | 40 |
35 | 41 |
36 def checkout(self, revision, local=None): | 42 def install(self, host, build=True, builddir=None): |
37 """ | 43 # use tmpdir if no builddir specified |
38 Checkout the commit id, branch, or tag. | 44 # NB: pass a builddir to install() method if you |
39 | 45 # need to ensure the build remains after the completion |
40 @param revision: Name of the git remote branch, revision or tag | 46 # of a job |
41 @param local: Name of the local branch, implies -b | |
42 """ | |
43 logging.info('Checking out %s', revision) | |
44 super(GitKernel, self).checkout(revision) | |
45 self._revision = super(GitKernel, self).get_revision() | |
46 self._branch = super(GitKernel, self).get_branch() | |
47 logging.info('Checked out %s on branch %s', self._revision, | |
48 self._branch) | |
49 | |
50 | |
51 def show_branch(self): | |
52 """ | |
53 Print the current local branch name. | |
54 """ | |
55 self._branch = super(GitKernel, self).get_branch() | |
56 logging.info(self._branch) | |
57 | |
58 | |
59 def show_branches(self, all=True): | |
60 """ | |
61 Print the local and remote branches. | |
62 | |
63 @param all: Whether to show all branches (True) or only local branches | |
64 (False). | |
65 """ | |
66 self._branch = super(GitKernel, self).get_branch() | |
67 logging.info(super(GitKernel, self).get_branch(all=all)) | |
68 | |
69 | |
70 def show_revision(self): | |
71 """ | |
72 Show the current git revision. | |
73 """ | |
74 self._revision = super(GitKernel, self).get_revision() | |
75 logging.info(self._revision) | |
76 | |
77 | |
78 def install(self, host, build=True, builddir=None, revision=None): | |
79 """ | |
80 Install the git tree in a host. | |
81 | |
82 @param host: Host object | |
83 @param build: Whether to build the source tree | |
84 @param builddir: Specify a build dir. If no build dir is specified, | |
85 the job temporary directory will be used, so the build won't | |
86 be persistent. | |
87 @param revision: Desired commit hash. If ommited, will build from HEAD | |
88 of the branch. | |
89 """ | |
90 if revision: | |
91 self.checkout(revision) | |
92 self._revision = super(GitKernel, self).get_revision() | |
93 logging.info('Checked out revision: %s', self._revision) | |
94 | |
95 if not builddir: | 47 if not builddir: |
96 self._build = os.path.join(host.get_tmp_dir(), "build") | 48 self.__build = os.path.join(host.get_tmp_dir(),"build") |
97 logging.warning('Builddir %s is not persistent (it will be erased ' | 49 print 'warning: builddir %s is not persistent' %(self.__build) |
98 'in future jobs)', self._build) | |
99 | 50 |
100 # push source to host for install | 51 # push source to host for install |
101 logging.info('Pushing %s to host', self.source_material) | 52 print 'pushing %s to host' %(self.source_material) |
102 host.send_file(self.source_material, self._build) | 53 host.send_file(self.source_material, self.__build) |
| 54 remote_source_material= os.path.join(self.__build, |
| 55 os.path.basename(self.source_material)) |
103 | 56 |
104 # use a source_kernel to configure, patch, build and install. | 57 # use a source_kernel to configure, patch, build and install. |
105 sk = source_kernel.SourceKernel(self._build) | 58 sk = source_kernel.SourceKernel(remote_source_material) |
106 | 59 |
107 if build: | 60 if build: |
108 # apply patches | 61 # apply patches |
109 for p in self._patches: | 62 for p in self.__patches: |
110 sk.patch(p) | 63 sk.patch(p) |
111 | 64 |
112 # configure | 65 # configure |
113 sk.configure(self._config) | 66 sk.configure(self.__config) |
114 | 67 |
115 # build | 68 # build |
116 sk.build(host) | 69 sk.build(host) |
117 | 70 |
118 # install | 71 # install |
119 sk.install(host) | 72 sk.install(host) |
OLD | NEW |