894151096a6127c3829eb8f3d3f0cda4f2f6d78c
[releng-anteater.git] / anteater / src / get_lists.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 # Copyright (c) 2017 Luke Hinds <lhinds@redhat.com>, Red Hat
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 """
13     Gathers various values from the gate check yaml file and return them to the
14     calling instance
15 """
16
17 import anteater.utils.anteater_logger as antlog
18 import ConfigParser
19 import yaml
20 import re
21
22 config = ConfigParser.RawConfigParser()
23 config.read('anteater.conf')
24 logger = antlog.Logger(__name__).getLogger()
25 gate_checks = config.get('config', 'gate_checks')
26
27 with open(gate_checks, 'r') as f:
28     yl = yaml.safe_load(f)
29
30
31 class GetLists(object):
32     def __init__(self, *args):
33         # Placeholder for future args if more filters are needed
34         self.args = args
35
36     def binary_list(self, project):
37         project_list = False
38         try:
39             default_list = (yl['binaries']['binary_ignore'])
40         except KeyError:
41             logger.error('Key Error processing binary list values')
42         try:
43             project_list = (yl['binaries'][project]['binary_ignore'])
44         except KeyError:
45             logger.info('No binary waivers found for {0}'.
46                         format(project))
47
48         binary_re = re.compile("|".join(default_list),
49                 flags=re.IGNORECASE)
50
51         if project_list:
52             binary_project_re = re.compile("|".join(project_list),
53                                            flags=re.IGNORECASE)
54             return binary_re, binary_project_re
55         else:
56             binary_project_re = re.compile("")
57             return binary_re, binary_project_re
58
59     def file_audit_list(self, project):
60         project_list = False
61         try:
62             default_list = set((yl['file_audits']['file_names']))
63         except KeyError:
64             logger.error('Key Error processing file_names list values')
65         try:
66             project_list = set((yl['file_audits'][project]['file_names']))
67             logger.info('file_names waivers found for {0}'.
68                         format(project))
69         except KeyError:
70             logger.info('No file_names waivers found for {0}'.
71                         format(project))
72
73         file_names_re = re.compile("|".join(default_list),
74                                    flags=re.IGNORECASE)
75
76         if project_list:
77             file_names_proj_re = re.compile("|".join(project_list),
78                                             flags=re.IGNORECASE)
79             return file_names_re, file_names_proj_re
80         else:
81             file_names_proj_re = re.compile("")
82             return file_names_re, file_names_proj_re
83
84     def file_content_list(self,  project):
85         project_list = False
86         try:
87             default_list = set((yl['file_audits']['file_contents']))
88         except KeyError:
89             logger.error('Key Error processing file_contents list values')
90         try:
91             project_list = set((yl['file_audits'][project]['file_contents']))
92         except KeyError:
93             logger.info('No file_contents waivers found  for {0}'.
94                         format(project))
95
96         file_contents_re = re.compile("|".join(default_list),
97                                       flags=re.IGNORECASE)
98
99         if project_list:
100             file_contents_proj_re = re.compile("|".join(project_list),
101                                                flags=re.IGNORECASE)
102             return file_contents_re, file_contents_proj_re
103         else:
104             file_contents_proj_re = re.compile("")
105             return file_contents_re, file_contents_proj_re
106
107     def licence_extensions(self):
108         try:
109             licence_extensions = (yl['licence']['licence_ext'])
110         except KeyError:
111             logger.error('Key Error processing licence_extensions list values')
112         return licence_extensions
113
114     def licence_ignore(self):
115         try:
116             licence_ignore = (yl['licence']['licence_ignore'])
117         except KeyError:
118             logger.error('Key Error processing licence_ignore list values')
119         return licence_ignore