2 # -*- coding: utf-8 -*-
4 # lint.py - part of the FDroid server tool
5 # Copyright (C) 2013-2014 Daniel Martà <mvdan@mvdan.cc>
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.
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.
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/>.
20 from optparse import OptionParser
23 import common, metadata
30 (re.compile(r'.*[^sS]://github\.com/.*'),
31 "github URLs should always use https:// not http://"),
32 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
33 "code.google.com URLs should always use https:// not http://"),
36 (re.compile(r'.*[^sS]://github\.com/.*'),
37 "github URLs should always use https:// (not http://, git://, or git@)"),
38 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
39 "/source is missing"),
40 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
41 "code.google.com URLs should always use https:// not http://"),
42 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
43 "dl.google.com URLs should always use https:// not http://"),
44 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
45 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
48 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
49 "code.google.com URLs should always use https:// not http://"),
50 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
51 "dl.google.com URLs should always use https:// not http://"),
52 (re.compile(r'.*[^sS]://github\.com/.*'),
53 "github URLs should always use https:// (not http://, git://, or git@)"),
54 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
55 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
56 (re.compile(r'.*[^sS]://[^.]*\.googlecode\.com/svn/?.*'),
57 "Google Code SVN URLs should always use https:// (not http:// or svn://)"),
58 (re.compile(r'.*[^sS]://svn\.apache\.org/repos/?.*'),
59 "Apache SVN URLs should always use https:// (not http:// or svn://)"),
60 (re.compile(r'.*[^sS]://svn\.code\.sf\.net/.*'),
61 "Sourceforge SVN URLs should always use https:// (not http:// or svn://)"),
64 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
65 "/issues is missing"),
66 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
67 "code.google.com URLs should always use https:// not http://"),
68 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
69 "/issues is missing"),
70 (re.compile(r'.*[^sS]://github\.com/.*'),
71 "github URLs should always use https:// not http://"),
72 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
73 "gitorious URLs should always use https:// not http://"),
79 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
80 "Appending .git is not necessary"),
81 (re.compile(r'.*code\.google\.com/p/[^/]+/[^w]'),
82 "Possible incorrect path appended to google code project site"),
85 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
86 "Appending .git is not necessary"),
87 (re.compile(r'.*code\.google\.com/p/[^/]+/source/.*'),
88 "/source is often enough on its own"),
91 (re.compile(r'^http://.*'),
92 "if https:// is available, use it instead of http://"),
93 (re.compile(r'^svn://.*'),
94 "if https:// is available, use it instead of svn://"),
97 (re.compile(r'.*code\.google\.com/p/[^/]+/issues/.*'),
98 "/issues is often enough on its own"),
99 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
100 "/issues is often enough on its own"),
103 (re.compile(r'.*\bandroid\b.*', re.IGNORECASE),
104 "No need to specify that the app is for Android"),
105 (re.compile(r'.*\b(app|application)\b.*', re.IGNORECASE),
106 "No need to specify that the app is... an app"),
107 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
108 "No need to specify that the app is Free Software"),
109 (re.compile(r'.*[a-z0-9][.,!?][ $]'),
110 "Punctuation should be avoided"),
116 global config, options, appid, app_count, warn_count
123 global appid, app_count, warn_count
128 print ' %s' % message
135 # Parse command line...
136 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
137 parser.add_option("-p", "--pedantic", action="store_true", default=False,
138 help="Show pedantic warnings that might give false positives")
139 parser.add_option("-v", "--verbose", action="store_true", default=False,
140 help="Spew out even more information than normal")
141 (options, args) = parser.parse_args()
143 config = common.read_config(options)
146 allapps = metadata.read_metadata(xref=False)
147 apps = common.read_app_args(args, allapps, False)
156 for build in app['builds']:
157 if 'commit' in build and 'disable' not in build:
158 lastcommit = build['commit']
160 # Potentially incorrect UCM
161 if (app['Update Check Mode'] == 'RepoManifest' and
162 any(s in lastcommit for s in '.,_-/')):
163 pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
164 lastcommit, app['Update Check Mode']))
167 if app['License'] in ('Unknown','None',''):
168 warn("License was not set")
171 summ_chars = len(app['Summary'])
172 if summ_chars > config['char_limits']['Summary']:
173 warn("Summary of length %s is over the %i char limit" % (
174 summ_chars, config['char_limits']['Summary']))
176 # Redundant summaries
177 summary = app['Summary']
178 name = str(app['Name'] if app['Name'] else app['Auto Name'])
180 summary_l = summary.lower()
181 name_l = name.lower()
182 if summary_l == name_l:
183 warn("Summary '%s' is just the app's name" % summary)
184 elif (summary_l in name_l or name_l in summary_l):
185 pwarn("Summary '%s' probably contains redundant info already in app name '%s'" % (
190 for line in app['Description']:
191 if re.match(r'[ ]*[*#][^ .]', line):
192 warn("Invalid bulleted list: '%s'" % line)
193 desc_chars += len(line)
195 # Description size limit
196 if desc_chars > config['char_limits']['Description']:
197 warn("Description of length %s is over the %i char limit" % (
198 desc_chars, config['char_limits']['Description']))
200 # Regex checks in all kinds of fields
201 for f in regex_warnings:
202 for m, r in regex_warnings[f]:
204 warn("%s '%s': %s" % (f, app[f], r))
206 # Regex pedantic checks in all kinds of fields
208 for f in regex_pedantic:
209 for m, r in regex_pedantic[f]:
211 warn("%s '%s': %s" % (f, app[f], r))
214 for build in app['builds']:
215 for n in ['master', 'origin/', 'default', 'trunk']:
216 if 'commit' in build:
217 if build['commit'].startswith(n):
218 warn("Branch '%s' used as commit in build '%s'" % (
219 n, build['version']))
220 if 'srclibs' in build:
221 for srclib in build['srclibs']:
222 ref = srclib.split('@')[1].split('/')[0]
223 if ref.startswith(n):
224 warn("Branch '%s' used as commit in srclib '%s'" % (
230 logging.info("Found a total of %i warnings in %i apps." % (warn_count, app_count))
232 if __name__ == "__main__":