handle %license
[platform/upstream/rpmlint.git] / MenuXDGCheck.py
1 # -*- coding: utf-8 -*-
2 # Version         : $Id$
3
4 #
5 # check xdg file format violation
6 #
7 # http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
8 #
9
10 from Filter import addDetails, printError
11 from Pkg import getstatusoutput, is_utf8
12 import AbstractCheck
13
14
15 class MenuXDGCheck(AbstractCheck.AbstractFilesCheck):
16     def __init__(self):
17         # desktop file need to be in $XDG_DATA_DIRS
18         # $ echo $XDG_DATA_DIRS/applications
19         # /var/lib/menu-xdg:/usr/share
20         AbstractCheck.AbstractFilesCheck.__init__(
21                 self, "MenuXDGCheck", "(?:/usr/share|/etc/opt/.*/share|/opt/.*)/applications/.*\.desktop$")
22
23     def check_file(self, pkg, filename):
24         f = pkg.dirName() + filename
25         st = getstatusoutput(('desktop-file-validate', f), True)
26         if st[0]:
27             error_printed = False
28             for line in st[1].splitlines():
29                 if 'error: ' in line:
30                     printError(pkg, 'invalid-desktopfile', filename,
31                                line.split('error: ')[1])
32                     error_printed = True
33             if not error_printed:
34                 printError(pkg, 'invalid-desktopfile', filename)
35         if not is_utf8(f):
36             printError(pkg, 'non-utf8-desktopfile', filename)
37
38
39 check = MenuXDGCheck()
40
41 addDetails(
42 'invalid-desktopfile',
43 '''.desktop file is not valid, check with desktop-file-validate''',
44
45 'non-utf8-desktopfile',
46 '''.desktop file is not encoded in UTF-8''',
47 )
48
49 # Local variables:
50 # indent-tabs-mode: nil
51 # py-indent-offset: 4
52 # End:
53 # ex: ts=4 sw=4 et