forked from openSUSE/rpmlint-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckExecDocs.py
90 lines (71 loc) · 2.85 KB
/
CheckExecDocs.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# vim:sw=4:et
# ---------------------------------------------------------------
# Module : rpmlint
# File : CheckExecDocs.py
# Author : Stephan Kulow, Dirk Mueller
# Purpose : Check for executable files in %doc
# ---------------------------------------------------------------
import AbstractCheck
import Filter
import stat
def ignore_pkg(name):
if name.startswith('bundle-') or '-devel' in name or '-doc' in name:
return True
return False
def lang_ignore_pkg(name):
if ignore_pkg(name) or '-lang' in name or '-trans' in name:
return True
return False
class ExecDocsCheck(AbstractCheck.AbstractCheck):
def __init__(self):
self.map = []
AbstractCheck.AbstractCheck.__init__(self, "CheckExecDocs")
def check(self, pkg):
if pkg.isSource():
return
files = pkg.files()
complete_size = 0
lang_size = 0
for f, pkgfile in files.items():
if stat.S_ISREG(pkgfile.mode):
complete_size += pkgfile.size
if pkgfile.lang != '':
lang_size += pkgfile.size
doc_size = 0
for f in pkg.docFiles():
if stat.S_ISREG(files[f].mode):
doc_size += files[f].size
if doc_size * 2 >= complete_size and \
doc_size > 100 * 1024 and \
(complete_size - doc_size) * 20 > complete_size and \
not ignore_pkg(pkg.name):
Filter.printWarning(pkg, "package-with-huge-docs",
("%3d%%" % (doc_size * 100 / complete_size)))
if lang_size * 2 >= complete_size \
and lang_size > 100 * 1024 and \
(complete_size - lang_size) * 20 > complete_size and \
not lang_ignore_pkg(pkg.name):
Filter.printWarning(pkg, "package-with-huge-translation",
("%3d%%" % (lang_size * 100 / complete_size)))
for f in pkg.docFiles():
mode = files[f].mode
if not stat.S_ISREG(mode) or not mode & 0o111:
continue
for ext in ['txt', 'gif', 'jpg', 'html',
'pdf', 'ps', 'pdf.gz', 'ps.gz']:
if f.endswith("." + ext):
Filter.printError(pkg, 'executable-docs', f)
for name in ['README', 'NEWS', 'COPYING', 'AUTHORS']:
if f.endswith("/" + name):
Filter.printError(pkg, 'executable-docs', f)
check = ExecDocsCheck()
Filter.addDetails(
'executable-docs',
"Documentation should not be executable.",
'package-with-huge-docs',
"""More than half the size of your package is documentation.
Consider splitting it into a -doc subpackage.""",
'package-with-huge-translation',
"""More than half the size of your package is language-specific.
Consider splitting it into a -lang subpackage."""
)