Example #1
0
 def build(self, filename):
     """
     Run a mock build against the srpm filename.
     Raises ReviewError on build errors, return
     nothing.
     """
     cmd = ' '.join(self._mock_cmd())
     if Settings.log_level > logging.INFO:
         cmd += ' -q'
     cmd += ' --rebuild'
     cmd += ' ' + filename + ' 2>&1 | tee build.log'
     if not Settings.verbose and not ' -q' in cmd:
         cmd += ' | egrep "Results and/or logs|ERROR" '
     self.log.debug('Build command: %s' % cmd)
     rc = call(cmd, shell=True)
     self.builddir_cleanup()
     rc = str(rc)
     try:
         with open('build.log') as f:
             log = '\n'.join(f.readlines())
             if 'ERROR' in log:
                 rc = 'Build error(s)'
     except IOError:
         rc = "Can't open logfile"
     if rc == '0':
         self.log.info('Build completed')
         return None
     else:
         self.log.debug('Build failed rc = ' + rc)
         error = ReviewError('mock build failed, see ' + self.resultdir
                             + '/build.log')
         error.show_logs = False
         raise error
Example #2
0
 def build(self, filename):
     """
     Run a mock build against the srpm filename.
     Raises ReviewError on build errors, return
     nothing.
     """
     self.clear_builddir()
     mock_cmd = ['"' + s + '"' for s in self._mock_cmd()]
     cmd = ' '.join(mock_cmd)
     if Settings.log_level > logging.INFO:
         cmd += ' -q'
     cmd += ' --rebuild'
     cmd += ' ' + filename + ' 2>&1 | tee build.log'
     if not Settings.verbose and ' -q' not in cmd:
         cmd += ' | egrep "Results and/or logs|ERROR" '
     self.log.debug('Build command: %s' % cmd)
     rc = call(cmd, shell=True)
     self.builddir_cleanup()
     rc = str(rc)
     try:
         with open('build.log') as f:
             log = '\n'.join(f.readlines())
             if 'ERROR' in log:
                 rc = 'Build error(s)'
     except IOError:
         rc = "Can't open logfile"
     if rc == '0':
         self.log.info('Build completed')
         return None
     else:
         self.log.debug('Build failed rc = ' + rc)
         error = ReviewError('mock build failed, see ' + self.resultdir +
                             '/build.log')
         error.show_logs = False
         raise error
Example #3
0
 def get_package_srpm_path(spec):
     ''' Return path to srpm given a spec. '''
     pattern = '*%s-%s*' % (spec.name, spec.version)
     paths = self._get_rpm_paths(pattern)
     paths = [p for p in paths if p.endswith('.src.rpm')]
     if len(paths) == 0:
         raise ReviewError('No srpm found for ' + spec.name)
     elif len(paths) > 1:
         raise ReviewError('Multiple srpms found for ' + spec.name)
     else:
         return paths[0]
Example #4
0
 def get_package_rpm_path(self, nvr):
     '''
     Return path to generated pkg_name rpm, throws ReviewError
     on missing or multiple matches. Argument should have
     have name, version and release attributes.
     '''
     pattern = '%s-%s*' % (nvr.name, nvr.version)
     paths = self._get_rpm_paths(pattern)
     paths = filter(
         lambda p: p.endswith('.rpm') and not p.endswith('.src.rpm'), paths)
     if len(paths) == 0:
         raise ReviewError('No built package found for ' + nvr.name)
     elif len(paths) > 1:
         raise ReviewError('Multiple packages found for ' + nvr.name)
     else:
         return paths[0]
Example #5
0
    def _get_prebuilt_macros(self, spec, flags):
        ''' Evaluate macros based on prebuilt packages (#208).'''

        paths = self.get_package_rpm_paths(spec)
        tag = _get_tag(paths)
        if not tag.startswith('fc') and not tag.startswith('el'):
            tag = _get_tag_from_flags(self, flags)
        macros = _add_disttag_macros({}, tag)
        buildarch, macros = _add_buildarch_macros(macros, paths)
        try:
            _arch = check_output('rpm --eval %_arch'.split()).strip()
        except CalledProcessError:
            raise ReviewError("Can't evaluate 'rpm --eval %_arch")
        if buildarch is 'x86_64' and _arch is not 'x86_64':
            raise ReviewError("Can't build x86_64 on i86 host")
        return macros
Example #6
0
 def _do_run(self, outfile=None):
     ''' Initiate, download url:s, run checks a write report. '''
     Settings.init()
     make_report = True
     if Settings.list_checks:
         self._list_checks()
         make_report = False
     elif Settings.list_flags:
         self._list_flags()
         make_report = False
     elif Settings.version:
         self._print_version()
         make_report = False
     elif Settings.list_plugins:
         self._list_plugins()
         make_report = False
     elif Settings.url:
         self.log.info("Processing bug on url: " + Settings.url)
         self.bug = UrlBug(Settings.url)
     elif Settings.bug:
         self.log.info("Processing bugzilla bug: " + Settings.bug)
         self.bug = BugzillaBug(Settings.bug)
     elif Settings.name:
         self.log.info("Processing local files: " + Settings.name)
         self.bug = NameBug(Settings.name)
     if make_report:
         if not Mock.is_available() and not Settings.prebuilt:
             raise ReviewError("Mock unavailable, --prebuilt must be used.")
         self._do_report(outfile)
