Пример #1
0
    def parse_only_extr_license(self, extr_lic):
        """
        Return an ExtractedLicense object to represent a license object.
        But does not add it to the SPDXDocument model.
        Return None if failed.
        """
        # Grab all possible values
        ident = self.get_extr_license_ident(extr_lic)
        text = self.get_extr_license_text(extr_lic)
        comment = self.get_extr_lics_comment(extr_lic)
        xrefs = self.get_extr_lics_xref(extr_lic)
        name = self.get_extr_lic_name(extr_lic)

        if not ident:
            # Must have identifier
            return

        # Set fields
        # FIXME: the constructor of the license should alwas accept a name
        lic = document.ExtractedLicense(ident)
        if text is not None:
            lic.text = text
        if name is not None:
            lic.full_name = name
        if comment is not None:
            lic.comment = comment
        lic.cross_ref = list(map(lambda x: six.text_type(x), xrefs))
        return lic
Пример #2
0
    def parse_only_extr_license(self, extr_lic):
        """Returns a License object to represent a license object.
        But does not add it to the SPDXDocument model.
        Returns None if failed.
        """
        # Grab all possible values
        ident = self.get_extr_license_ident(extr_lic)
        text = self.get_extr_license_text(extr_lic)
        comment = self.get_extr_lics_comment(extr_lic)
        xrefs = self.get_extr_lics_xref(extr_lic)
        name = self.get_extr_lic_name(extr_lic)

        if ident is None:
            # Must have identifier
            return

        # Set fields
        lic = document.ExtractedLicense(ident)
        if text is not None:
            lic.text = text
        if name is not None:
            lic.full_name = name
        if comment is not None:
            lic.comment = comment
        lic.cross_ref = map(lambda x: six.text_type(x), xrefs)
        return lic
Пример #3
0
 def set_lic_id(self, doc, lic_id):
     """Adds a new extracted license to the document.
     Raises SPDXValueError if data format is incorrect.
     """
     self.reset_extr_lics()
     if validations.validate_extracted_lic_id(lic_id):
         doc.add_extr_lic(document.ExtractedLicense(lic_id))
         return True
     else:
         raise SPDXValueError('ExtractedLicense::id')
Пример #4
0
 def create_license_helper(self, lic):
     """
     Handle single(no conjunction/disjunction) licenses.
     Return the created node.
     """
     if isinstance(lic, document.ExtractedLicense):
         return self.create_extracted_license(lic)
     if lic.identifier.rstrip("+") in config.LICENSE_MAP:
         return URIRef(lic.url)
     else:
         matches = [
             l for l in self.document.extracted_licenses
             if l.identifier == lic.identifier
         ]
         if len(matches) != 0:
             return self.create_extracted_license(matches[0])
         else:
             lic = document.ExtractedLicense(lic.identifier)
             warnings.warn("Missing extracted license: {0}".format(
                 lic.identifier))
             return self.create_extracted_license(lic)