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