def _get_spec_file(self, prj, pkg, rev):

        file_list = []
        try:
            file_list = self.obs.getPackageFileList(prj, pkg, revision=rev)
        except:
            pass

        specs = [ fil for fil in file_list if fil.endswith(".spec")]

        if len(specs) > 1:
             specs = [ fil for fil in specs if (fil == "%s.spec" % pkg or fil.endswith(":%s.spec" % pkg))]

        if not specs:
            return "No specfile in %s" % pkg, None

        elif len(specs) > 1:
             return "Couldn't determine which spec file to use for %s " % pkg, None

        print specs
        fil = specs[0]

        spec = self.obs.getFile(prj, pkg, fil, revision=rev)
        specob = None

        print fil
        print spec
        with NamedTemporaryFile() as specf:
            specf.write(spec)
            specf.flush()
            try:
                specob = parse_spec(specf.name)
            except ValueError, exobj:
                return "Could not parse spec in %s: %s" % (pkg, exobj), None
 def check_spec_version_match(self, version, prj, pkg, rev=None):
     """Check that spec version matches given version"""
     spec = ""
     file_list = self.obs.getPackageFileList(prj, pkg, revision=rev)
     for fil in file_list:
         if fil.endswith(".spec"):
             spec = self.obs.getFile(prj, pkg, fil, revision=rev)
             break
     if not spec:
         return False, "No specfile in %s" % pkg
     with NamedTemporaryFile() as specf:
         specf.write(spec)
         specf.flush()
         try:
             specob = parse_spec(specf.name)
         except ValueError, exobj:
             return False, "Could not parse spec in %s: %s" % (pkg, exobj)
Пример #3
0
class ParticipantHandler(object):
    """ Participant class as defined by the SkyNET API """
    def __init__(self):
        self.obs = None
        self.oscrc = None

    def handle_wi_control(self, ctrl):
        """ job control thread """
        pass

    def handle_lifecycle_control(self, ctrl):
        """ participant control thread """
        if ctrl.message == "start":
            if ctrl.config.has_option("obs", "oscrc"):
                self.oscrc = ctrl.config.get("obs", "oscrc")

    def setup_obs(self, namespace):
        """ setup the Buildservice instance using the namespace as an alias
            to the apiurl """

        self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)

    @CheckActionProcessor("check_package_is_complete")
    def is_complete(self, action, wid):
        """ Package file completeness check """

        filelist = self.obs.getPackageFileList(action['sourceproject'],
                                               action['sourcepackage'],
                                               action['sourcerevision'])

        if "_service" in filelist:
            filelist.remove("_service")
        if "_ccache" in filelist:
            filelist.remove("_ccache")
        if "_src" in filelist:
            filelist.remove("_src")
        spec = self.has_spec_file(action, wid, filelist)[0]
        changes = self.has_changes_file(action, wid, filelist)[0]
        sources = spec and self.check_source_files(action, wid, filelist)[0]

        return (spec and changes and sources), ""

    def get_rpm_sources(self, action, filelist):
        """Extract source file list from package spec.

        :parma action: OBS request action dictionary
        :param filelist: List of package files
        :returns: List of source file names
        :raises SourceError: If something goes wrong
        """
        try:
            specs = [name for name in filelist if name.endswith(".spec")]
            if len(specs) > 1:
                specs = [
                    name for name in filelist
                    if name.endswith("%s.spec" % action['sourcepackage'])
                ]
            if len(specs) > 1:
                specs = [
                    name for name in filelist
                    if name.endswith(":%s.spec" % action['sourcepackage'])
                ]
            spec_name = specs[0]
        except IndexError:
            # raise SourceError("No spec file found")
            return []
        print spec_name
        try:
            spec = self.obs.getFile(action["sourceproject"],
                                    action["sourcepackage"], spec_name,
                                    action["sourcerevision"])
        except Exception, exobj:
            raise SourceError(
                "Failed to fetch spec file %s/%s/%s rev %s: %s" %
                (action["sourceproject"], action["sourcepackage"], spec_name,
                 action["sourcerevision"], exobj))
        import hashlib
        print "Spec file retrieved from", action["sourceproject"], action[
            "sourcepackage"], action["sourcerevision"], ": ", hashlib.md5(
                spec).hexdigest()
        try:
            tmp_spec = NamedTemporaryFile(mode="w", delete=False)
            tmp_spec.file.write(spec)
            tmp_spec.file.flush()
            print "Parsing spec file from", tmp_spec.name
            spec_obj = parse_spec(tmp_spec.name)
            sources = [
                os.path.basename(name) for name, _, _ in spec_obj.sources
            ]
            tmp_spec.close()
        except ValueError, exobj:
            raise SourceError("Failed to parse spec file: %s" % exobj)