forked from openSUSE/rpmlint-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckIconSizes.py
51 lines (39 loc) · 1.67 KB
/
CheckIconSizes.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
# vim:sw=4:et
#############################################################################
# File : CheckIconSizes.py
# Package : rpmlint
# Author : Dirk Mueller
# Purpose : Check for common scaling errors in icons
#############################################################################
import AbstractCheck
from Filter import printError, addDetails
import re
class IconSizesCheck(AbstractCheck.AbstractCheck):
def __init__(self):
AbstractCheck.AbstractCheck.__init__(self, "CheckIconSizes")
self.file_size_regex = re.compile(r'/icons/[^/]+/(\d+)x(\d+)/')
self.info_size_regex = re.compile(r'(\d+) x (\d+)')
def check(self, pkg):
if pkg.isSource():
return
for fname, pkgfile in pkg.files().items():
if '/animations/' in fname:
continue
res = self.file_size_regex.search(fname)
if res:
sizes = (res.group(1), res.group(2))
res = self.info_size_regex.search(pkgfile.magic)
if res:
actualsizes = (res.group(1), res.group(2))
if abs(int(sizes[0]) - int(actualsizes[0])) > 2 or \
abs(int(sizes[1]) - int(actualsizes[1])) > 2:
printError(pkg, "wrong-icon-size", fname, "expected:",
"x".join(sizes),
"actual:", "x".join(actualsizes))
check = IconSizesCheck()
addDetails(
'wrong-icon-size',
"""Your icon file is installed in a fixed-size directory, but has a
largely incorrect size. Some desktop environments (e.g. GNOME)
display them incorrectly."""
)