Allow downloading files hosted by git.openstack.org
[releng-anteater.git] / anteater / anteater.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
27 import ConfigParser
28 from docopt import docopt
29 import os
30 from src.patch_scan import prepare_patchset
31 from src.project_scan import prepare_project
32 import utils.anteater_logger as antlog
33
34
35 config = ConfigParser.RawConfigParser()
36 config.read('anteater.conf')
37 reports_dir = config.get('config', 'reports_dir')
38 logger = antlog.Logger(__name__).getLogger()
39 __version__ = "0.1"
40
41
42 def check_dir():
43     """ Creates a directory for scan reports """
44     try:
45         os.makedirs(reports_dir)
46         logger.info('Creating reports directory: {0}'.format(reports_dir))
47     except OSError as e:
48         if not os.path.isdir(reports_dir):
49             logger.error(e)
50
51
52 def main():
53     """ Main function, mostly for passing arguments """
54     check_dir()
55     arguments = docopt(__doc__, version=__version__)
56
57     if arguments['<patchset>']:
58         prepare_patchset(arguments['<project>'], arguments['<patchset>'])
59     elif arguments['<project_path>']:
60         prepare_project(arguments['<project>'], arguments['<project_path>'])
61
62
63 if __name__ == "__main__":
64     main()