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
31 def enforce_https(domain):
32 return (re.compile(r'.*[^sS]://[^/]*' + re.escape(domain) + r'(/.*)?'),
33 domain + " URLs should always use https://")
36 enforce_https('github.com'),
37 enforce_https('gitlab.com'),
38 enforce_https('bitbucket.org'),
39 enforce_https('apache.org'),
40 enforce_https('google.com'),
41 enforce_https('svn.code.sf.net'),
45 def forbid_shortener(domain):
46 return (re.compile(r'https?://[^/]*' + re.escape(domain) + r'/.*'),
47 "URL shorteners should not be used")
49 http_url_shorteners = [
50 forbid_shortener('goo.gl'),
51 forbid_shortener('t.co'),
52 forbid_shortener('ur1.ca'),
55 http_checks = https_enforcings + http_url_shorteners + [
56 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
57 "Appending .git is not necessary"),
58 (re.compile(r'(.*/blob/master/|.*raw\.github.com/[^/]*/[^/]*/master/)'),
59 "Use /HEAD/ instead of /master/ to point at a file in the default branch"),
63 'Web Site': http_checks + [
65 'Source Code': http_checks + [
67 'Repo': https_enforcings + [
69 'Issue Tracker': http_checks + [
70 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
71 "/issues is missing"),
73 'Donate': http_checks + [
74 (re.compile(r'.*flattr\.com'),
75 "Flattr donation methods belong in the FlattrID flag"),
77 'Changelog': http_checks + [
80 (re.compile(r'^(|None|Unknown)$'),
81 "No license specified"),
85 "Summary yet to be filled"),
86 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
87 "No need to specify that the app is Free Software"),
88 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
89 "No need to specify that the app is for Android"),
90 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
91 "Punctuation should be avoided"),
94 (re.compile(r'^No description available$'),
95 "Description yet to be filled"),
96 (re.compile(r'\s*[*#][^ .]'),
97 "Invalid bulleted list"),
99 "Unnecessary leading space"),
100 (re.compile(r'.*\s$'),
101 "Unnecessary trailing space"),
102 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
103 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
104 (re.compile(r'.*[^[]https?://[^ ]+'),
105 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
110 def check_regexes(app):
111 for f, checks in regex_checks.iteritems():
118 yield "%s '%s': %s" % (f, v, r)
119 elif type(v) == list:
122 yield "%s at line '%s': %s" % (f, l, r)
125 def get_lastbuild(builds):
129 if not build['disable']:
130 vercode = int(build['vercode'])
131 if lowest_vercode == -1 or vercode < lowest_vercode:
132 lowest_vercode = vercode
133 if not lastbuild or int(build['vercode']) > int(lastbuild['vercode']):
138 def check_ucm_tags(app):
139 lastbuild = get_lastbuild(app['builds'])
140 if (lastbuild is not None
141 and lastbuild['commit']
142 and app['Update Check Mode'] == 'RepoManifest'
143 and not lastbuild['commit'].startswith('unknown')
144 and lastbuild['vercode'] == app['Current Version Code']
145 and not lastbuild['forcevercode']
146 and any(s in lastbuild['commit'] for s in '.,_-/')):
147 yield "Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
148 lastbuild['commit'], app['Update Check Mode'])
151 def check_char_limits(app):
152 limits = config['char_limits']
154 summ_chars = len(app['Summary'])
155 if summ_chars > limits['Summary']:
156 yield "Summary of length %s is over the %i char limit" % (
157 summ_chars, limits['Summary'])
159 desc_charcount = sum(len(l) for l in app['Description'])
160 if desc_charcount > limits['Description']:
161 yield "Description of length %s is over the %i char limit" % (
162 desc_charcount, limits['Description'])
165 def check_old_links(app):
175 if any(s in app['Repo'] for s in usual_sites):
176 for f in ['Web Site', 'Source Code', 'Issue Tracker', 'Changelog']:
177 if any(s in app[f] for s in old_sites):
178 yield "App is in '%s' but has a link to '%s'" % (app['Repo'], app[f])
181 def check_useless_fields(app):
182 if app['Update Check Name'] == app['id']:
183 yield "Update Check Name is set to the known app id - it can be removed"
185 filling_ucms = re.compile('^(Tags.*|RepoManifest.*)')
188 def check_checkupdates_ran(app):
189 if filling_ucms.match(app['Update Check Mode']):
190 if all(app[f] == metadata.app_defaults[f] for f in [
193 'Current Version Code',
195 yield "UCM is set but it looks like checkupdates hasn't been run yet"
198 def check_empty_fields(app):
199 if not app['Categories']:
200 yield "Categories are not set"
202 all_categories = Set([
213 "Science & Education",
223 def check_categories(app):
224 for categ in app['Categories']:
225 if categ not in all_categories:
226 yield "Category '%s' is not valid" % categ
229 def check_duplicates(app):
230 if app['Web Site'] and app['Source Code']:
231 if app['Web Site'].lower() == app['Source Code'].lower():
232 yield "Website '%s' is just the app's source code link" % app['Web Site']
234 if app['Name'] and app['Name'] == app['Auto Name']:
235 yield "Name '%s' is just the auto name" % app['Name']
237 name = app['Name'] or app['Auto Name']
238 if app['Summary'] and name:
239 if app['Summary'].lower() == name.lower():
240 yield "Summary '%s' is just the app's name" % app['Summary']
242 desc = app['Description']
243 if app['Summary'] and desc and len(desc) == 1:
244 if app['Summary'].lower() == desc[0].lower():
245 yield "Description '%s' is just the app's summary" % app['Summary']
248 for l in app['Description']:
252 yield "Description has a duplicate line"
256 desc_url = re.compile("[^[]\[([^ ]+)( |\]|$)")
259 def check_mediawiki_links(app):
260 wholedesc = ' '.join(app['Description'])
261 for um in desc_url.finditer(wholedesc):
263 for m, r in http_checks:
265 yield "URL '%s' in Description: %s" % (url, r)
268 def check_bulleted_lists(app):
269 validchars = ['*', '#']
272 for l in app['Description']:
277 if l[0] == lchar and l[1] == ' ':
279 if lcount > 2 and lchar not in validchars:
280 yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
287 def check_builds(app):
288 for build in app['builds']:
291 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
292 if build['commit'] and build['commit'].startswith(s):
293 yield "Branch '%s' used as commit in build '%s'" % (s, build['version'])
294 for srclib in build['srclibs']:
295 ref = srclib.split('@')[1].split('/')[0]
296 if ref.startswith(s):
297 yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
302 global config, options
306 # Parse command line...
307 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
308 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
309 parser.add_argument("-v", "--verbose", action="store_true", default=False,
310 help="Spew out even more information than normal")
311 parser.add_argument("-q", "--quiet", action="store_true", default=False,
312 help="Restrict output to warnings and errors")
313 options = parser.parse_args()
315 config = common.read_config(options)
318 allapps = metadata.read_metadata(xref=True)
319 apps = common.read_app_args(options.appid, allapps, False)
321 for appid, app in apps.iteritems():
332 check_checkupdates_ran,
333 check_useless_fields,
337 check_mediawiki_links,
338 check_bulleted_lists,
341 warns += check_func(app)
346 print "%s: %s" % (appid, warn)
352 if __name__ == "__main__":