aboutsummaryrefslogtreecommitdiffstats
path: root/anteater/src/get_lists.py
diff options
context:
space:
mode:
authorlhinds <lhinds@redhat.com>2017-05-17 13:31:18 +0100
committerlhinds <lhinds@redhat.com>2017-05-22 14:12:27 +0100
commit0142c227fca974fb65561d0aeb9b38c8683e22e6 (patch)
treef802b60e2ceab8b033212568d3adddc754faa7da /anteater/src/get_lists.py
parent9c00ca00dcad5624288de38e0a529f7f7b3915db (diff)
Initial code push of Anteater
Likely far to much to cover in a commit msg. Main bulk is the Anteater code itself, alongside packaging requirements and build tools and Dockerfile. Unit tests are planned as a follow up, so pushing this for now so that efforts can get underway to integrate the tool with jjb. Questions on how it works, please reach me in IRC. Change-Id: I2cd3cae391f8bf2cdc91b39c56dfc4833a1c4913 Signed-off-by: lhinds <lhinds@redhat.com>
Diffstat (limited to 'anteater/src/get_lists.py')
-rw-r--r--anteater/src/get_lists.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/anteater/src/get_lists.py b/anteater/src/get_lists.py
new file mode 100644
index 0000000..8941510
--- /dev/null
+++ b/anteater/src/get_lists.py
@@ -0,0 +1,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