summaryrefslogtreecommitdiff
path: root/server/git_kernel.py
blob: f9937322f5c632dee50a3e085a8d91f6cd49bc35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
# Copyright 2007 IBM Corp. Released under the GPL v2
# Authors: Ryan Harper <ryanh@us.ibm.com>
#

"""
This module defines the GitKernel class
"""

__author__ = """
ryanh@us.ibm.com (Ryan Harper)
"""


import os
import git, source_kernel


class GitKernel(git.GitRepo):
	"""
	This class represents a 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.

	"""
	def __init__(self, repodir, giturl, weburl):
		git.GitRepo.__init__(self, repodir, giturl, weburl)
		self.__patches = []
		self.__config = None
		self.__build = None


	def configure(self, config):
		self.__config = config


	def patch(self, patch):
		self.__patches.append(patch)


	def install(self, host, build=True, builddir=None):
		# use tmpdir if no builddir specified
		# NB: pass a builddir to install() method if you
		# need to ensure the build remains after the completion
		# of a job 
		if not builddir:
			self.__build = os.path.join(host.get_tmp_dir(),"build")
			print 'warning: builddir %s is not persistent' %(self.__build)

		# push source to host for install
		print '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))

		# use a source_kernel to configure, patch, build and install.
		sk = source_kernel.SourceKernel(remote_source_material)

		if build:
			# apply patches
			for p in self.__patches:
				sk.patch(p)

			# configure
			sk.configure(self.__config)

			# build
			sk.build(host)
			
		# install
		sk.install(host)