# Fedora Developer Shell # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Authors: Yaakov M. Nemoy # from __future__ import with_statement from shutil import copyfileobj from os.path import join, abspath, isfile from os import listdir, getcwd, walk from subprocess import Popen from base.base import log from base.module import Module from base.util import pwd, copy, symlink, move from base.exceptions import ExecutionException from base.vars import FEDORA_DIR from base.profiles import dir_defines, join_defines, dist_defines, Profile from modules.package import Package class Build(Module): def __init__(self, name=None, target_dir=None): log.debug('name is %s' % name) self.name = name self.pkg = Package(name) self.target_dir = target_dir def setup_source(self, target_dir=None): if not target_dir: if self.target_dir: target_dir = self.target_dir else: raise ExecutionException(None, 'no Target Dir specified') log.debug('target dir is %s' % target_dir) with pwd(self.pkg.code_dir): symlink(self.name + '.spec', join(self.target_dir, 'SPECS', self.name + '.spec')) sball = self.pkg.pkg_cfg['sourceball'] symlink(sball, join(self.target_dir, 'SOURCES', sball)) patches = [f for f in listdir(getcwd()) if f.endswith('.patch')] for p in patches: symlink(patch, join(self.target_dir, 'SOURCES', p)) def build_quick_rpm(self, target_dir=None): self.rpmbuild('-ba', target_dir) def build_source_rpm(self, target_dir=None): self.rpmbuild('-bs', target_dir) def rpmbuild(self, param, target_dir=None, profile=None): if not target_dir: if self.target_dir: target_dir = self.target_dir else: raise ExecutionException(None, 'no Target Dir specified') if profile: defines = join_defines(profile.dist_defines, dir_defines(target_dir)) else: defines = dir_defines(target_dir) with pwd(self.pkg.code_dir): with file('rpmbuild.log', 'w') as rpm_out: with pwd(join(target_dir, 'SPECS')): p = Popen(['rpmbuild', defines, param, self.name + '.spec'], stdout=rpm_out, stderr=rpm_out) log.info('building %s... please wait' % \ self.pkg.spec_file()) p.wait() def fetch_rpms(self, target_dir=None): if not target_dir: if self.target_dir: target_dir = self.target_dir else: raise ExecutionException(None, 'no Target Dir specified') with pwd(target_dir): for path, dirs, files in walk('.'): for f in files: if f.endswith('.rpm'): move(join(path, f), join(FEDORA_DIR, f)) def fetch_build(self, target_dir=None): if not target_dir: if self.target_dir: target_dir = self.target_dir else: raise ExecutionException(None, 'no Target Dir specified') with pwd(target_dir): source = self.pkg.pkg_cfg['source'] move(join('BUILD', source), join(self.pkg.code_dir, 'results')) def close(self): self.pkg.close() __all__ = ['Build']