chiark / gitweb /
bd9d27009286ff4701a3cdc10ce1f3fd479f8d20
[fdroidserver.git] / scanner.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # scanner.py - part of the FDroid server tools
5 # Copyright (C) 2010-12, 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 sys
21 import os
22 import shutil
23 import re
24 import urllib
25 import time
26 import subprocess
27 import traceback
28 from optparse import OptionParser
29 import HTMLParser
30 import common
31 from common import BuildException
32 from common import VCSException
33
34 def main():
35
36     # Read configuration...
37     execfile('config.py', globals())
38
39
40     # Parse command line...
41     parser = OptionParser()
42     parser.add_option("-v", "--verbose", action="store_true", default=False,
43                       help="Spew out even more information than normal")
44     parser.add_option("-p", "--package", default=None,
45                       help="Scan only the specified package")
46     parser.add_option("--nosvn", action="store_true", default=False,
47                       help="Skip svn repositories - for test purposes, because they are too slow.")
48     (options, args) = parser.parse_args()
49
50     # Get all apps...
51     apps = common.read_metadata(options.verbose)
52
53     html_parser = HTMLParser.HTMLParser()
54
55     problems = []
56
57     extlib_dir = os.path.join('build', 'extlib')
58
59     for app in apps:
60
61         skip = False
62         if options.package and app['id'] != options.package:
63             skip = True
64         elif app['Disabled']:
65             print "Skipping %s: disabled" % app['id']
66             skip = True
67         elif not app['builds']:
68             print "Skipping %s: no builds specified" % app['id']
69             skip = True
70         elif options.nosvn and app['Repo Type'] == 'svn':
71             skip = True
72
73         if not skip:
74
75             print "Processing " + app['id']
76
77             try:
78
79                 build_dir = 'build/' + app['id']
80
81                 # Set up vcs interface and make sure we have the latest code...
82                 vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir)
83
84                 for thisbuild in app['builds']:
85
86                     if thisbuild['commit'].startswith('!'):
87                         print ("..skipping version " + thisbuild['version'] + " - " +
88                                 thisbuild['commit'][1:])
89                     else:
90                         print "..scanning version " + thisbuild['version']
91
92                         # Prepare the source code...
93                         root_dir = common.prepare_source(vcs, app, thisbuild,
94                                 build_dir, extlib_dir, sdk_path, ndk_path, javacc_path)
95
96                         # Do the scan...
97                         buildprobs = common.scan_source(build_dir, root_dir, thisbuild)
98                         for problem in buildprobs:
99                             problems.append(problem + 
100                                 ' in ' + app['id'] + ' ' + thisbuild['version'])
101
102             except BuildException as be:
103                 msg = "Could not scan app %s due to BuildException: %s" % (app['id'], be)
104                 problems.append(msg)
105             except VCSException as vcse:
106                 msg = "VCS error while scanning app %s: %s" % (app['id'], vcse)
107                 problems.append(msg)
108             except Exception:
109                 msg = "Could not scan app %s due to unknown error: %s" % (app['id'], traceback.format_exc())
110                 problems.append(msg)
111
112     print "Finished:"
113     for problem in problems:
114         print problem
115     print str(len(problems)) + ' problems.'
116
117 if __name__ == "__main__":
118     main()
119