Example #7
0
 def check_source_checksum(self):
     ''' Check source with upstream source using checksumming. '''
     self.log.debug("Checking source {0} : {1}".format(
         Settings.checksum, self.filename))
     if self.downloaded:
         return self._checksum(self.filename)
     else:
         raise ReviewError(self.tag + ": upstream source not found")
Example #8
0
def _make_log_dir():
    ''' Create the log dir, unless it's already there. '''
    try:
        os.makedirs(os.path.dirname(SESSION_LOG))
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise ReviewError('Cannot create log directory: ' +
                              SESSION_LOG)
Example #9
0
def _get_tag_from_flags(self, flags):
    ''' Retrieve disttag from user defined flag value. '''
    if flags['DISTTAG']:
        self.log.info("Using disttag from DISTTAG flag.")
        return flags['DISTTAG'].value
    self.log.warning('No disttag found in prebuilt packages')
    self.log.info('Use --define DISTTAG to set proper dist.'
                  ' e. g. --define DISTTAG fc21.')
    raise ReviewError('No disttag in package and no DISTTAG flag.'
                      ' Use --define DISTTAG to set proper dist'
                      ' e. g., --define DISTTAG=fc21.')
Example #10
0
 def _update_flags(self):
     ''' Update registered flags with user -D settings. '''
     for flag_opt in Settings.flags:
         try:
             if '=' not in flag_opt:
                 key = flag_opt
                 self.flags[flag_opt].activate()
             else:
                 key, value = flag_opt.split('=')
                 self.flags[key].value = value
         except KeyError:
             raise ReviewError(key + ': No such flag')
Example #11
0
def _check_mock_grp():
    ''' Raise ReviewError unless mock installation is OK. '''

    mock_msg = \
        'No mock group - mock not installed or mock not in effective' \
        'groups. Try running  "newgrp" or logging out from all your local ' \
        'sessions and logging back in. Or disable test using ' \
        'REVIEW_NO_MOCKGROUP_CHECK, see manpage'

    if 'REVIEW_NO_MOCKGROUP_CHECK' in os.environ:
        return
    mock_gid = grp.getgrnam('mock')[2]
    if mock_gid not in os.getgroups():
        raise ReviewError(mock_msg)
Example #12
0
    def _get_spec_from_srpm(self):
        ''' Extract spec from srpm and update self.spec_url. '''
        path = urlparse(self.srpm_url).path
        name = os.path.basename(path).rsplit('-', 2)[0]
        ReviewDirs.workdir_setup(name, Settings.cache)
        self.do_download_srpm()

        SRPMFile(self.srpm_file).unpack()
        try:
            path = glob(os.path.join(ReviewDirs.srpm_unpacked,
                                     name + '*.spec'))[0]
        except IndexError:
            raise ReviewError("Cannot find spec file in srpm")
        self.spec_file = path
        self.spec_url = 'file://' + path
Example #13
0
    def extract(self):
        ''' Extract the source into a directory under upstream-unpacked,
            available in the extract_dir property. Sources which not
            could be extracted e. g., plain files are copied to the
            extract-dir.
        '''
        if not os.path.isfile(self.filename):
            raise ReviewError("%s file %s is missing in src.rpm."
                              " Conditional source inclusion?" %
                              (self.tag, self.filename))

        self.extract_dir = os.path.join(ReviewDirs.upstream_unpacked, self.tag)
        if os.path.exists(self.extract_dir):
            return
        os.mkdir(self.extract_dir)
        if self.downloaded:
            if not self.rpmdev_extract(self.filename, self.extract_dir):
                shutil.copy(self.filename, self.extract_dir)
Example #14
0
 def __init__(self):
     ReviewError.__init__(
         self, 'The resultdir is not empty, I cannot handle this')
Example #15
0
 def __init__(self, path):
     msg = 'The directory %s is in the way, please remove' % \
         os.path.abspath(path)
     ReviewError.__init__(self, msg, 2)
     self.show_logs = False
Example #16
0
 def __init__(self):
     ReviewError.__init__(
         self,
         'The resultdir is not empty, I cannot handle this')
Example #17
0
 def __init__(self, code, url):
     ReviewError.__init__(
         self, "Error %s downloading %s" % (code, url))
Example #18
0
 def __init__(self, what):
     ReviewError.__init__(self, "Incompatible settings: " + what)
Example #19
0
 def __init__(self, msg):
     ReviewError.__init__(self, msg)
Example #20
0
 def __init__(self):
     ReviewError.__init__(self, 'Bad options!!', 2, True)
Example #21
0
 def __init__(self, what):
     ReviewError.__init__(self, what, 2)
     self.show_logs = False
Example #22
0
 def __init__(self, what):
     ReviewError.__init__(self, "Incompatible settings: " + what)
Example #23
0
 def __init__(self, what):
     ReviewError.__init__(self, what, 2)
     self.show_logs = False
Example #24
0
 def __init__(self, path):
     msg = 'The directory %s is in the way, please remove' % \
         os.path.abspath(path)
     ReviewError.__init__(self, msg, 2)
     self.show_logs = False
Example #25
0
 def __init__(self):
     ReviewError.__init__(self, 'Bad options!!', 2, True)
Example #26
0
 def __init__(self, msg):
     ReviewError.__init__(self, msg)