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 argparse import ArgumentParser
26 from collections import Counter
33 def enforce_https(domain):
34 return (re.compile(r'.*[^sS]://[^/]*' + re.escape(domain) + r'(/.*)?'),
35 domain + " URLs should always use https://")
38 enforce_https('github.com'),
39 enforce_https('gitlab.com'),
40 enforce_https('bitbucket.org'),
41 enforce_https('apache.org'),
42 enforce_https('google.com'),
43 enforce_https('svn.code.sf.net'),
47 def forbid_shortener(domain):
48 return (re.compile(r'https?://[^/]*' + re.escape(domain) + r'/.*'),
49 "URL shorteners should not be used")
51 http_url_shorteners = [
52 forbid_shortener('goo.gl'),
53 forbid_shortener('t.co'),
54 forbid_shortener('ur1.ca'),
57 http_warnings = https_enforcings + http_url_shorteners + [
58 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
59 "Appending .git is not necessary"),
60 (re.compile(r'(.*/blob/master/|.*raw\.github.com/[^/]*/[^/]*/master/)'),
61 "Use /HEAD/ instead of /master/ to point at a file in the default branch"),
65 'Web Site': http_warnings + [
67 'Source Code': http_warnings + [
69 'Repo': https_enforcings + [
71 'Issue Tracker': http_warnings + [
72 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
73 "/issues is missing"),
75 'Donate': http_warnings + [
76 (re.compile(r'.*flattr\.com'),
77 "Flattr donation methods belong in the FlattrID flag"),
79 'Changelog': http_warnings + [
82 (re.compile(r'^(|None|Unknown)$'),
83 "No license specified"),
87 "Summary yet to be filled"),
88 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
89 "No need to specify that the app is Free Software"),
90 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
91 "No need to specify that the app is for Android"),
92 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
93 "Punctuation should be avoided"),
96 (re.compile(r'^No description available$'),
97 "Description yet to be filled"),
98 (re.compile(r'\s*[*#][^ .]'),
99 "Invalid bulleted list"),
101 "Unnecessary leading space"),
102 (re.compile(r'.*\s$'),
103 "Unnecessary trailing space"),
104 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
105 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
106 (re.compile(r'.*[^[]https?://[^ ]+'),
107 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
122 "Science & Education",
131 desc_url = re.compile("[^[]\[([^ ]+)( |\]|$)")
136 global config, options, curid, count
147 print ' %s' % message
150 # Parse command line...
151 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
152 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
153 parser.add_argument("-v", "--verbose", action="store_true", default=False,
154 help="Spew out even more information than normal")
155 parser.add_argument("-q", "--quiet", action="store_true", default=False,
156 help="Restrict output to warnings and errors")
157 options = parser.parse_args()
159 config = common.read_config(options)
162 allapps = metadata.read_metadata(xref=True)
163 apps = common.read_app_args(options.appid, allapps, False)
165 filling_ucms = re.compile('^(Tags.*|RepoManifest.*)')
167 for appid, app in apps.iteritems():
172 count['app_total'] += 1
176 for build in app['builds']:
177 if not build['disable']:
178 vercode = int(build['vercode'])
179 if lowest_vercode == -1 or vercode < lowest_vercode:
180 lowest_vercode = vercode
181 if not curbuild or int(build['vercode']) > int(curbuild['vercode']):
185 if (curbuild and curbuild['commit']
186 and app['Update Check Mode'] == 'RepoManifest'
187 and not curbuild['commit'].startswith('unknown')
188 and curbuild['vercode'] == app['Current Version Code']
189 and not curbuild['forcevercode']
190 and any(s in curbuild['commit'] for s in '.,_-/')):
191 warn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
192 curbuild['commit'], app['Update Check Mode']))
195 summ_chars = len(app['Summary'])
196 if summ_chars > config['char_limits']['Summary']:
197 warn("Summary of length %s is over the %i char limit" % (
198 summ_chars, config['char_limits']['Summary']))
201 if app['Web Site'] and app['Source Code']:
202 if app['Web Site'].lower() == app['Source Code'].lower():
203 warn("Website '%s' is just the app's source code link" % app['Web Site'])
215 if any(s in app['Repo'] for s in usual_sites):
216 for f in ['Web Site', 'Source Code', 'Issue Tracker', 'Changelog']:
217 if any(s in app[f] for s in old_sites):
218 warn("App is in '%s' but has a link to '%s'" % (app['Repo'], app[f]))
220 if filling_ucms.match(app['Update Check Mode']):
221 if all(app[f] == metadata.app_defaults[f] for f in [
224 'Current Version Code',
226 warn("UCM is set but it looks like checkupdates hasn't been run yet")
228 if app['Update Check Name'] == appid:
229 warn("Update Check Name is set to the known app id - it can be removed")
231 cvc = int(app['Current Version Code'])
232 if cvc > 0 and cvc < lowest_vercode:
233 warn("Current Version Code is lower than any enabled build")
235 # Missing or incorrect categories
236 if not app['Categories']:
237 warn("Categories are not set")
238 for categ in app['Categories']:
239 if categ not in categories:
240 warn("Category '%s' is not valid" % categ)
242 if app['Name'] and app['Name'] == app['Auto Name']:
243 warn("Name '%s' is just the auto name" % app['Name'])
245 name = app['Name'] or app['Auto Name']
246 if app['Summary'] and name:
247 if app['Summary'].lower() == name.lower():
248 warn("Summary '%s' is just the app's name" % app['Summary'])
250 desc = app['Description']
251 if app['Summary'] and desc and len(desc) == 1:
252 if app['Summary'].lower() == desc[0].lower():
253 warn("Description '%s' is just the app's summary" % app['Summary'])
255 # Description size limit
256 desc_charcount = sum(len(l) for l in desc)
257 if desc_charcount > config['char_limits']['Description']:
258 warn("Description of length %s is over the %i char limit" % (
259 desc_charcount, config['char_limits']['Description']))
262 for l in app['Description']:
263 if any(l.startswith(c) for c in ['*', '#']):
265 if any(len(w) > maxcols for w in l.split(' ')):
268 warn("Description should be wrapped to 80-120 chars")
271 if (not desc[0] or not desc[-1]
272 or any(not desc[l - 1] and not desc[l] for l in range(1, len(desc)))):
273 warn("Description has an extra empty line")
276 for l in app['Description']:
280 warn("Description has a duplicate line")
283 for l in app['Description']:
284 for um in desc_url.finditer(l):
286 for m, r in http_warnings:
288 warn("URL '%s' in Description: %s" % (url, r))
290 # Check for lists using the wrong characters
291 validchars = ['*', '#']
294 for l in app['Description']:
299 if l[0] == lchar and l[1] == ' ':
301 if lcount > 2 and lchar not in validchars:
302 warn("Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar)
308 # Regex checks in all kinds of fields
309 for f in regex_warnings:
310 for m, r in regex_warnings[f]:
316 warn("%s '%s': %s" % (f, v, r))
317 elif type(v) == list:
320 warn("%s at line '%s': %s" % (f, l, r))
323 for build in app['builds']:
326 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
327 if build['commit'] and build['commit'].startswith(s):
328 warn("Branch '%s' used as commit in build '%s'" % (
329 s, build['version']))
330 for srclib in build['srclibs']:
331 ref = srclib.split('@')[1].split('/')[0]
332 if ref.startswith(s):
333 warn("Branch '%s' used as commit in srclib '%s'" % (
339 if count['warn'] > 0:
340 logging.warn("Found a total of %i warnings in %i apps out of %i total." % (
341 count['warn'], count['app'], count['app_total']))
345 if __name__ == "__main__":