summaryrefslogtreecommitdiffstats
path: root/Namcap/rules/pathdepends.py
blob: 5bc4313db9649987227083e1b40a3676d7c0ea02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 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: