diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2022-05-27 17:47:15 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2022-06-07 18:16:54 +0300 |
commit | dd860396f2fa459872360704626443ecab000d48 (patch) | |
tree | b50cc17fa53fa087f6582bc266c9d80188fcd6ea | |
parent | f4e788e17bce36b1b4658646728fb877463c32f4 (diff) |
Extend fix-missing-src-hint-info for license:
-rw-r--r-- | .flake8 | 2 | ||||
-rw-r--r-- | calm/fix-missing-src-hint-info.py | 10 | ||||
-rw-r--r-- | calm/fixes.py | 101 |
3 files changed, 92 insertions, 21 deletions
@@ -1,3 +1,5 @@ [flake8] ignore=E741,E129,W504,A003,B020,B902 max-line-length=240 +per-file-ignores = + calm/fixes.py:E241,E127 diff --git a/calm/fix-missing-src-hint-info.py b/calm/fix-missing-src-hint-info.py index 88142a6..3185083 100644 --- a/calm/fix-missing-src-hint-info.py +++ b/calm/fix-missing-src-hint-info.py @@ -32,7 +32,7 @@ from . import common_constants from . import fixes -def fix_hints(relarea, packages): +def fix_hints(relarea, packages, fixids): for (dirpath, _subdirs, files) in os.walk(relarea): # only apply to listed packages, if specified @@ -50,7 +50,7 @@ def fix_hints(relarea, packages): logging.error('hint %s missing' % hf) continue - fixes.fix_hint(dirpath, hf, f, ['homepage']) + fixes.fix_hint(dirpath, hf, f, fixids) # @@ -62,6 +62,7 @@ def main(): parser = argparse.ArgumentParser(description='src hint improver') parser.add_argument('package', nargs='*', metavar='PACKAGE') + parser.add_argument('--fix', action='append', help='ids of fixes to perform') parser.add_argument('-v', '--verbose', action='count', dest='verbose', help='verbose output', default=0) parser.add_argument('--releasearea', action='store', metavar='DIR', help="release directory (default: " + relarea_default + ")", default=relarea_default, dest='relarea') (args) = parser.parse_args() @@ -69,9 +70,12 @@ def main(): if args.verbose: logging.getLogger().setLevel(logging.INFO) + if not args.fix: + args.fix = ['homepage', 'license'] + logging.basicConfig(format=os.path.basename(sys.argv[0]) + ': %(message)s') - fix_hints(args.relarea, args.package) + fix_hints(args.relarea, args.package, args.fix) # diff --git a/calm/fixes.py b/calm/fixes.py index 796805a..e7f8146 100644 --- a/calm/fixes.py +++ b/calm/fixes.py @@ -63,6 +63,29 @@ def read_cygport(dirpath, tf): return content +def _parse_cygport_var(dirpath, tf, var): + # crack open corresponding -src.tar and parse var out from .cygport + logging.debug('examining %s' % tf) + content = read_cygport(dirpath, tf) + + value = None + if content: + for l in content.splitlines(): + match = re.match(r'^\s*' + var + r'\s*=\s*("|)([^"].*)\1', l) + if match: + if value: + logging.warning('multiple %s lines in .cygport in srcpkg %s' % (var, tf)) + pn = os.path.basename(dirpath) + value = match.group(2) + value = re.sub(r'\$({|)(PN|ORIG_PN|NAME)(}|)', pn, value) + + if value and '$' in value: + logging.warning('unknown shell parameter expansions in %s="%s" in .cygport in srcpkg %s' % (var, value, tf)) + value = None + + return value + + class NoRedirection(urllib.request.HTTPErrorProcessor): def http_response(self, request, response): return response @@ -89,24 +112,7 @@ def _fix_homepage_src_hint(hints, dirpath, _hf, tf): if 'homepage' in hints: homepage = hints['homepage'] else: - # crack open corresponding -src.tar and parse homepage out from .cygport - logging.debug('examining %s' % tf) - content = read_cygport(dirpath, tf) - - homepage = None - if content: - for l in content.splitlines(): - match = re.match(r'^\s*HOMEPAGE\s*=\s*("|)([^"].*)\1', l) - if match: - if homepage: - logging.warning('multiple HOMEPAGE lines in .cygport in srcpkg %s', tf) - pn = os.path.basename(dirpath) - homepage = match.group(2) - homepage = re.sub(r'\$({|)(PN|ORIG_PN|NAME)(}|)', pn, homepage) - - if homepage and '$' in homepage: - logging.warning('unknown shell parameter expansions in HOMEPAGE="%s" in .cygport in srcpkg %s' % (homepage, tf)) - homepage = None + homepage = _parse_cygport_var(dirpath, tf, 'HOMEPAGE') if not homepage: logging.info('cannot determine homepage: from srcpkg %s' % tf) @@ -139,6 +145,63 @@ def _fix_homepage_src_hint(hints, dirpath, _hf, tf): return False +# for specific packages, map some human-readable license texts to SPDX expressions +licmap = [ + ('Apache License, Version 2', 'Apache-2.0', ['meson', 'ninja']), + ('BSD 3-Clause', 'BSD-3-Clause', ['libsolv', 'mingw64-i686-libsolv', 'mingw64-x86_64-libsolv']), + ('BSD3/GPLv2+', 'BSD-3-Clause AND GPL-2.0-or-later', ['dash']), + ('CC BY-SA 3.0', 'CC-BY-SA-3.0', ['dmalloc']), + ('GNU General Public License, Version 2', 'GPL-2.0-only', ['buildbot-slave', 'buildbot-worker']), + ('GNU General Public License, Version 3', 'GPL-3.0-or-later', ['osslsigncode']), + ('GPL', 'GPL-2.0-or-later', ['cpuid']), + ('GPL', 'GPL-3.0-or-later', ['units']), + ('GPLv2+', 'GPL-2.0-or-later', ['grep', 'gzip', 'readline']), + ('GPLv2+FontEmbExc/OFL-1.1', 'GPL-2.0-or-later WITH Font-exception-2.0 OR OFL-1.1', + ['unifont']), + ('GPLv3+', 'GPL-3.0-or-later', ['bison', 'wget']), + ('LGPLv2.1+/GPLv2+', 'LGPL-2.1-or-later AND GPL-2.0-or-later', ['libgcrypt']), + ('LGPLv3+/GPLv2+/GPLv3+/LGPLv2+', '(LGPL-3.0-or-later OR GPL-2.0-or-later) AND GPL-3.0-or-later', + ['libidn', 'mingw64-i686-libidn', 'mingw64-x86_64-libidn']), + ('LGPLv3+/GPLv2+/GPLv3+/Unicode2016', '(LGPL-3.0-or-later OR GPL-2.0-or-later) AND GPL-3.0-or-later AND Unicode-DFS-2016', + ['libidn2', 'mingw64-i686-libidn2', 'mingw64-x86_64-libidn2']), + ('MIT License', 'MIT', ['python-future']), + ('MIT-like', 'curl', ['curl', 'mingw64-i686-curl', 'mingw64-x86_64-curl']), + ('MIT-like', 'Linux-man-pages-copyleft', ['man-pages-linux', 'man-pages-posix']), + ('MIT-like', 'BSD-Source-Code', ['vttest']), + ('Public domain', 'BSD-3-Clause AND Public-Domain', ['tzdata', 'tzcode']), + ('SGI Free Software License B', 'SGI-B-2.0', ['khronos-opengl-registry']), + ('Sun OpenLook', 'XVIEW', ['xview']), +] + + +def _fix_license_src_hint(hints, dirpath, _hf, tf): + # already present? + if 'license' in hints: + lic = hints['license'] + else: + lic = _parse_cygport_var(dirpath, tf, 'LICENSE') + + if not lic: + logging.info('cannot determine license: from srcpkg %s' % tf) + return False + + pn = dirpath.split(os.path.sep)[-1] + for (human, spdx, pl) in licmap: + if (pn in pl) and (lic.lower() == human.lower()): + lic = spdx + logging.info("converted license text '%s' to SPDX license expression '%s'" % (human, spdx)) + break + + logging.info('adding license:%s to hints for srcpkg %s' % (lic, tf)) + + # changed? + if lic != hints.get('license', None): + hints['license'] = lic + return True + + return False + + def _fix_invalid_keys_hint(hints, _dirpath, hf, _tf): # eliminate keys that aren't appropriate to the package type if hf.endswith('-src.hint'): @@ -170,6 +233,8 @@ def fix_hint(dirpath, hf, tf, problems): changed = _fix_homepage_src_hint(hints, dirpath, hf, tf) if 'invalid_keys' in problems: changed = _fix_invalid_keys_hint(hints, dirpath, hf, tf) or changed + if 'license' in problems: + changed = _fix_license_src_hint(hints, dirpath, hf, tf) or changed # write updated hints if changed: |