Beispiel #1
0
    def save_license(self, key, mapping, text):
        """
        Return a ScanCode License for `key` constructed from a `mapping`
        of attributes and a license `text`. Save the license metadata
        and its text in the `self.src_dir`.
        """
        new_key = None
        if self.matching_key == 'key':
            new_key = self.find_key(key, text)
        elif self.matching_key == 'spdx_license_key':
            new_key = self.find_key(mapping['spdx_license_key'], text)

        if not new_key:
            key = key.lower()
            if TRACE: print('  No Scancode key found. USING key as:', key)
        else:
            if key == new_key:
                if TRACE: print('  Scancode key found:', key)
            else:
                if TRACE: print('  Scancode key found:', new_key, 'CHANGED from:', key)
                key = new_key

        lic = License(key=key, src_dir=self.src_dir)
        for name, value in mapping.items():
            setattr(lic, name, value)

        with codecs.open(lic.text_file, 'wb', encoding='utf-8')as tf:
            tf.write(text)
        lic.dump()
        return lic
Beispiel #2
0
    def save_license(self, key, mapping, text):
        """
        Return a ScanCode License for `key` constructed from a `mapping`
        of attributes and a license `text`. Save the license metadata
        and its text in the `self.src_dir`.
        """
        new_key = None
        if self.matching_key == 'key':
            new_key = self.find_key(key, text)
        elif self.matching_key == 'spdx_license_key':
            new_key = self.find_key(mapping['spdx_license_key'], text)

        if not new_key:
            key = key.lower()
            if TRACE: print('  No Scancode key found. USING key as:', key)
        else:
            if key == new_key:
                if TRACE: print('  Scancode key found:', key)
            else:
                if TRACE:
                    print('  Scancode key found:', new_key, 'CHANGED from:',
                          key)
                key = new_key

        lic = License(key=key, src_dir=self.src_dir)
        for name, value in mapping.items():
            setattr(lic, name, value)

        with codecs.open(lic.text_file, 'wb', encoding='utf-8') as tf:
            tf.write(text)
        lic.dump()
        return lic
Beispiel #3
0
    def build_license(self, mapping, scancode_licenses):
        """
        Return a ScanCode License object built from a DejaCode license
        mapping or None for skipped licenses.
        """
        key = mapping['key']

        # TODO: Not yet available in ScanCode
        is_foreign = key in scancode_licenses.non_english_by_key
        if is_foreign:
            if TRACE: print('Skipping NON-english license:', key)
            return

        # these licenses are rare commercial license with no text and only a
        # link so we ignore these
        dejacode_special_no_text = set([
            'alglib-commercial',
            'atlassian-customer-agreement',
            'dalton-maag-eula',
            'highsoft-standard-license-agreement-4.0',
            'monotype-tou',
        ])
        is_special = key in dejacode_special_no_text
        if is_special:
            if TRACE:
                print(
                    'Skipping special DejaCode license with NO TEXT FOR NOW:',
                    key)
            return

        # these licenses are combos of many others and are ignored: we detect
        # instead each part of the combo
        dejacode_special_composites = set([
            'lzma-sdk-2006',
            'intel-bsd-special',
            'openssh',
            'aes-128-3.0',
            'stlport-2000',
        ])
        is_combo = key in dejacode_special_composites
        if is_combo:
            if TRACE: print('Skipping DejaCode combo license', key)
            return

        deprecated = not mapping.get('is_active')
        if deprecated and key not in scancode_licenses.by_key:
            if TRACE:
                print('Skipping deprecated license not in ScanCode:', key)
            return

        standard_notice = mapping.get('standard_notice') or ''
        standard_notice = clean_text(standard_notice)

        lic = License(
            key=key,
            src_dir=self.original_dir,
            name=mapping['name'],
            short_name=mapping['short_name'],
            homepage_url=mapping['homepage_url'],
            category=mapping['category'],
            owner=mapping['owner_name'],

            # FIXME: we may not want to carry notes over???
            # lic.notes = mapping.notes
            spdx_license_key=mapping['spdx_license_key'],
            text_urls=mapping['text_urls'].splitlines(False),
            osi_url=mapping['osi_url'],
            faq_url=mapping['faq_url'],
            other_urls=mapping['other_urls'].splitlines(False),
            is_exception=mapping.get('is_exception', False),
            is_deprecated=deprecated,
            standard_notice=standard_notice,
        )
        text = mapping['full_text'] or ''
        # normalize EOL to POSIX
        text = text.replace('\r\n', '\n').strip()
        return lic, text
