2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 # Copyright (c) 2017 Luke Hinds <lhinds@redhat.com>, Red Hat
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 ##############################################################################
12 # from __future__ import division, print_function, absolute_import
14 """Anteater - CI Gate Checks.
17 anteater (-p |--project) <project> [(-ps |--patchset) <patchset>]
18 anteater (-p |--project) <project> [--path <project_path>]
19 anteater (-h | --help)
23 -h --help Show this screen.
24 --version Show version.
26 from __future__ import absolute_import
32 import six.moves.configparser
33 from docopt import docopt
35 from anteater import LOG
36 from anteater.src.patch_scan import prepare_patchset
37 from anteater.src.project_scan import prepare_project
39 config = six.moves.configparser.RawConfigParser()
40 config.read('anteater.conf')
41 reports_dir = config.get('config', 'reports_dir')
43 logger = logging.getLogger(__name__)
46 def _init_logging(anteater_log):
47 """ Setup root logger for package """
49 LOG.setLevel(logging.DEBUG)
50 ch = logging.StreamHandler()
51 formatter = logging.Formatter('%(asctime)s - %(name)s - '
52 '%(levelname)s - %(message)s')
53 ch.setFormatter(formatter)
54 ch.setLevel(logging.DEBUG)
56 # create the directory if it does not exist
57 path = os.path.dirname(anteater_log)
61 if e.errno != errno.EEXIST:
64 handler = logging.FileHandler(anteater_log)
65 handler.setFormatter(formatter)
66 handler.setLevel(logging.DEBUG)
67 del logging.root.handlers[:]
68 logging.root.addHandler(ch)
69 logging.root.addHandler(handler)
73 """ Creates a directory for scan reports """
75 os.makedirs(reports_dir)
76 logger.info('Creating reports directory: %s', reports_dir)
78 if e.errno != errno.EEXIST:
83 """ Main function, mostly for passing arguments """
84 _init_logging(config.get('config', 'anteater_log'))
86 arguments = docopt(__doc__, version=__version__)
88 if arguments['<patchset>']:
89 prepare_patchset(arguments['<project>'], arguments['<patchset>'])
90 elif arguments['<project_path>']:
91 prepare_project(arguments['<project>'], arguments['<project_path>'])
94 if __name__ == "__main__":