'Initialize the kernel build environment
job
which job this build is part of
base_tree
base kernel tree. Can be one of the following:
1. A local tarball
2. A URL to a tarball
3. A local directory (will symlink it)
4. A shorthand expandable (eg \'2.6.11-git3\')
subdir
subdir in the results directory (eg "build")
(holds config/, debug/, results/)
tmp_dir
leave
Boolean, whether to leave existing tmpdir or not'

def __init__(self, job, base_tree, subdir, tmp_dir, build_dir, leave=False):

    super(kernel, self).__init__(job)
    self.autodir = job.autodir
    self.src_dir = os.path.join(tmp_dir, 'src')
    self.build_dir = os.path.join(tmp_dir, build_dir)
    self.config_dir = os.path.join(subdir, 'config')
    self.log_dir = os.path.join(subdir, 'debug')
    self.results_dir = os.path.join(subdir, 'results')
    self.subdir = os.path.basename(subdir)
    if (not leave):
        if os.path.isdir(self.src_dir):
            utils.system(('rm    -rf    ' + self.src_dir))
        if os.path.isdir(self.build_dir):
            utils.system(('rm    -rf    ' + self.build_dir))
    if (not os.path.exists(self.src_dir)):
        os.mkdir(self.src_dir)
    for path in [self.config_dir, self.log_dir, self.results_dir]:
        if os.path.exists(path):
            utils.system(('rm    -rf    ' + path))
        os.mkdir(path)
    logpath = os.path.join(self.log_dir, 'build_log')
    self.logfile = open(logpath, 'w+')
    self.applied_patches = []
    self.target_arch = None
    self.build_target = 'bzImage'
    self.build_image = None
    arch = utils.get_current_kernel_arch()
    if (arch == 'ia64'):
        self.build_target = 'all'
        self.build_image = 'vmlinux.gz'
    elif (arch in ['s390', 's390x']):
        self.build_target = 'image'
    elif ('ppc' in arch):
        self.build_target = 'vmlinux'
    if (not leave):
        self.logfile.write(('BASE:    %s\n' % base_tree))
        shorthand = re.compile('^\\d+\\.\\d+\\.\\d+')
        if shorthand.match(base_tree):
            self.base_tree_version = base_tree
        else:
            self.base_tree_version = None
        self.extract(base_tree)
