stricter-interpreter-check.diff
[platform/upstream/rpmlint.git] / DocFilesCheck.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; version 2 of the License.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16
17 import rpm
18
19 from Filter import addDetails, printWarning
20 import AbstractCheck
21
22
23 class DocFilesCheck(AbstractCheck.AbstractCheck):
24     def __init__(self):
25         AbstractCheck.AbstractCheck.__init__(self, 'DocFilesCheck')
26
27     def __checkRequirements(self, pkg):
28
29         doc_files = pkg.docFiles()
30         files = pkg.files()
31
32         reqs = {}
33         for fname, pkgfile in files.items():
34             reqs[fname] = [x[0] for x in pkgfile.requires]
35
36         core_reqs = {}  # dependencies of non-doc files
37         doc_reqs  = {}  # dependencies of doc files
38
39         for dep in pkg.header.dsFromHeader():
40             # skip deps which were found by find-requires
41             if dep.Flags() & rpm.RPMSENSE_FIND_REQUIRES != 0:
42                 continue
43             core_reqs[dep.N()] = []
44
45         # register things which are provided by the package
46         for i in pkg.header[rpm.RPMTAG_PROVIDES] + files.keys():
47             core_reqs[i] = []
48
49         for i in files:
50             if not reqs[i]:
51                 continue # skip empty dependencies
52             if i in doc_files:
53                 target = doc_reqs
54             else:
55                 target = core_reqs
56
57             for r in reqs[i]:
58                 if r not in target:
59                     target[r] = []
60                 target[r].append(i)
61
62         # go through the calculated requirements of the %doc files
63         for (dep, req_files) in doc_reqs.items():
64             if dep not in core_reqs:
65                 for f in req_files:
66                     printWarning(pkg, "doc-file-dependency", f, dep)
67
68     def __checkUnwantedFiles(self, pkg):
69
70         for docfile in pkg.docFiles():
71             if docfile.endswith("/INSTALL"):
72                 printWarning(pkg, "install-file-in-docs", docfile)
73
74     def check(self, pkg):
75
76         if pkg.isSource() or not pkg.docFiles():
77             return
78
79         self.__checkRequirements(pkg)
80         self.__checkUnwantedFiles(pkg)
81
82
83 check = DocFilesCheck()
84
85 addDetails(
86 'doc-file-dependency',
87 '''An included file marked as %doc creates a possible additional dependency in
88 the package.  Usually, this is not wanted and may be caused by eg. example
89 scripts with executable bits set included in the package's documentation.''',
90
91 'install-file-in-docs',
92 '''A file whose name suggests that it contains installation instructions is
93 included in the package.  Such instructions are often not relevant for already
94 installed packages; if this is the case for this file and it does not contain
95 any information that is of interest after the package has been built and
96 installed, do not include the file in the binary package.''',
97 )
98
99 # DocFilesCheck.py ends here
100
101 # Local variables:
102 # indent-tabs-mode: nil
103 # py-indent-offset: 4
104 # End:
105 # ex: ts=4 sw=4 et