예제 #1
0
    def setUp(self):
        """
        Verify required modulemd file parameter has been specified, exists,
        and can be loaded. The file name and loaded metadata are saved.
        """
        mdfile = self.params.get('modulemd')
        if mdfile is None:
            self.error("modulemd parameter must be supplied")

        mdfile = str(mdfile)
        if not os.path.isfile(mdfile):
            self.error("modulemd file %s must exist" % mdfile)

        try:
            mmd = modulemd.ModuleMetadata()
            mmd.load(mdfile)
        except Exception as ex:
            self.error(
                "There was an error while processing modulemd file %s: %s" %
                (mdfile, ex))

        # Infer the module name from the mdfile name and check that it is sane
        mdfileModuleName, mdfileExtension = os.path.basename(mdfile).split(
            '.', 1)
        if (mdfileExtension != 'yaml') and (mdfileExtension != 'yml'):
            self.error("modulemd file %s must have a .y[a]ml extension" %
                       mdfile)
        if mmd.name == '':
            # The name can be missing from the metadata because the builder
            # knows how to infer it
            mmd.name = mdfileModuleName
        elif mmd.name != mdfileModuleName:
            self.error(
                "modulemd file name %s and module name %s do not match" %
                (mdfileModuleName, mmd.name))

        self.mdfile = mdfile
        self.mmd = mmd

        try:
            jargonfile = self.params.get('jargonfile')
            if jargonfile is not None:
                jargonfile = str(jargonfile)
                dict = DictWithPWL("en_US", jargonfile)
                for w in self.mmd.name.split('-'):
                    dict.add_to_session(w)
                self.chkr = SpellChecker(dict)
            else:
                self.chkr = SpellChecker("en_US")
        except:
            self.error(
                "Could not initialize spell checker with dictionary %s" % dict)
예제 #2
0
    def _init_spell_checker(self):
        """
        Initialize spell checker dictionary
        """

        default_dict = "en_US"
        spell_dict = None

        jargonfile = self.params.get('jargonfile')
        if not jargonfile:
            jargonfile = os.environ.get('JARGONFILE')
        if jargonfile is not None:
            try:
                jargonfile = str(jargonfile)
                spell_dict = DictWithPWL(default_dict, jargonfile)
            except:
                self.error(
                    "Could not initialize dictionary using %s file" % jargonfile)

        if not spell_dict:
            try:
                spell_dict = DictWithPWL(default_dict)
            except:
                self.error(
                    "Could not initialize spell checker with dictionary %s" % default_dict)

            #Check if there is jargonfile on module repo
            url = ("https://src.fedoraproject.org/cgit/modules/%s.git/plain/jargon.txt" %
                   self.mmd.name)
            resp = requests.get(url)
            if resp.status_code >= 200 and resp.status_code < 300:
                for w in resp.content.split("\n"):
                    if w != '':
                        spell_dict.add_to_session(w)

        #add words from module name as jargon
        for w in self.mmd.name.split('-'):
            spell_dict.add_to_session(w)

        try:
            chkr = SpellChecker(spell_dict)
        except:
            self.error("Could not initialize spell checker")

        return chkr