commit: 47f880cf6ffa44309dd85e4e54ee5b0cf3043498 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Sun Jan 3 23:09:27 2016 +0000 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> CommitDate: Sat Jan 30 06:33:57 2016 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=47f880cf
repoman: Migrate license checks to a plugin module pym/repoman/checks/ebuilds/variables/license.py | 47 ---------------------- pym/repoman/modules/scan/metadata/__init__.py | 9 +++++ pym/repoman/modules/scan/metadata/license.py | 53 +++++++++++++++++++++++++ pym/repoman/scanner.py | 7 +--- 4 files changed, 63 insertions(+), 53 deletions(-) diff --git a/pym/repoman/checks/ebuilds/variables/license.py b/pym/repoman/checks/ebuilds/variables/license.py deleted file mode 100644 index bdc859c..0000000 --- a/pym/repoman/checks/ebuilds/variables/license.py +++ /dev/null @@ -1,47 +0,0 @@ - -'''description.py -Perform checks on the LICENSE variable. -''' - -# import our initialized portage instance -from repoman._portage import portage - - -class LicenseChecks(object): - '''Perform checks on the LICENSE variable.''' - - def __init__(self, qatracker, liclist, liclist_deprecated): - ''' - @param qatracker: QATracker instance - @param liclist: List of licenses. - @param liclist: List of deprecated licenses. - ''' - self.qatracker = qatracker - self.liclist = liclist - self.liclist_deprecated = liclist_deprecated - - def check( - self, pkg, package, ebuild, y_ebuild): - ''' - @param pkg: Package in which we check (object). - @param package: Package in which we check (string). - @param ebuild: Ebuild which we check (object). - @param y_ebuild: Ebuild which we check (string). - ''' - - # Parse the LICENSE variable, remove USE conditions and flatten it. - licenses = portage.dep.use_reduce( - pkg._metadata["LICENSE"], matchall=1, flat=True) - - # Check each entry to ensure that it exists in ${PORTDIR}/licenses/. - for lic in licenses: - # Need to check for "||" manually as no portage - # function will remove it without removing values. - if lic not in self.liclist and lic != "||": - self.qatracker.add_error( - "LICENSE.invalid", - package + "/" + y_ebuild + ".ebuild: %s" % lic) - elif lic in self.liclist_deprecated: - self.qatracker.add_error( - "LICENSE.deprecated", - "%s: %s" % (ebuild.relative_path, lic)) diff --git a/pym/repoman/modules/scan/metadata/__init__.py b/pym/repoman/modules/scan/metadata/__init__.py index 83aac7f..c8f3609 100644 --- a/pym/repoman/modules/scan/metadata/__init__.py +++ b/pym/repoman/modules/scan/metadata/__init__.py @@ -37,6 +37,15 @@ module_spec = { 'func_desc': { }, }, + 'license-metadata': { + 'name': "license", + 'sourcefile': "license", + 'class': "LicenseChecks", + 'description': doc, + 'functions': ['check'], + 'func_desc': { + }, + }, } } diff --git a/pym/repoman/modules/scan/metadata/license.py b/pym/repoman/modules/scan/metadata/license.py new file mode 100644 index 0000000..b022b20 --- /dev/null +++ b/pym/repoman/modules/scan/metadata/license.py @@ -0,0 +1,53 @@ + +'''license.py +Perform checks on the LICENSE variable. +''' + +# import our initialized portage instance +from repoman._portage import portage + + +class LicenseChecks(object): + '''Perform checks on the LICENSE variable.''' + + def __init__(self, **kwargs): + ''' + @param qatracker: QATracker instance + @param repo_metadata: dictionary of various repository items. + ''' + self.qatracker = kwargs.get('qatracker') + self.repo_metadata = kwargs.get('repo_metadata') + + def check(self, **kwargs): + ''' + @param xpkg: Package in which we check (string). + @param ebuild: Ebuild which we check (object). + @param y_ebuild: Ebuild which we check (string). + ''' + xpkg = kwargs.get('xpkg') + ebuild = kwargs.get('ebuild') + y_ebuild = kwargs.get('y_ebuild') + if not kwargs.get('badlicsyntax'): + # Parse the LICENSE variable, remove USE conditions and flatten it. + licenses = portage.dep.use_reduce( + ebuild.metadata["LICENSE"], matchall=1, flat=True) + + # Check each entry to ensure that it exists in ${PORTDIR}/licenses/. + for lic in licenses: + # Need to check for "||" manually as no portage + # function will remove it without removing values. + if lic not in self.repo_metadata['liclist'] and lic != "||": + self.qatracker.add_error("LICENSE.invalid", + "%s/%s.ebuild: %s" % (xpkg, y_ebuild, lic)) + elif lic in self.repo_metadata['lic_deprecated']: + self.qatracker.add_error("LICENSE.deprecated", + "%s: %s" % (ebuild.relative_path, lic)) + return {'continue': False} + + @property + def runInPkgs(self): + return (False, []) + + @property + def runInEbuilds(self): + return (True, [self.check]) diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py index c8539cb..55f3d56 100644 --- a/pym/repoman/scanner.py +++ b/pym/repoman/scanner.py @@ -18,7 +18,6 @@ from portage import _unicode_encode from portage.dep import Atom from portage.output import green from repoman.checks.ebuilds.checks import run_checks -from repoman.checks.ebuilds.variables.license import LicenseChecks from repoman.checks.ebuilds.variables.restrict import RestrictChecks from repoman.modules.commit import repochecks from repoman.profile import check_profiles, dev_profile_keywords, setup_profile @@ -213,7 +212,6 @@ class Scanner(object): self.modules[mod_class.__name__] = mod_class(**self.kwargs) # initialize our checks classes here before the big xpkg loop - self.licensecheck = LicenseChecks(self.qatracker, liclist, liclist_deprecated) self.restrictcheck = RestrictChecks(self.qatracker) @@ -300,6 +298,7 @@ class Scanner(object): ('description', 'DescriptionChecks'), (None, 'KeywordChecks'), ('arches', 'ArchChecks'), ('depend', 'DependChecks'), ('use_flags', 'USEFlagChecks'), ('ruby', 'RubyEclassChecks'), + ('license', 'LicenseChecks'), ]: if mod[0]: mod_class = MODULE_CONTROLLER.get_class(mod[0]) @@ -327,10 +326,6 @@ class Scanner(object): if y_ebuild_continue: continue - # license checks - if not dynamic_data['badlicsyntax']: - self.licensecheck.check(dynamic_data['pkg'], xpkg, dynamic_data['ebuild'], y_ebuild) - self.restrictcheck.check(dynamic_data['pkg'], xpkg, dynamic_data['ebuild'], y_ebuild) # Syntax Checks