chiark / gitweb /
Warn about branches used in commit=
[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 re
22 import common, metadata
23
24 config = None
25 options = None
26
27 appid = None
28
29 def warn(message):
30     global appid
31     if appid:
32         print "%s:" % appid
33         appid = None
34     print('    %s' % message)
35
36 def main():
37
38     global config, options, appid
39
40     # Parse command line...
41     parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
42     parser.add_option("-v", "--verbose", action="store_true", default=False,
43                       help="Spew out even more information than normal")
44     (options, args) = parser.parse_args()
45
46     config = common.read_config(options)
47
48     # Get all apps...
49     allapps = metadata.read_metadata(xref=False)
50     apps = common.read_app_args(args, allapps, False)
51
52     regex_warnings = {
53             'Source Code': [
54                 (re.compile(r'.*code\.google\.com/p/[^/]+/source/.*'),
55                     "/source is often enough on its own"),
56                 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
57                     "/source is missing")
58             ],
59             'Issue Tracker': [
60                 (re.compile(r'.*code\.google\.com/p/[^/]+/issues/.*'),
61                     "/issues is often enough on its own"),
62                 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
63                     "/issues is missing"),
64                 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
65                     "/issues is often enough on its own"),
66                 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
67                     "/issues is missing")
68             ]
69     }
70
71     for app in apps:
72         appid = app['id']
73         lastcommit = ''
74
75         for build in app['builds']:
76             if 'commit' in build and 'disable' not in build:
77                 lastcommit = build['commit']
78
79         # Potentially incorrect UCM
80         if (app['Update Check Mode'] == 'RepoManifest' and
81                 any(s in lastcommit for s in ('.', ',', '_', '-', '/'))):
82             warn("Last used commit '%s' looks like a tag, but Update Check Mode is RepoManifest" % lastcommit)
83
84         # Summary size limit
85         summ_chars = len(app['Summary'])
86         if summ_chars > config['char_limits']['Summary']:
87             warn("Summary of length %s is over the %i char limit" % (
88                 summ_chars, config['char_limits']['Summary']))
89
90         # Description size limit
91         desc_chars = 0
92         for line in app['Description']:
93             desc_chars += len(line)
94         if desc_chars > config['char_limits']['Description']:
95             warn("Description of length %s is over the %i char limit" % (
96                 desc_chars, config['char_limits']['Description']))
97
98         # No punctuation in summary
99         if app['Summary']:
100             lastchar = app['Summary'][-1]
101             if any(lastchar==c for c in ['.', ',', '!', '?']):
102                 warn("Summary should not end with a %s" % lastchar)
103
104         # Common mistakes in urls
105         for f in ['Source Code', 'Issue Tracker']:
106             if f not in regex_warnings:
107                 continue
108             for m, r in regex_warnings[f]:
109                 if m.match(app[f]):
110                     warn("%s url '%s': %s" % (f, app[f], r))
111
112         # Build warnings
113         for build in app['builds']:
114             for n in ['master', 'origin/', 'default', 'trunk']:
115                 if 'commit' not in build:
116                     continue
117                 if build['commit'].startswith(n):
118                     warn("Branch '%s' used as commit" % n)
119
120
121         if not appid:
122             print
123
124     print "Finished."
125
126 if __name__ == "__main__":
127     main()
128