Beispiel #4
0
    def build_license(self, mapping, scancode_licenses):
        """
        Return a ScanCode License object built from an SPDX license mapping.
        """
        spdx_license_key = mapping.get('licenseId') or mapping.get(
            'licenseExceptionId')
        assert spdx_license_key
        spdx_license_key = spdx_license_key.strip()
        key = spdx_license_key.lower()

        # TODO: Not yet available in ScanCode
        is_foreign = key in scancode_licenses.non_english_by_spdx_key
        if is_foreign:
            if TRACE: print('Skipping NON-english license FOR NOW:', key)
            return

        # these keys have a complicated history
        if key in set([
                'gpl-1.0',
                'gpl-2.0',
                'gpl-3.0',
                'lgpl-2.0',
                'lgpl-2.1',
                'lgpl-3.0',
                'agpl-1.0',
                'agpl-2.0',
                'agpl-3.0',
                'gfdl-1.1',
                'gfdl-1.2',
                'gfdl-1.3',
                'nokia-qt-exception-1.1',
        ]):
            return

        deprecated = mapping.get('isDeprecatedLicenseId', False)
        if deprecated:
            # we use concrete keys for some plus/or later versions for
            # simplicity and override SPDX deprecation for these
            if key.endswith('+'):
                # 'gpl-1.0+', 'gpl-2.0+', 'gpl-3.0+',
                # 'lgpl-2.0+', 'lgpl-2.1+', 'lgpl-3.0+',
                # 'gfdl-1.1+', 'gfdl-1.2+', 'gfdl-1.3+'
                # 'agpl-3.0+'
                deprecated = False

        other_urls = mapping.get('seeAlso', [])
        other_urls = (o for o in other_urls if o)
        other_urls = (o.strip() for o in other_urls)
        other_urls = (o for o in other_urls if o)
        # see https://github.com/spdx/license-list-data/issues/9
        junk_see_also = ('none', 'found')
        other_urls = (o for o in other_urls if o not in junk_see_also)

        other_urls = list(other_urls)

        #         notes = mapping.get('licenseComments')
        #         if notes and notes.strip():
        #             notes = 'Per SPDX.org, ' + ' '.join(notes.split())

        standard_notice = mapping.get('standardLicenseHeader') or ''
        if standard_notice:
            standard_notice = clean_text(standard_notice)

        lic = License(
            key=key,
            src_dir=self.original_dir,
            spdx_license_key=spdx_license_key,
            name=mapping['name'].strip(),
            short_name=mapping['name'].strip(),
            is_deprecated=deprecated,
            is_exception=bool(mapping.get('licenseExceptionId')),
            other_urls=other_urls,

            # TODO: the formatting might need to be preserved
            standard_notice=standard_notice,

            # FIXME: Do we really want to carry notes over???
            # notes=notes,

            # FIXME: available in ScanCode but as an OSI URL
            # we should check if we have the osi_url when this flag is there?
            # osi_url = mapping.get('isOsiApproved', False)

            # TODO: detect licenses on these texts to ensure they match?
            # TODO: add rule? and test license detection???
            # standard_template = mapping('standardLicenseTemplate')
            # exception_example
            # example = mapping.get('example')
        )
        text = mapping.get('licenseText') or mapping.get(
            'licenseExceptionText')
        text = text.strip()
        return lic, text
Beispiel #5
0
    def build_license(self, mapping, scancode_licenses):
        """
        Return a ScanCode License object built from a DejaCode license
        mapping or None for skipped licenses.
        """
        key = mapping['key']

        # TODO: Not yet available in ScanCode
        is_foreign = key in scancode_licenses.non_english_by_key
        if is_foreign:
            if TRACE: print('Skipping NON-english license:', key)
            return

        # these licenses are rare commercial license with no text and only a
        # link so we ignore these
        dejacode_special_no_text = set([
            'alglib-commercial',
            'atlassian-customer-agreement',
            'dalton-maag-eula',
            'highsoft-standard-license-agreement-4.0',
            'monotype-tou',
            ])
        is_special = key in dejacode_special_no_text
        if is_special:
            if TRACE: print('Skipping special DejaCode license with NO TEXT FOR NOW:', key)
            return

        # these licenses are combos of many others and are ignored: we detect
        # instead each part of the combos separately
        dejacode_special_composites = set([
            'net-snmp',
            'aes-128-3.0',
            'agpl-3.0-bacula',
            'bacula-exception',
            'componentace-jcraft',
            'nvidia-cuda-supplement-2020',
            'dejacode',
            'ibm-icu',
            'unicode-icu-58',
            'info-zip-1997-10',
            'info-zip-2001-01',
            'info-zip-2002-02',
            'info-zip-2003-05',
            'info-zip-2004-05',
            'info-zip-2005-02',
            'info-zip-2007-03',
            'info-zip-2009-01',
            'intel-bsd-special',
            'lgpl-3.0-plus-openssl',
            'newlib-subdirectory',
        ])
        is_combo = key in dejacode_special_composites
        if is_combo:
            if TRACE: print('Skipping DejaCode combo/component license', key)
            return

        deprecated = not mapping.get('is_active')
        if deprecated and key not in scancode_licenses.by_key:
            if TRACE: print('Skipping deprecated license not in ScanCode:', key)
            return

        standard_notice = mapping.get('standard_notice') or ''
        standard_notice = clean_text(standard_notice)

        spdx_license_key = mapping.get('spdx_license_key') or None
        if deprecated:
            spdx_license_key = None
        else:
            if not spdx_license_key:
                spdx_license_key = f'LicenseRef-scancode-{key}'

        lic = License(
            key=key,
            src_dir=self.original_dir,
            name=mapping['name'],
            short_name=mapping['short_name'],
            homepage_url=mapping['homepage_url'],

            category=mapping['category'],
            owner=mapping['owner_name'],

            # FIXME: we may not want to carry notes over???
            # lic.notes = mapping.notes
            spdx_license_key=spdx_license_key,
            text_urls=mapping['text_urls'].splitlines(False),
            osi_url=mapping['osi_url'],
            faq_url=mapping['faq_url'],
            other_urls=mapping['other_urls'].splitlines(False),
            is_exception=mapping.get('is_exception', False),
            is_deprecated=deprecated,
            standard_notice=standard_notice,
        )
        text = mapping['full_text'] or ''
        # normalize EOL to POSIX
        text = text.replace('\r\n', '\n').strip()
        return lic, text