File: DistributionCheck.py

package info (click to toggle)
rpmlint 1.9-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 22,212 kB
  • ctags: 722
  • sloc: python: 14,926; makefile: 63; sh: 49
file content (83 lines) | stat: -rw-r--r-- 3,161 bytes parent folder | download
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
# -*- coding: utf-8 -*-
#############################################################################
# File          : DistributionCheck.py
# Package       : rpmlint
# Author        : Frederic Lepied
# Created on    : Tue Sep 28 00:05:33 1999
# Purpose       : check the Distribution specificities in a binary rpm package.
#############################################################################

import re

import rpm

import AbstractCheck
import Config
from Filter import addDetails, printWarning


man_regex = re.compile("/man(?:\d[px]?|n)/")
info_regex = re.compile("(/usr/share|/usr)/info/")
vendor = Config.getOption("Vendor")
distribution = Config.getOption("Distribution")
compress_ext = Config.getOption("CompressExtension", "bz2")


class DistributionCheck(AbstractCheck.AbstractCheck):

    def __init__(self):
        AbstractCheck.AbstractCheck.__init__(self, "DistributionCheck")

    def check_binary(self, pkg):
        if vendor and pkg[rpm.RPMTAG_VENDOR] != vendor:
            printWarning(pkg, "invalid-vendor", pkg[rpm.RPMTAG_VENDOR])

        if distribution and pkg[rpm.RPMTAG_DISTRIBUTION] != distribution:
            printWarning(pkg, "invalid-distribution",
                         pkg[rpm.RPMTAG_DISTRIBUTION])

        if compress_ext:
            for fname in pkg.files():
                if man_regex.search(fname):
                    if not fname.endswith(compress_ext):
                        printWarning(pkg, 'manpage-not-compressed',
                                     compress_ext, fname)
                elif info_regex.search(fname) and \
                        not fname.endswith("/info/dir"):
                    if not fname.endswith(compress_ext):
                        printWarning(pkg, 'infopage-not-compressed',
                                     compress_ext, fname)


# Create an object to enable the auto registration of the test
check = DistributionCheck()

addDetails(
'invalid-vendor',
'In the "%s" distribution, vendor should be "%s".' % (distribution, vendor),

'invalid-distribution',
'The distribution value should be "' + distribution + '".',

'manpage-not-compressed',
'''This manual page is not compressed with the %s compression method
(does not have the %s extension). If the compression does not happen
automatically when the package is rebuilt, make sure that you have the
appropriate rpm helper and/or config packages for your target distribution
installed and try rebuilding again; if it still does not happen automatically,
you can compress this file in the %%install section of the spec file.'''
% (compress_ext, compress_ext),

'infopage-not-compressed',
'''This info page is not compressed with the %s compression method
(does not have the %s extension). If the compression does not happen
automatically when the package is rebuilt, make sure that you have the
appropriate rpm helper and/or config packages for your target distribution
installed and try rebuilding again; if it still does not happen automatically,
you can compress this file in the %%install section of the spec file.'''
% (compress_ext, compress_ext),
)

# DistributionCheck.py ends here

# ex: ts=4 sw=4 et