chiark / gitweb /
Restrict vagrant-cachier caches to only apt and chef.
[fdroidserver.git] / fdroidserver / scanner.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 #
4 # scanner.py - part of the FDroid server tools
5 # Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 import os
21 import traceback
22 from optparse import OptionParser
23 import logging
24
25 import common
26 import metadata
27 from common import BuildException, VCSException
28
29 config = None
30 options = None
31
32
33 def main():
34
35     global config, options
36
37     # Parse command line...
38     parser = OptionParser(usage="Usage: %prog [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
39     parser.add_option("-v", "--verbose", action="store_true", default=False,
40                       help="Spew out even more information than normal")
41     parser.add_option("-q", "--quiet", action="store_true", default=False,
42                       help="Restrict output to warnings and errors")
43     (options, args) = parser.parse_args()
44
45     config = common.read_config(options)
46
47     # Read all app and srclib metadata
48     allapps = metadata.read_metadata()
49     apps = common.read_app_args(args, allapps, True)
50
51     problems = []
52
53     build_dir = 'build'
54     if not os.path.isdir(build_dir):
55         logging.info("Creating build directory")
56         os.makedirs(build_dir)
57     srclib_dir = os.path.join(build_dir, 'srclib')
58     extlib_dir = os.path.join(build_dir, 'extlib')
59
60     for appid, app in apps.iteritems():
61
62         if app['Disabled']:
63             logging.info("Skipping %s: disabled" % appid)
64             continue
65         if not app['builds']:
66             logging.info("Skipping %s: no builds specified" % appid)
67             continue
68
69         logging.info("Processing " + appid)
70
71         try:
72
73             build_dir = 'build/' + appid
74
75             # Set up vcs interface and make sure we have the latest code...
76             vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir)
77
78             for thisbuild in app['builds']:
79
80                 if thisbuild['disable']:
81                     logging.info("...skipping version %s - %s" % (
82                         thisbuild['version'], thisbuild.get('disable', thisbuild['commit'][1:])))
83                 else:
84                     logging.info("...scanning version " + thisbuild['version'])
85
86                     # Prepare the source code...
87                     root_dir, _ = common.prepare_source(vcs, app, thisbuild,
88                                                         build_dir, srclib_dir,
89                                                         extlib_dir, False)
90
91                     # Do the scan...
92                     buildprobs = common.scan_source(build_dir, root_dir, thisbuild)
93                     for problem in buildprobs:
94                         problems.append(problem + ' in ' + appid
95                                         + ' ' + thisbuild['version'])
96
97         except BuildException as be:
98             msg = "Could not scan app %s due to BuildException: %s" % (appid, be)
99             problems.append(msg)
100         except VCSException as vcse:
101             msg = "VCS error while scanning app %s: %s" % (appid, vcse)
102             problems.append(msg)
103         except Exception:
104             msg = "Could not scan app %s due to unknown error: %s" % (appid, traceback.format_exc())
105             problems.append(msg)
106
107     logging.info("Finished:")
108     for problem in problems:
109         print problem
110     print str(len(problems)) + ' problems.'
111
112 if __name__ == "__main__":
113     main()