コード例 #1
0
def replace_full_license(para):
    license = para.license
    license_matched = find_common_license_from_fulltext(license.text)
    if license_matched is None:
        if os.path.exists(os.path.join(COMMON_LICENSES_DIR, license.synopsis)):
            warn('A common license shortname (%s) is used, but license '
                 'text not recognized.' % license.synopsis)
        return
    # The full license text was found. Replace it with a blurb.
    canonical_id = canonical_license_id(license.synopsis)
    for shortname, blurb in _BLURB.items():
        if canonical_id == canonical_license_id(shortname):
            break
    else:
        if license.synopsis in SPDX_RENAMES:
            renames[license.synopsis] = SPDX_RENAMES[license.synopsis]
            return
        else:
            warn('Found full license text for %s, but unknown synopsis %s (%s)'
                 % (license_matched, license.synopsis, canonical_id))
        return
    if license_matched == 'Apache-2.0':
        fixed_lintian_tag('source',
                          'copyright-file-contains-full-apache-2-license',
                          info=())
    if license_matched.startswith('GFDL-'):
        fixed_lintian_tag('source',
                          'copyright-file-contains-full-gfdl-license',
                          info=())
    if license_matched.startswith('GPL-'):
        fixed_lintian_tag('source',
                          'copyright-file-contains-full-gpl-license',
                          info=())
    para.license = License(license.synopsis, blurb)
    return license_matched
コード例 #2
0
def fix_shortname(copyright):
    for paragraph in copyright.all_paragraphs():
        if paragraph.license is None:
            continue
        try:
            new_name = typos[paragraph.license.synopsis]
        except KeyError:
            continue
        issue = LintianIssue('source',
                             'invalid-short-name-in-dep5-copyright',
                             info=paragraph.license.synopsis)
        if issue.should_fix():
            renames[paragraph.license.synopsis] = new_name
            paragraph.license = License(new_name, paragraph.license.text)
            issue.report_fixed()
コード例 #3
0
def fix_spaces(copyright):
    for paragraph in copyright.all_paragraphs():
        if not paragraph.license:
            continue
        if ' ' not in paragraph.license.synopsis:
            continue
        ors = paragraph.license.synopsis.replace(' | ', ' or ').split(' or ')
        names = []
        for name in ors:
            if name.lower() in RENAMES:
                name = RENAMES[name.lower()]
            elif name.replace(' ', '-').lower() in REPLACE_SPACES:
                name = name.replace(' ', '-')
            names.append(name)
        newsynopsis = ' or '.join(names)
        if newsynopsis != paragraph.license.synopsis:
            fixed_lintian_tag('source',
                              'space-in-std-shortname-in-dep5-copyright',
                              '%s (line XX)' % paragraph.license.synopsis)
            paragraph.license = License(newsynopsis, paragraph.license.text)
コード例 #4
0
def reference_common_license(para):
    license = para.license
    common_license = find_common_license_from_blurb(license.text)
    if not common_license:
        return
    if COMMON_LICENSES_DIR in license.text:
        return
    if para.comment is not None and COMMON_LICENSES_DIR in para.comment:
        return
    if 'X-Comment' in para and COMMON_LICENSES_DIR in para['X-Comment']:
        return
    if 'License-Reference' in para:
        return
    para.license = License(
        license.synopsis, license.text + '\n\n' + debian_file_reference(
            FULL_LICENSE_NAME.get(common_license, common_license),
            common_license))
    if common_license in ('Apache-2.0', 'Apache-2'):
        fixed_lintian_tag('source',
                          'copyright-not-using-common-license-for-apache2',
                          info=())
    elif common_license.startswith('GPL-'):
        fixed_lintian_tag('source',
                          'copyright-not-using-common-license-for-gpl',
                          info=())
    elif common_license.startswith('LGPL-'):
        fixed_lintian_tag('source',
                          'copyright-not-using-common-license-for-lgpl',
                          info=())
    elif common_license.startswith('GFDL-'):
        fixed_lintian_tag('source',
                          'copyright-not-using-common-license-for-gfdl',
                          info=())
    fixed_lintian_tag('source',
                      'copyright-does-not-refer-to-common-license-file',
                      info=())
    if license.synopsis != common_license:
        renames[license.synopsis] = common_license
    return common_license
コード例 #5
0
    if not group.copyright_block_valid():
        continue

    licenses.update(group.licenses.keys())

    if options.glob:
        files = group.files.get_patterns()
    else:
        files = group.files.sorted_members()

    if group.copyrights:
        holders = '\n           '.join(group.copyrights.sorted_members())
    else:
        holders = 'Unknown'
    paragraph = FilesParagraph.create(list(files), holders,
                                      License(group.license))

    comments = group.get_comments()
    if comments:
        paragraph.comment = comments

    c.add_files_paragraph(paragraph)

# Print license paragraphs
for key in sorted(licenses):
    license_ = DecopyLicense.get(key)
    paragraph = LicenseParagraph.create(License(license_.name))
    paragraph.comment = "Add the corresponding license text here"
    c.add_license_paragraph(paragraph)

with open('debian/copyright', 'w') as f:
コード例 #6
0
        return path
    if not newpath.startswith(path + '-'):
        return path
    updated.add(synopsis)
    if waslink:
        fixed_lintian_tag('all',
                          'copyright-refers-to-symlink-license',
                          info=path.lstrip('/'))
    fixed_lintian_tag('all',
                      'copyright-refers-to-versionless-license-file',
                      info=path.lstrip('/'))
    return newpath


try:
    with CopyrightEditor() as updater:
        for para in updater.copyright.all_paragraphs():
            license = para.license
            if not license or not license.text:
                continue
            changed_text = re.sub(
                '/usr/share/common-licenses/([A-Za-z0-9-.]+)',
                partial(replace_symlink_path, license.synopsis), license.text)
            if changed_text != license.text:
                para.license = License(license.synopsis, changed_text)
except (FileNotFoundError, NotMachineReadableError):
    pass

report_result('Refer to specific version of license %s.' %
              ', '.join(sorted(updated)))
コード例 #7
0
            if not license or not license.text:
                continue
            replaced_license = replace_full_license(para)
            if replaced_license:
                updated.add(replaced_license)
            replaced_license = reference_common_license(para)
            if replaced_license:
                updated.add(replaced_license)
        for paragraph in updater.copyright.all_paragraphs():
            if not paragraph.license or not paragraph.license.synopsis:
                continue
            try:
                newsynopsis = renames[paragraph.license.synopsis]
            except KeyError:
                continue
            paragraph.license = License(newsynopsis, paragraph.license.text)
except (NotMachineReadableError, FileNotFoundError):
    pass

done = []
if updated:
    done.append('refer to common license file for %s' %
                ', '.join(sorted(updated)))
if set(renames.values()) - set(updated):
    done.append('use common license names: ' + ', '.join([
        '%s (was: %s)' % (new, old)
        for (old, new) in sorted(renames.items()) if new not in updated
    ]))

if done:
    report_result(done[0][0].capitalize() + ('; '.join(done) + '.')[1:])