diff options
-rw-r--r-- | LicenseCheck.py | 80 | ||||
-rw-r--r-- | packaging/config | 2 | ||||
-rw-r--r-- | packaging/rpmlint.spec | 4 |
3 files changed, 83 insertions, 3 deletions
diff --git a/LicenseCheck.py b/LicenseCheck.py new file mode 100644 index 0000000..88a2b77 --- /dev/null +++ b/LicenseCheck.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# Version : $Id$ + +# +# check license files and verify them against declared license in License tag +# + +from Filter import addDetails, printError, printWarning +from Pkg import getstatusoutput, is_utf8 +import AbstractCheck +import os +import stat +import Config +import rpm +import re + +DEFAULT_VALID_LICENSES = () +VALID_LICENSES = Config.getOption('ValidLicenses', DEFAULT_VALID_LICENSES) +license_regex = re.compile('\(([^)]+)\)|\s(?:and|or)\s') + + +class LicenseCheck(AbstractCheck.AbstractFilesCheck): + def __init__(self): + AbstractCheck.AbstractCheck.__init__( + self, "LicenseCheck") + + def __checkLicenseFiles(self, pkg): + for fname, pkgfile in pkg.files().items(): + if not fname.startswith('/usr/share/licenses/'): + continue + + if not stat.S_ISREG(pkgfile.mode): + continue + + basename = os.path.basename(fname) + st = getstatusoutput(('nomos', pkgfile.path), True) + print st + def split_license(license): + return (x.strip() for x in + (l for l in license_regex.split(license) if l)) + + if st[0]: + for line in st[1].splitlines(): + if 'license(s)' in line: + licenses = line.split('license(s) ')[1].split(",") + rpm_license = pkg[rpm.RPMTAG_LICENSE] + if not rpm_license: + continue + else: + if rpm_license not in VALID_LICENSES: + for l1 in split_license(rpm_license): + if l1 in VALID_LICENSES and l1 == licenses[0]: + continue + sp = split_license(l1) + if sp != licenses: + printWarning(pkg, 'licenses-do-not-match', sp, licenses) + + + + def check(self, pkg): + + if pkg.isSource() or not pkg.licenseFiles(): + return + + self.__checkLicenseFiles(pkg) + +check = LicenseCheck() + +addDetails( +'licenses-do-not-match', +'''Licenses do not match.''', +'wrong-number-of-licenses', +'''Number of licenses do not match.''', +) + +# Local variables: +# indent-tabs-mode: nil +# py-indent-offset: 4 +# End: +# ex: ts=4 sw=4 et diff --git a/packaging/config b/packaging/config index 9489e73..1930417 100644 --- a/packaging/config +++ b/packaging/config @@ -18,6 +18,8 @@ allChecks() addCheck("CheckBuildRoot") addCheck("CheckExecDocs") +addCheck("LicenseCheck") +addCheck("DocFilesCheck") addCheck("CheckPkgConfig") addCheck("CheckCommonFiles") #addCheck("CheckInitScripts") diff --git a/packaging/rpmlint.spec b/packaging/rpmlint.spec index f902f9b..acfbdef 100644 --- a/packaging/rpmlint.spec +++ b/packaging/rpmlint.spec @@ -5,7 +5,7 @@ Summary: Rpm correctness checker License: GPL-2.0+ Group: System/Packages Version: 1.4 -Release: 0 +Release: 100 Source0: http://rpmlint.zarb.org/download/rpmlint-%{version}.tar.bz2 Source1: rpmlint-checks-master.tar.gz Source2: config @@ -51,8 +51,6 @@ python -tt %{SOURCE100} $RPM_BUILD_ROOT/usr/share/rpmlint/*.py $RPM_BUILD_ROOT/u %__install -m 644 %{SOURCE11} %{buildroot}/%{_sysconfdir}/rpmlint/ %__install -m 644 %{SOURCE12} %{buildroot}/%{_sysconfdir}/rpmlint/ -%clean -rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root,0755) |