We can make git_kernel to use an implementation derived from GitRepoHelper, as it's simpler and more straight forward. This patch implements this approach.
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]> --- server/git_kernel.py | 149 +++++++++++++++++++------------------------------- 1 files changed, 57 insertions(+), 92 deletions(-) diff --git a/server/git_kernel.py b/server/git_kernel.py index 0581ca0..b544a52 100644 --- a/server/git_kernel.py +++ b/server/git_kernel.py @@ -1,120 +1,85 @@ """ -This module defines the GitKernel class - -@author: Ryan Harper ([email protected]) -@copyright: IBM 2007 +This module defines the GitKernel class. """ -import os, logging -import git, source_kernel +import logging, os +import source_kernel +from autotest_lib.client.common_lib import git -class GitKernel(git.InstallableGitRepo): +class GitKernel(git.GitRepoHelper): """ This class represents an installable git kernel repo. - It is used to pull down a local copy of a git repo, check if the local repo - is up-to-date, if not update and then build the kernel from the git repo. + It will fetch a git repo and copy its contents over to a client, so + it can be built as a normal source kernel. """ - def __init__(self, repodir, giturl, weburl=None): - super(GitKernel, self).__init__(repodir, giturl, weburl) - self._patches = [] - self._config = None - self._build = None - self._branch = None - self._revision = None - - - def configure(self, config): - self._config = config - - - def patch(self, patch): - self._patches.append(patch) - - - def checkout(self, revision, local=None): - """ - Checkout the commit id, branch, or tag. - - @param revision: Name of the git remote branch, revision or tag - @param local: Name of the local branch, implies -b - """ - logging.info('Checking out %s', revision) - super(GitKernel, self).checkout(revision) - self._revision = super(GitKernel, self).get_revision() - self._branch = super(GitKernel, self).get_branch() - logging.info('Checked out %s on branch %s', self._revision, - self._branch) - - - def show_branch(self): - """ - Print the current local branch name. - """ - self._branch = super(GitKernel, self).get_branch() - logging.info(self._branch) - - - def show_branches(self, all=True): - """ - Print the local and remote branches. - - @param all: Whether to show all branches (True) or only local branches - (False). - """ - self._branch = super(GitKernel, self).get_branch() - logging.info(super(GitKernel, self).get_branch(all=all)) - - - def show_revision(self): - """ - Show the current git revision. - """ - self._revision = super(GitKernel, self).get_revision() - logging.info(self._revision) + def __init__(self, uri, branch='master', lbranch='master', commit=None, + destination_dir=None, base_uri=None, + remote_destination_dir=None, patches=[], config=None): + ''' + Instantiates a new GitRepoHelper + + @type uri: string + @param uri: git repository url + @type branch: string + @param branch: git remote branch + @type destination_dir: string + @param destination_dir: path of a dir where to save downloaded code + @type commit: string + @param commit: specific commit to download + @type lbranch: string + @param lbranch: git local branch name, if different from remote + @type base_uri: string + @param base_uri: a closer, usually local, git repository url from where + to fetch content first from. + + @param remote_destination_dir: To where the source code will be copied + on the client + @param patches: List of patches to be applied on top of this kernel + @param config: Config to pass to the kernel + ''' + super(GitKernel, self).__init__(uri=uri, branch=branch, lbranch=lbranch, + commit=commit, + destination_dir=destination_dir, + base_uri=base_uri) + + if remote_destination_dir is None: + self.remote_destination_dir = self.destination_dir + else: + self.remote_destination_dir = remote_destination_dir + self.patches = patches + self.config = config - def install(self, host, build=True, builddir=None, revision=None): + def install(self, host, build=True, branch=None, commit=None): """ Install the git tree in a host. - @param host: Host object - @param build: Whether to build the source tree - @param builddir: Specify a build dir. If no build dir is specified, - the job temporary directory will be used, so the build won't - be persistent. - @param revision: Desired commit hash. If ommited, will build from HEAD - of the branch. + @param host: Host object. + @param build: Whether to build the source tree. + @param branch: Check out this specific branch before building. + @param commit: Check out this specific commit before building. """ - if revision: - self.checkout(revision) - self._revision = super(GitKernel, self).get_revision() - logging.info('Checked out revision: %s', self._revision) - - if not builddir: - self._build = os.path.join(host.get_tmp_dir(), "build") - logging.warning('Builddir %s is not persistent (it will be erased ' - 'in future jobs)', self._build) - else: - self._build = builddir + self.execute() + if (branch is not None) or (commit is not None): + self.checkout(branch=branch, commit=commit) # push source to host for install - logging.info('Pushing %s to host', self.source_material) - host.send_file(self.source_material, self._build) - remote_source_material= os.path.join(self._build, - os.path.basename(self.source_material)) + logging.info('Pushing %s to client', self.destination_dir) + host.send_file(self.destination_dir, + os.path.dirname(self.remote_destination_dir)) # use a source_kernel to configure, patch, build and install. - sk = source_kernel.SourceKernel(remote_source_material) + sk = source_kernel.SourceKernel(self.remote_destination_dir) if build: # apply patches - for p in self._patches: + for p in self.patches: sk.patch(p) # configure - sk.configure(self._config) + sk.configure(self.config) # build sk.build(host) -- 1.7.7.3 _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
