2 This module defines the GitKernel class
4 @author: Ryan Harper (ryanh@us.ibm.com)
9 import git
, source_kernel
12 class GitKernel(git
.InstallableGitRepo
):
14 This class represents an installable git kernel repo.
16 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.
19 def __init__(self
, repodir
, giturl
, weburl
=None):
20 super(GitKernel
, self
).__init
__(repodir
, giturl
, weburl
)
28 def configure(self
, config
):
32 def patch(self
, patch
):
33 self
._patches
.append(patch
)
36 def checkout(self
, revision
, local
=None):
38 Checkout the commit id, branch, or tag.
40 @param revision: Name of the git remote branch, revision or tag
41 @param local: Name of the local branch, implies -b
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
,
51 def show_branch(self
):
53 Print the current local branch name.
55 self
._branch
= super(GitKernel
, self
).get_branch()
56 logging
.info(self
._branch
)
59 def show_branches(self
, all
=True):
61 Print the local and remote branches.
63 @param all: Whether to show all branches (True) or only local branches
66 self
._branch
= super(GitKernel
, self
).get_branch()
67 logging
.info(super(GitKernel
, self
).get_branch(all
=all
))
70 def show_revision(self
):
72 Show the current git revision.
74 self
._revision
= super(GitKernel
, self
).get_revision()
75 logging
.info(self
._revision
)
78 def install(self
, host
, build
=True, builddir
=None, revision
=None):
80 Install the git tree in a host.
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
87 @param revision: Desired commit hash. If ommited, will build from HEAD
91 self
.checkout(revision
)
92 self
._revision
= super(GitKernel
, self
).get_revision()
93 logging
.info('Checked out revision: %s', self
._revision
)
96 self
._build
= os
.path
.join(host
.get_tmp_dir(), "build")
97 logging
.warning('Builddir %s is not persistent (it will be erased '
98 'in future jobs)', self
._build
)
100 self
._build
= builddir
102 # push source to host for install
103 logging
.info('Pushing %s to host', self
.source_material
)
104 host
.send_file(self
.source_material
, self
._build
)
105 remote_source_material
= os
.path
.join(self
._build
,
106 os
.path
.basename(self
.source_material
))
108 # use a source_kernel to configure, patch, build and install.
109 sk
= source_kernel
.SourceKernel(remote_source_material
)
113 for p
in self
._patches
:
117 sk
.configure(self
._config
)