Esempio n. 1
0
    def set_pkg_ext_ref_type(self, doc, typ):
        """
        Set the package's external reference type.
        Raise OrderError if no package previously defined.
        Raise SPDXValueError if malformed value.
        """
        self.assert_package_exists()
        if "#" in typ:
            typ = typ.split("#")[-1]
        else:
            typ = typ.split("/")[-1]

        if validations.validate_pkg_ext_ref_type(typ):
            if (len(doc.package.pkg_ext_refs)
                    and doc.package.pkg_ext_refs[-1].pkg_ext_ref_type is None):
                doc.package.pkg_ext_refs[-1].pkg_ext_ref_type = typ
            else:
                doc.package.add_pkg_ext_refs(
                    package.ExternalPackageRef(pkg_ext_ref_type=typ))
        else:
            raise SPDXValueError("ExternalRef::Type")
Esempio n. 2
0
    def set_pkg_ext_ref_category(self, doc, category):
        """
        Set the package's external reference locator.
        Raise OrderError if no package previously defined.
        Raise SPDXValueError if malformed value.
        """
        self.assert_package_exists()
        category = category.split("_")[-1]

        if category.lower() == "packagemanager":
            category = "PACKAGE-MANAGER"

        if validations.validate_pkg_ext_ref_category(category):
            if (len(doc.package.pkg_ext_refs)
                    and doc.package.pkg_ext_refs[-1].category is None):
                doc.package.pkg_ext_refs[-1].category = category
            else:
                doc.package.add_pkg_ext_refs(
                    package.ExternalPackageRef(category=category))
        else:
            raise SPDXValueError("ExternalRef::Category")