summaryrefslogtreecommitdiff
path: root/rpmlint-checks-master/CheckBuildDate.py
blob: 73d025b79c8433d708ac193e6a0ca3c1db798a3a (plain)
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
#############################################################################
# File          : CheckBuilDate.py
# Package       : rpmlint
# Author        : Cristian Rodriguez
# Purpose       : Check for binaries containing build date
#############################################################################

from Filter import *
import AbstractCheck
import rpm
import re
import os
import commands
import Config
import stat
import time

class BuildDateCheck(AbstractCheck.AbstractFilesCheck):
    def __init__(self):
        AbstractCheck.AbstractFilesCheck.__init__(self, "CheckBuildDate", ".*")
        self.looksliketime = re.compile('(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])')
        self.istoday = re.compile(time.strftime("%b %e %Y"))

    def check_file(self, pkg, filename):
        if filename.startswith('/usr/lib/debug') or pkg.isSource():
            return

        if not stat.S_ISREG(pkg.files()[filename].mode):
            return

        grep_date = pkg.grep(self.istoday, filename)

        grep_time = pkg.grep(self.looksliketime, filename)

        if len(grep_date):
            if len(grep_time):
                printError(pkg, "file-contains-date-and-time", filename)
            else:
                printWarning(pkg, "file-contains-current-date", filename)

check=BuildDateCheck()

if Config.info:
    addDetails(
'file-contains-current-date',
"""Your file contains the current date, this may cause the package to rebuild in excess.""",
'file-contains-date-and-time',
"""Your file uses  __DATE and __TIME__ this causes the package to rebuild when not needed"""
)