def read_config_file(self, config_file=None): if not config_file: config_file = (utils.find_file( 'config', [OSG_KOJI_USER_CONFIG_DIR, KOJI_USER_CONFIG_DIR]) or utils.find_file(KOJI_CONF, DATA_FILE_SEARCH_PATH) or utils.find_file(OLD_KOJI_CONF, DATA_FILE_SEARCH_PATH)) if not config_file or not os.path.isfile(config_file): raise KojiError("Can't find koji config file.") try: cfg = ConfigParser.ConfigParser() cfg.read(config_file) items = dict(cfg.items('koji')) except ConfigParser.Error, err: raise KojiError("Can't read config file from %s: %s" % (config_file, str(err)))
def get_koji_cmd(use_osg_koji): """Get the command used to call koji.""" # Use osg-koji wrapper if available and configured. if utils.which("osg-koji") and use_osg_koji: return ["osg-koji"] elif utils.which("koji"): # Not using osg-koji, so we need to find the conf file and do some # checks ourselves. conf_file = (utils.find_file(KOJI_CONF, DATA_FILE_SEARCH_PATH) or utils.find_file(OLD_KOJI_CONF, DATA_FILE_SEARCH_PATH)) if not conf_file: raise KojiError("Can't find %s or %s; search path was: %s" % (KOJI_CONF, OLD_KOJI_CONF, os.pathsep.join(DATA_FILE_SEARCH_PATH))) return ["koji", "--config", conf_file, "--authtype", "ssl"] else: raise KojiError("Can't find koji or osg-koji!")
def make_mock_config_from_template(arch, cfg_path, dist, rhel): """Autogenerate a mock config for arch 'arch'.""" if re.match(r'i[3-6]86', arch): basearch = 'i386' else: basearch = arch cfg_abspath = os.path.abspath(cfg_path) cfg_name = re.sub(r'\.cfg$', '', os.path.basename(cfg_abspath)) template = string.Template(utils.slurp(utils.find_file('mock-auto.cfg.in', DATA_FILE_SEARCH_PATH))) utils.unslurp(cfg_abspath, template.safe_substitute(NAME=cfg_name, ARCH=arch, BASEARCH=basearch, DIST=dist, RHEL=rhel)) return cfg_abspath
def lint(self): """lint task. Prebuild the package and run rpmlint on the SRPM.""" if not utils.which("rpmlint"): raise ProgramNotFoundError("rpmlint") conf_file = utils.find_file("rpmlint.cfg", DATA_FILE_SEARCH_PATH) if not conf_file: raise FileNotFoundError("rpmlint.cfg", DATA_FILE_SEARCH_PATH) srpm = self.prebuild() lint_output, lint_returncode = utils.sbacktick( ["rpmlint", "-f", conf_file, srpm]) print lint_output if lint_returncode == 0: print "rpmlint ok for " + self.package_name elif lint_returncode < 64: print "Error running rpmlint for " + self.package_name elif lint_returncode == 64: print "rpmlint found problems with " + self.package_name elif lint_returncode == 66: print "rpmlint found many problems with " + self.package_name else: print "unrecognized return code from rpmlint: " + str(lint_returncode)
def make_mock_config_from_template(arch, cfg_path, dist, rhel): """Autogenerate a mock config for arch 'arch'.""" if re.match(r'i[3-6]86', arch): basearch = 'i386' else: basearch = arch cfg_abspath = os.path.abspath(cfg_path) cfg_name = re.sub(r'\.cfg$', '', os.path.basename(cfg_abspath)) template = string.Template( utils.slurp(utils.find_file('mock-auto.cfg.in', DATA_FILE_SEARCH_PATH))) utils.unslurp( cfg_abspath, template.safe_substitute(NAME=cfg_name, ARCH=arch, BASEARCH=basearch, DIST=dist, RHEL=rhel)) return cfg_abspath
import shutil import tempfile import unittest from unittest import makeSuite import sys import osgbuild.constants as C from osgbuild import main from osgbuild import srpm from osgbuild.utils import (checked_backtick, checked_call, CalledProcessError, find_file, errprintf) TRUNK = "native/redhat/trunk" initial_wd = os.getcwd() osg_build_path = find_file('osg-build', [initial_wd, '/usr/bin']) if not osg_build_path: errprintf("osg-build script not found!") sys.exit(255) osg_build_command = [osg_build_path] def common_setUp(path, rev): '''Create a temporary directory, ensure it gets deleted on exit, cd to it, and check out a specific revision of a path from our SVN. ''' working_dir = tempfile.mkdtemp(prefix="osg-build-test-") atexit.register(shutil.rmtree, working_dir)
def _init_get_cfg_path(self): """Find the appropriate configuration to use for mock based on options and make a Mock object with it. """ distro_tag = self.buildopts['distro_tag'] mock_config = self.buildopts['mock_config'] mock_config_from_koji = self.buildopts['mock_config_from_koji'] target_arch = self.buildopts['target_arch'] machine_arch = os.uname()[4] # the "or ''" part is in case target_arch is None if re.search("i[3-6]86", target_arch or ''): arch = 'i386' elif (re.search("x86_64", target_arch or '') and not re.search("x86_64", machine_arch)): raise OSGBuildError("Can't do 64-bit build on 32-bit machine") else: arch = machine_arch if mock_config: if mock_config == "AUTO": cfg_dir = tempfile.mkdtemp(prefix="osg-build-mock-") atexit.register(shutil.rmtree, cfg_dir) cfg_path = make_mock_config_from_template( arch, os.path.join(cfg_dir,"mock-auto-%s.%d.cfg" % (arch, os.getuid())), distro_tag, self.buildopts['redhat_release']) else: # mock is very particular with its config file # names. The path we pass it is interpreted to be # relative to '/etc/mock', and mock will append '.cfg' # to the end of the config file name. So the argument # to --mock-config can be interpreted in the usual way # (as a file name with either an absolute path or path # relative to the cwd), or it can be interpreted in # the way mock does it. Figure out which the user # meant (by seeing which interpretation exists) and # translate it to what mock wants. if not mock_config.endswith(".cfg"): given_cfg_path = mock_config + ".cfg" else: given_cfg_path = mock_config if given_cfg_path.startswith('/'): # Absolute path cfg_path = given_cfg_path else: # Relative path. Can be relative to cwd or # /etc/mock. Prefer cwd. given_cfg_dir, given_cfg_file = os.path.split(given_cfg_path) cfg_dir1 = os.path.abspath(given_cfg_dir) cfg_dir2 = os.path.abspath(os.path.join('/etc/mock', given_cfg_dir)) cfg_path = utils.find_file(given_cfg_file, [cfg_dir1, cfg_dir2]) elif mock_config_from_koji: cfg_dir = tempfile.mkdtemp(prefix="osg-build-mock-") atexit.register(shutil.rmtree, cfg_dir) cfg_path = make_mock_config_from_koji( self.koji_obj, arch, os.path.join(cfg_dir,"mock-koji-%s-%s.%d.cfg" % (mock_config_from_koji, arch, os.getuid())), mock_config_from_koji, distro_tag) else: cfg_path = None # end if return cfg_path
def _init_get_cfg_path(self): """Find the appropriate configuration to use for mock based on options and make a Mock object with it. """ distro_tag = self.buildopts['distro_tag'] mock_config = self.buildopts['mock_config'] mock_config_from_koji = self.buildopts['mock_config_from_koji'] target_arch = self.buildopts['target_arch'] machine_arch = os.uname()[4] # the "or ''" part is in case target_arch is None if re.search("i[3-6]86", target_arch or ''): arch = 'i386' elif (re.search("x86_64", target_arch or '') and not re.search("x86_64", machine_arch)): raise OSGBuildError("Can't do 64-bit build on 32-bit machine") else: arch = machine_arch if mock_config: if mock_config == "AUTO": cfg_dir = tempfile.mkdtemp(prefix="osg-build-mock-") atexit.register(shutil.rmtree, cfg_dir) cfg_path = make_mock_config_from_template( arch, os.path.join(cfg_dir, "mock-auto-%s.%d.cfg" % (arch, os.getuid())), distro_tag, self.buildopts['redhat_release']) else: # mock is very particular with its config file # names. The path we pass it is interpreted to be # relative to '/etc/mock', and mock will append '.cfg' # to the end of the config file name. So the argument # to --mock-config can be interpreted in the usual way # (as a file name with either an absolute path or path # relative to the cwd), or it can be interpreted in # the way mock does it. Figure out which the user # meant (by seeing which interpretation exists) and # translate it to what mock wants. if not mock_config.endswith(".cfg"): given_cfg_path = mock_config + ".cfg" else: given_cfg_path = mock_config if given_cfg_path.startswith('/'): # Absolute path cfg_path = given_cfg_path else: # Relative path. Can be relative to cwd or # /etc/mock. Prefer cwd. given_cfg_dir, given_cfg_file = os.path.split( given_cfg_path) cfg_dir1 = os.path.abspath(given_cfg_dir) cfg_dir2 = os.path.abspath( os.path.join('/etc/mock', given_cfg_dir)) cfg_path = utils.find_file(given_cfg_file, [cfg_dir1, cfg_dir2]) elif mock_config_from_koji: cfg_dir = tempfile.mkdtemp(prefix="osg-build-mock-") atexit.register(shutil.rmtree, cfg_dir) cfg_path = make_mock_config_from_koji( self.koji_obj, arch, os.path.join( cfg_dir, "mock-koji-%s-%s.%d.cfg" % (mock_config_from_koji, arch, os.getuid())), mock_config_from_koji, distro_tag) else: cfg_path = None # end if return cfg_path
import osgbuild.constants as C from osgbuild import main from osgbuild import srpm from osgbuild.utils import ( checked_backtick, checked_call, CalledProcessError, find_file, errprintf, unslurp) TRUNK = "native/redhat/trunk" initial_wd = os.getcwd() osg_build_path = find_file('osg-build', [initial_wd, '/usr/bin']) if not osg_build_path: errprintf("osg-build script not found!") sys.exit(255) osg_build_command = [osg_build_path] def go_to_temp_dir(): working_dir = tempfile.mkdtemp(prefix="osg-build-test-") atexit.register(shutil.rmtree, working_dir) os.chdir(working_dir) return working_dir