aboutsummaryrefslogtreecommitdiffstats
path: root/anteater/src/get_lists.py
blob: 894151096a6127c3829eb8f3d3f0cda4f2f6d78c (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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) 2017 Luke Hinds <lhinds@redhat.com>, Red Hat
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

"""
    Gathers various values from the gate check yaml file and return them to the
    calling instance
"""

import anteater.utils.anteater_logger as antlog
import ConfigParser
import yaml
import re

config = ConfigParser.RawConfigParser()
config.read('anteater.conf')
logger = antlog.Logger(__name__).getLogger()
gate_checks = config.get('config', 'gate_checks')

with open(gate_checks, 'r') as f:
    yl = yaml.safe_load(f)


class GetLists(object):
    def __init__(self, *args):
        # Placeholder for future args if more filters are needed
        self.args = args

    def binary_list(self, project):
        project_list = False
        try:
            default_list = (yl['binaries']['binary_ignore'])
        except KeyError:
            logger.error('Key Error processing binary list values')
        try:
            project_list = (yl['binaries'][project]['binary_ignore'])
        except KeyError:
            logger.info('No binary waivers found for {0}'.
                        format(project))

        binary_re = re.compile("|".join(default_list),
                flags=re.IGNORECASE)

        if project_list:
            binary_project_re = re.compile("|".join(project_list),
                                           flags=re.IGNORECASE)
            return binary_re, binary_project_re
        else:
            binary_project_re = re.compile("")
            return binary_re, binary_project_re

    def file_audit_list(self, project):
        project_list = False
        try:
            default_list = set((yl['file_audits']['file_names']))
        except KeyError:
            logger.error('Key Error processing file_names list values')
        try:
            project_list = set((yl['file_audits'][project]['file_names']))
            logger.info('file_names waivers found for {0}'.
                        format(project))
        except KeyError:
            logger.info('No file_names waivers found for {0}'.
                        format(project))

        file_names_re = re.compile("|".join(default_list),
                                   flags=re.IGNORECASE)

        if project_list:
            file_names_proj_re = re.compile("|".join(project_list),
                                            flags=re.IGNORECASE)
            return file_names_re, file_names_proj_re
        else:
            file_names_proj_re = re.compile("")
            return file_names_re, file_names_proj_re

    def file_content_list(self,  project):
        project_list = False
        try:
            default_list = set((yl['file_audits']['file_contents']))
        except KeyError:
            logger.error('Key Error processing file_contents list values')
        try:
            project_list = set((yl['file_audits'][project]['file_contents']))
        except KeyError:
            logger.info('No file_contents waivers found  for {0}'.
                        format(project))

        file_contents_re = re.compile("|".join(default_list),
                                      flags=re.IGNORECASE)

        if project_list:
            file_contents_proj_re = re.compile("|".join(project_list),
                                               flags=re.IGNORECASE)
            return file_contents_re, file_contents_proj_re
        else:
            file_contents_proj_re = re.compile("")
            return file_contents_re, file_contents_proj_re

    def licence_extensions(self):
        try:
            licence_extensions = (yl['licence']['licence_ext'])
        except KeyError:
            logger.error('Key Error processing licence_extensions list values')
        return licence_extensions

    def licence_ignore(self):
        try:
            licence_ignore = (yl['licence']['licence_ignore'])
        except KeyError:
            logger.error('Key Error processing licence_ignore list values')
        return licence_ignore