def __init__(self, name=None, tarball=""): if tarball: tmp_dir = mkdtemp() with pwd(tmp_dir): sourceball_name = copy(tarball, split(tarball)[1]) log.debug("sourceball_name " + sourceball_name) sourceball = tarfile.open(sourceball_name) extract_dir = base_dir(sourceball) if name and not name == extract_dir: log.debug("hahahahhaah") raise ExecutionException("tarball is not target directory") if not name: name = extract_dir super(SourceBall, self).__init__(name) if tarball: self.cfg["tarball_source"] = tarball with pwd(self.parent): sourceball.extractall() with pwd(self.branches_dir): sourceball.extractall() move(self.name, self.orig_dir(self.name)) with pwd(self.pkg_src_dir): move(join(tmp_dir, sourceball_name), sourceball_name) self.cfg["sourceball"] = sourceball_name self.set_cur_to("head")
def rpm_macros(**keys): for key, value in keys.iteritems(): log.debug('setting...') log.debug(key + ' ' + value) rpm.addMacro(key, value) yield for key, value in keys.iteritems(): rpm.delMacro(key)
def setup_source(self, package): '''Given a package, set's it up in the buildroot for being built with rpmbuild package is a directory name to a Package (Directory). returns nothing ''' pkg = DirFactory(package) with pwd(pkg.dir): symlink(pkg.spec_file, join(self.dir, 'SPECS', pkg.spec_file)) pkg.fetch_sourceballs() for source in pkg.spec_all_sources(): log.debug(source) symlink(source, join(self.dir, 'SOURCES', source))
def generate_patch(self, patch_name): prefix = self.next_patch_num + "." patch_name = patch_name + ".patch" if not patch_name.endswith(".patch") else patch_name patch_name = prefix + patch_name log.debug("patch_name " + patch_name) with self.patches_applied("orig"): with self.do_diff(self.branch("orig"), ".") as diff: with pwd(self.dir): with file(join(self.pkg_src_dir, patch_name), "w") as patch_file: diff(patch_file) # We have to do this last step because of the context manager # it assumes that this last patch has also been applied patch_name = join(self.pkg_src_dir, patch_name) with pwd(self.branch_dir("orig")): self.apply_patch(patch_name)
def add_spec(self, spec_file): '''add's a spec file to the package, and sets the canonical package name based on the spec file, possibly renaming the spec file to match within fedora guidelines''' log.debug('spec_file is %s' % spec_file) log.debug('spec_file_name is %s' % self.name + '.spec') #TODO: get the spec file name, copy # Then get the actual package name and set pkg_name to the right one spec_file = abspath(spec_file) spec_fname = basename(spec_file) with pwd(self.dir): try: copy(spec_file, spec_fname) rpm = RPMSpec(spec_fname) self.cfg['pkg_name'] = rpm.name() if not spec_fname == self.spec_file: move(spec_fname, self.spec_file) except IOError, e: log.error(str(e)) raise ExecutionException(e, 'spec-file could not be added')
def build(self, package): pkg = DirFactory(package) srpm_name = pkg.get_srpm_name(self.profile) mock_cfg = self.profile.mock_cfg result_dir = self.profile.result_dir config_dir = self.profile.mock_cfg_dir log.debug("mock_cfg is " + mock_cfg) log.debug("result_dir is " + result_dir) log.debug("config_dir is " + config_dir) cmd = ["mock", "-r", mock_cfg, "--configdir=%s" % config_dir, "--resultdir=%s" % result_dir, srpm_name] log.debug("cmd is " + str(cmd)) with pwd(result_dir): with log_file("mock.log") as mock_out: p = Popen(cmd, stdout=mock_out, stderr=mock_out) log.info("mock compiling %s... please wait" % srpm_name) p.communicate()
def rpmbuild(self, param, package, profile=None): '''The work horse of building rpms Given a directive param for rpmbuild, the package, and a possible profile, it runs rpmbuild appropriatly. package is a directory name to a Package (Directory). profile is a Profile object, this parameter should only be used internally returns nothing ''' pkg = DirFactory(package) log.debug(package) log.debug(pkg) if profile: defines = join_defines(profile.dist_defines, dir_defines(self.dir)) else: defines = dir_defines(self.dir) log.debug('defines are ' + str(defines)) log.debug('spec file is ' + pkg.spec_file) cmd = ['rpmbuild'] + defines + ['-v', param, pkg.spec_file] log.debug('cmd is ' + str(cmd)) with pwd(pkg.dir): with log_file('rpmbuild.log') as rpm_out: with pwd(join(self.dir, 'SPECS')): p = Popen(cmd, stdout=rpm_out, stderr=rpm_out) log.info('building %s... please wait' % pkg.spec_file) p.wait() log.debug(p.returncode)