add Development Groups
[platform/upstream/rpmlint.git] / DistributionCheck.py
1 # -*- coding: utf-8 -*-
2 #############################################################################
3 # File          : DistributionCheck.py
4 # Package       : rpmlint
5 # Author        : Frederic Lepied
6 # Created on    : Tue Sep 28 00:05:33 1999
7 # Version       : $Id: DistributionCheck.py 1732 2010-02-21 11:28:42Z scop $
8 # Purpose       : check the Distribution specificities in a binary rpm package.
9 #############################################################################
10
11 import re
12
13 import rpm
14
15 from Filter import addDetails, printWarning
16 import AbstractCheck
17 import Config
18
19
20 man_regex = re.compile("/man(?:\d[px]?|n)/")
21 info_regex = re.compile("(/usr/share|/usr)/info/")
22 vendor = Config.getOption("Vendor")
23 distribution = Config.getOption("Distribution")
24 compress_ext = Config.getOption("CompressExtension", "bz2")
25
26 class DistributionCheck(AbstractCheck.AbstractCheck):
27
28
29     def __init__(self):
30         AbstractCheck.AbstractCheck.__init__(self, "DistributionCheck")
31
32     def check(self, pkg):
33         # Check only binary package
34         if pkg.isSource():
35             return
36
37         if vendor and pkg[rpm.RPMTAG_VENDOR] != vendor:
38             printWarning(pkg, "invalid-vendor", pkg[rpm.RPMTAG_VENDOR])
39
40         if distribution and pkg[rpm.RPMTAG_DISTRIBUTION] != distribution:
41             printWarning(pkg, "invalid-distribution",
42                          pkg[rpm.RPMTAG_DISTRIBUTION])
43
44         if compress_ext:
45             for fname in pkg.files():
46                 if man_regex.search(fname):
47                     if not fname.endswith(compress_ext):
48                         printWarning(pkg, 'manpage-not-compressed',
49                                      compress_ext, fname)
50                 elif info_regex.search(fname) and \
51                         not fname.endswith("/info/dir"):
52                     if not fname.endswith(compress_ext):
53                         printWarning(pkg, 'infopage-not-compressed',
54                                      compress_ext, fname)
55
56
57 # Create an object to enable the auto registration of the test
58 check = DistributionCheck()
59
60 addDetails(
61 'invalid-vendor',
62 '''In the "%s" distribution, vendor should be "%s".''' % (distribution, vendor),
63
64 'invalid-distribution',
65 'The distribution value should be "' + distribution + '".',
66
67 'manpage-not-compressed',
68 '''This manual page is not compressed with the %s compression method
69 (does not have the %s extension). If the compression does not happen
70 automatically when the package is rebuilt, make sure that you have the
71 appropriate rpm helper and/or config packages for your target distribution
72 installed and try rebuilding again; if it still does not happen automatically,
73 you can compress this file in the %%install section of the spec file.''' \
74 % (compress_ext, compress_ext),
75
76 'infopage-not-compressed',
77 '''This info page is not compressed with the %s compression method
78 (does not have the %s extension). If the compression does not happen
79 automatically when the package is rebuilt, make sure that you have the
80 appropriate rpm helper and/or config packages for your target distribution
81 installed and try rebuilding again; if it still does not happen automatically,
82 you can compress this file in the %%install section of the spec file.''' \
83 % (compress_ext, compress_ext),
84 )
85
86 # DistributionCheck.py ends here
87
88 # Local variables:
89 # indent-tabs-mode: nil
90 # py-indent-offset: 4
91 # End:
92 # ex: ts=4 sw=4 et