diff --git a/Namcap/rules/__init__.py b/Namcap/rules/__init__.py index 1e05326..525dbc6 100644 --- a/Namcap/rules/__init__.py +++ b/Namcap/rules/__init__.py @@ -31,6 +31,7 @@ from . import ( fileownership, gnomemime, hardlinks, + hookdepends, infodirectory, javafiles, kdeprograms, diff --git a/Namcap/rules/hookdepends.py b/Namcap/rules/hookdepends.py new file mode 100644 index 0000000..dcf03a1 --- /dev/null +++ b/Namcap/rules/hookdepends.py @@ -0,0 +1,48 @@ +# +# namcap rules - hookdepends +# Copyright (C) 2019 Eli Schwartz +# Copyright (C) 2016 Kyle Keen +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import re +from Namcap.ruleclass import * + +class HookDependsRule(TarballRule): + name = "hookdepends" + description = "Check for redundant hook dependencies" + subrules = [ + { + 'path': '^usr/share/applications/.*\.desktop$', + 'dep': 'desktop-file-utils', + }, + { + 'path': '^usr/share/mime$', + 'dep': 'shared-mime-info', + } + ] + def analyze(self, pkginfo, tar): + names = [entry.name for entry in tar] + for subrule in self.subrules: + pattern = re.compile(subrule['path']) + if any(pattern.search(n) for n in names): + dep = subrule['dep'] + if dep in pkginfo['depends']: + self.warnings = [('external-hooks-unneeded-warning', ())] + self.infos.append(('external-hooks-unneeded-name %s', dep)) + + +# vim: set ts=4 sw=4 noet: diff --git a/namcap-tags b/namcap-tags index 17b9506..84cc3f7 100644 --- a/namcap-tags +++ b/namcap-tags @@ -1,11 +1,11 @@ # namcap tags file -# The tags file consists of lines specifying the human readable form of the -# hyphenated tags used in the namcap code. A line beginning with a '#' is +# The tags file consists of lines specifying the human readable form of the +# hyphenated tags used in the namcap code. A line beginning with a '#' is # treated as a comment. Otherwise the format of the file is: # # machine-parseable-tag %s :: This is machine parseable tag %s # -# Note that a double colon (::) is used to separate the hyphenated tag from the +# Note that a double colon (::) is used to separate the hyphenated tag from the # human readable description. # rules tags @@ -26,6 +26,8 @@ empty-directory %s :: Directory (%s) is empty error-running-rule %s :: Error running rule '%s' external-hooks-name %s :: .INSTALL file runs a command (%s) provided by hooks. external-hooks-warning :: .INSTALL file runs a command provided by hooks. +external-hooks-unneeded-name %s :: unneeded dependency on a package (%s) run when needed by hooks. +external-hooks-unneeded-warning :: unneeded dependency on a package run when needed by hooks. extra-var-begins-without-underscore %s :: Non standard variable '%s' doesn't start with an underscore file-in-non-standard-dir %s :: File (%s) exists in a non-standard directory. file-in-temporary-dir %s :: File (%s) is in a temporary directory.