summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Keen <keenerd@gmail.com>2016-04-28 10:24:40 -0400
committerKyle Keen <keenerd@gmail.com>2016-04-28 11:08:49 -0400
commite385ac93a3544acba464ca9d6ea738c19f7e0fc5 (patch)
tree754c619a75171f21938b1a62af3b6a635a49008c
parentd8ee5eb5605d16cedf7b201b5c2c3740f7c5fe7e (diff)
downloadnamcap-e385ac93a3544acba464ca9d6ea738c19f7e0fc5.tar.gz
namcap-e385ac93a3544acba464ca9d6ea738c19f7e0fc5.zip
Restore and refactor accidentally removed tests
This introduces the 'pathdepends' check for an entire class of simple dependency errors. Previously these were mixed together with the .INSTALL tests. Signed-off-by: Kyle Keen <keenerd@gmail.com>
-rw-r--r--Namcap/package.py2
-rw-r--r--Namcap/rules/__init__.py4
-rw-r--r--Namcap/rules/hicoloricons.py30
-rw-r--r--Namcap/rules/mimefiles.py (renamed from Namcap/rules/glibfiles.py)24
-rw-r--r--Namcap/rules/pathdepends.py57
-rw-r--r--Namcap/tests/package/test_hicoloricons.py6
-rw-r--r--Namcap/tests/package/test_mimefiles.py (renamed from Namcap/tests/package/test_glibfiles.py)26
-rw-r--r--Namcap/tests/package/test_pathdepends.py81
-rw-r--r--namcap-tags1
9 files changed, 170 insertions, 61 deletions
diff --git a/Namcap/package.py b/Namcap/package.py
index 308d0ce..ece81b5 100644
--- a/Namcap/package.py
+++ b/Namcap/package.py
@@ -79,7 +79,7 @@ class PacmanPackage(collections.MutableMapping):
# Usual attributes
self.is_split = False
# a dictionary { package => [reasons why it is needed] }
- self.detected_deps = {}
+ self.detected_deps = collections.defaultdict(list)
self._data = {}
# Init from a dictionary
diff --git a/Namcap/rules/__init__.py b/Namcap/rules/__init__.py
index f64b641..7d313f7 100644
--- a/Namcap/rules/__init__.py
+++ b/Namcap/rules/__init__.py
@@ -29,17 +29,17 @@ from . import (
fhs,
filenames,
fileownership,
- glibfiles,
gnomemime,
hardlinks,
- hicoloricons,
infodirectory,
javafiles,
kdeprograms,
libtool,
licensepkg,
lotsofdocs,
+ mimefiles,
missingbackups,
+ pathdepends,
perllocal,
permissions,
py_mtime,
diff --git a/Namcap/rules/hicoloricons.py b/Namcap/rules/hicoloricons.py
deleted file mode 100644
index 653f52b..0000000
--- a/Namcap/rules/hicoloricons.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# namcap rules - hicoloricons
-# Copyright (C) 2009 Abhishek Dasgupta <abhidg@gmail.com>
-#
-# 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
-#
-
-from Namcap.ruleclass import *
-
-class package(TarballRule):
- name = "hicoloricons"
- description = "Checks for hicolor path dependency"
- def analyze(self, pkginfo, tar):
- if "usr/share/icons/hicolor" in tar.getnames():
- reasons = pkginfo.detected_deps.setdefault("hicolor-icon-theme", [])
- reasons.append( ('hicolor-icon-theme-needed-for-hicolor-dir',()) )
-
-# vim: set ts=4 sw=4 noet:
diff --git a/Namcap/rules/glibfiles.py b/Namcap/rules/mimefiles.py
index 16261db..4825867 100644
--- a/Namcap/rules/glibfiles.py
+++ b/Namcap/rules/mimefiles.py
@@ -1,6 +1,6 @@
-# -*- coding: utf-8 -*-
#
-# namcap rules - glibfiles
+# namcap rules - mimefiles
+# Copyright (C) 2009 Hugo Doria <hugo@archlinux.org>
# Copyright (C) 2011 Rémy Oudompheng <remy@archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
@@ -21,15 +21,21 @@
import os
from Namcap.ruleclass import *
-class GlibSchemasRule(TarballRule):
- name = "glibschemas"
- description = "Check for dconf schemas dependency"
+class MimeDesktopRule(TarballRule):
+ name = "mimedesktop"
+ description = "Check for MIME desktop file depends"
def analyze(self, pkginfo, tar):
for entry in tar:
- if ('usr/share/glib-2.0/schemas' in entry.name
- and os.path.basename(entry.name).endswith(".gschema.xml")):
- reasons = pkginfo.detected_deps.setdefault("dconf", [])
- reasons.append( ('dconf-needed-for-glib-schemas',()) )
+ if entry.issym():
+ continue
+ if not entry.name.startswith("usr/share/applications"):
+ continue
+ if not entry.name.endswith(".desktop"):
+ continue
+ with tar.extractfile(entry) as f:
+ if not any(l.startswith(b"MimeType=") for l in f):
+ continue
+ pkginfo.detected_deps["desktop-file-utils"].append( ('desktop-file-utils-needed', ()) )
break
# vim: set ts=4 sw=4 noet:
diff --git a/Namcap/rules/pathdepends.py b/Namcap/rules/pathdepends.py
new file mode 100644
index 0000000..e50a6f6
--- /dev/null
+++ b/Namcap/rules/pathdepends.py
@@ -0,0 +1,57 @@
+#
+# namcap rules - pathdepends
+# Copyright (C) 2016 Kyle Keen <keenerd@gmail.com>
+#
+# 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
+#
+
+"""
+This contains a collection of essentially one-line rules:
+If a certain path is detected then a certain dependency is expected.
+
+Anything fancier than this should get its own rule.
+"""
+
+import os, re
+from Namcap.ruleclass import *
+
+class PathDependsRule(TarballRule):
+ name = "pathdepends"
+ description = "Check for simple implicit path dependencies"
+ # list of path regex, dep name, reason tag
+ subrules = [
+ {'path': '^usr/share/glib-2\.0/schemas$',
+ 'dep':'dconf',
+ 'reason':'dconf-needed-for-glib-schemas'},
+ {'path': '^usr/lib/gio/modules/.*\.so$',
+ 'dep':'glib2',
+ 'reason':'glib2-needed-for-gio-modules'},
+ {'path': '^usr/share/icons/hicolor$',
+ 'dep':'hicolor-icon-theme',
+ 'reason':'hicolor-icon-theme-needed-for-hicolor-dir'},
+ {'path': '^usr/share/mime$',
+ 'dep':'shared-mime-info',
+ 'reason':'shared-mime-info-needed'},
+ ]
+ 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']
+ reason = subrule['reason']
+ pkginfo.detected_deps[dep].append( (reason, ()) )
+
+# vim: set ts=4 sw=4 noet:
diff --git a/Namcap/tests/package/test_hicoloricons.py b/Namcap/tests/package/test_hicoloricons.py
index cc3d9e3..7130e22 100644
--- a/Namcap/tests/package/test_hicoloricons.py
+++ b/Namcap/tests/package/test_hicoloricons.py
@@ -22,7 +22,7 @@
import os
from Namcap.tests.makepkg import MakepkgTest
import Namcap.depends
-import Namcap.rules.hicoloricons
+import Namcap.rules.pathdepends
class HiColorIconsTest(MakepkgTest):
pkgbuild = """
@@ -50,7 +50,7 @@ package() {
self.run_makepkg()
pkg, r = self.run_rule_on_tarball(
os.path.join(self.tmpdir, pkgfile),
- Namcap.rules.hicoloricons.package
+ Namcap.rules.pathdepends.PathDependsRule
)
e, w, i = Namcap.depends.analyze_depends(pkg)
self.assertEqual(pkg.detected_deps, {
@@ -92,7 +92,7 @@ package() {
self.run_makepkg()
pkg, r = self.run_rule_on_tarball(
os.path.join(self.tmpdir, pkgfile),
- Namcap.rules.hicoloricons.package
+ Namcap.rules.pathdepends.PathDependsRule
)
e, w, i = Namcap.depends.analyze_depends(pkg)
self.assertEqual(pkg.detected_deps, {
diff --git a/Namcap/tests/package/test_glibfiles.py b/Namcap/tests/package/test_mimefiles.py
index b9f58b5..bfed439 100644
--- a/Namcap/tests/package/test_glibfiles.py
+++ b/Namcap/tests/package/test_mimefiles.py
@@ -1,6 +1,5 @@
-# -*- coding: utf-8 -*-
#
-# namcap tests - glibfiles
+# namcap tests - mimefiles
# Copyright (C) 2011 Rémy Oudompheng <remy@archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
@@ -21,11 +20,11 @@
import os
from Namcap.tests.makepkg import MakepkgTest
-import Namcap.rules.glibfiles
+import Namcap.rules.mimefiles
-class GlibSchemasTest(MakepkgTest):
+class MimeFilesTest(MakepkgTest):
pkgbuild = """
-pkgname=__namcap_test_glibfiles
+pkgname=__namcap_test_mimefiles
pkgver=1.0
pkgrel=1
pkgdesc="A package"
@@ -39,28 +38,25 @@ build() {
true
}
package() {
- mkdir -p "${pkgdir}/usr/share/glib-2.0/schemas"
- touch "${pkgdir}/usr/share/glib-2.0/schemas/org.test.gschema.xml"
-
- mkdir -p "${pkgdir}/usr/lib/gio/modules"
- touch "${pkgdir}/usr/lib/gio/modules/something.so"
+ mkdir -p "${pkgdir}/usr/share/applications"
+ echo "MimeType=applcation/pdf" > "${pkgdir}/usr/share/applications/foobar.desktop"
}
"""
- def test_glib_schemas_exists(self):
- pkgfile = "__namcap_test_glibfiles-1.0-1-%(arch)s.pkg.tar" % { "arch": self.arch }
+ def test_mimetype_in_desktop(self):
+ "Package with desktop files and an missing dependency"
+ pkgfile = "__namcap_test_mimefiles-1.0-1-%(arch)s.pkg.tar" % { "arch": self.arch }
with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f:
f.write(self.pkgbuild)
self.run_makepkg()
pkg, r = self.run_rule_on_tarball(
os.path.join(self.tmpdir, pkgfile),
- Namcap.rules.glibfiles.GlibSchemasRule
+ Namcap.rules.mimefiles.MimeDesktopRule
)
self.assertEqual(pkg.detected_deps,
- {'dconf': [('dconf-needed-for-glib-schemas', ())] }
+ {"desktop-file-utils": [('desktop-file-utils-needed', ())] }
)
self.assertEqual(r.errors, [])
self.assertEqual(r.warnings, [])
self.assertEqual(r.infos, [])
# vim: set ts=4 sw=4 noet:
-
diff --git a/Namcap/tests/package/test_pathdepends.py b/Namcap/tests/package/test_pathdepends.py
new file mode 100644
index 0000000..48f153c
--- /dev/null
+++ b/Namcap/tests/package/test_pathdepends.py
@@ -0,0 +1,81 @@
+#
+# namcap tests - glibfiles
+# Copyright (C) 2011 Rémy Oudompheng <remy@archlinux.org>
+# Copyright (C) 2016 Kyle Keen <keenerd@gmail.com>
+#
+# 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 os
+from Namcap.tests.makepkg import MakepkgTest
+import Namcap.rules.pathdepends
+
+class PathDependsTest(MakepkgTest):
+ pkgbuild = """
+pkgname=__namcap_test_pathdepends
+pkgver=1.0
+pkgrel=1
+pkgdesc="A package"
+arch=('i686' 'x86_64')
+url="http://www.example.com/"
+license=('GPL')
+depends=('glibc')
+source=()
+options=(!purge !zipman)
+build() {
+ true
+}
+package() {
+ # dconf-needed-for-glib-schemas
+ mkdir -p "${pkgdir}/usr/share/glib-2.0/schemas"
+ touch "${pkgdir}/usr/share/glib-2.0/schemas/org.test.gschema.xml"
+
+ # glib2-needed-for-gio-modules
+ mkdir -p "${pkgdir}/usr/lib/gio/modules"
+ touch "${pkgdir}/usr/lib/gio/modules/something.so"
+
+ # hicolor-icon-theme-needed-for-hicolor-dir
+ mkdir -p "${pkgdir}/usr/share/icons/hicolor/64x64/apps"
+ touch "${pkgdir}/usr/share/icons/hicolor/64x64/apps/example.png"
+
+ # shared-mime-info-needed
+ mkdir -p "${pkgdir}/usr/share/mime/text"
+ touch "${pkgdir}/usr/share/mime/text/example.xml"
+}
+"""
+
+ def test_pathdepends_exists(self):
+ pkgfile = "__namcap_test_pathdepends-1.0-1-%(arch)s.pkg.tar" % { "arch": self.arch }
+ with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f:
+ f.write(self.pkgbuild)
+ self.run_makepkg()
+ pkg, r = self.run_rule_on_tarball(
+ os.path.join(self.tmpdir, pkgfile),
+ Namcap.rules.pathdepends.PathDependsRule
+ )
+ self.assertEqual(pkg.detected_deps,
+ {'dconf': [('dconf-needed-for-glib-schemas', ())],
+ 'glib2': [('glib2-needed-for-gio-modules', ())],
+ 'hicolor-icon-theme': [('hicolor-icon-theme-needed-for-hicolor-dir', ())],
+ 'shared-mime-info': [('shared-mime-info-needed', ())],
+ })
+ self.assertEqual(r.errors, [])
+ self.assertEqual(r.warnings, [])
+ self.assertEqual(r.infos, [])
+
+
+# vim: set ts=4 sw=4 noet:
+
diff --git a/namcap-tags b/namcap-tags
index 5cf938f..1a60e88 100644
--- a/namcap-tags
+++ b/namcap-tags
@@ -13,7 +13,6 @@ backups-preceding-slashes :: Backup entries should not have preceding slashes
cross-dir-hardlink %s %s :: Cross-directory hardlink in package (%s, %s)
dangling-hardlink %s points to %s :: Hard link (%s) points to non-existing %s
dangling-symlink %s points to %s :: Symlink (%s) points to non-existing %s
-desktop-database-not-updated :: Mime type handler found. Add "update-desktop-database -q" to the install file
directory-not-world-executable %s :: Directory (%s) does not have the world executable bit set.
elffile-in-any-package %s :: ELF file ('%s') found in an 'any' package.
elffile-not-in-allowed-dirs %s :: ELF file ('%s') outside of a valid path.