Allow downloading files hosted by git.openstack.org
[releng-anteater.git] / anteater / main.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 # from __future__ import division, print_function, absolute_import
13
14 """Anteater - CI Gate Checks.
15
16 Usage:
17   anteater (-p |--project) <project> [(-ps |--patchset) <patchset>]
18   anteater (-p |--project) <project> [--path <project_path>]
19   anteater (-h | --help)
20   anteater --version
21
22 Options:
23   -h --help     Show this screen.
24   --version     Show version.
25 """
26 from __future__ import absolute_import
27
28 import six.moves.configparser
29 from docopt import docopt
30 import os
31 from anteater.src.patch_scan import prepare_patchset
32 from anteater.src.project_scan import prepare_project
33 from anteater.utils import anteater_logger as antlog
34
35
36 config = six.moves.configparser.RawConfigParser()
37 config.read('anteater.conf')
38 reports_dir = config.get('config', 'reports_dir')
39 logger = antlog.Logger(__name__).getLogger()
40 __version__ = "0.1"
41
42
43 def check_dir():
44     """ Creates a directory for scan reports """
45     try:
46         os.makedirs(reports_dir)
47         logger.info('Creating reports directory: {0}'.format(reports_dir))
48     except OSError as e:
49         if not os.path.isdir(reports_dir):
50             logger.error(e)
51
52
53 def main():
54     """ Main function, mostly for passing arguments """
55     check_dir()
56     arguments = docopt(__doc__, version=__version__)
57
58     if arguments['<patchset>']:
59         prepare_patchset(arguments['<project>'], arguments['<patchset>'])
60     elif arguments['<project_path>']:
61         prepare_project(arguments['<project>'], arguments['<project_path>'])
62
63
64 if __name__ == "__main__":
65     main()