chiark / gitweb /
New 'lint' subcommand in testing phase
[fdroidserver.git] / fdroidserver / lint.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 #
4 # rewritemeta.py - part of the FDroid server tool
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 th
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public Licen
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 from optparse import OptionParser
21 import common, metadata
22
23 config = None
24 options = None
25
26 appid = None
27
28 def warn(message):
29     global appid
30     if appid:
31         print "%s:" % appid
32         appid = None
33     print('    %s' % message)
34
35 def main():
36
37     global config, options, appid
38
39     # Parse command line...
40     parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
41     parser.add_option("-v", "--verbose", action="store_true", default=False,
42                       help="Spew out even more information than normal")
43     (options, args) = parser.parse_args()
44
45     config = common.read_config(options)
46
47     # Get all apps...
48     allapps = metadata.read_metadata(xref=False)
49     apps = common.read_app_args(args, allapps, False)
50
51     for app in apps:
52         appid = app['id']
53         lastcommit = ''
54
55         for build in app['builds']:
56             if 'commit' in build and 'disable' not in build:
57                 lastcommit = build['commit']
58
59         if (app['Update Check Mode'] == 'RepoManifest' and
60                 any(s in lastcommit for s in ('.', ',', '_', '-', '/'))):
61             warn("Last used commit '%s' looks like a tag, but Update Check Mode is RepoManifest" % lastcommit)
62
63         summ_chars = len(app['Summary'])
64         if summ_chars > config['char_limits']['Summary']:
65             warn("Summary of length %s is over the %i char limit" % (
66                 summ_chars, config['char_limits']['Summary']))
67
68         desc_chars = 0
69         for line in app['Description']:
70             desc_chars += len(line)
71         if desc_chars > config['char_limits']['Description']:
72             warn("Description of length %s is over the %i char limit" % (
73                 desc_chars, config['char_limits']['Description']))
74
75         if not appid:
76             print
77
78     print "Finished."
79
80 if __name__ == "__main__":
81     main()
82