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
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('gitorious.org'),
41 enforce_https('apache.org'),
42 enforce_https('google.com'),
43 enforce_https('svn.code.sf.net'),
44 enforce_https('googlecode.com'),
48 def forbid_shortener(domain):
49 return (re.compile(r'https?://[^/]*' + re.escape(domain) + r'/.*'),
50 "URL shorteners should not be used")
52 http_url_shorteners = [
53 forbid_shortener('goo.gl'),
54 forbid_shortener('t.co'),
55 forbid_shortener('ur1.ca'),
58 http_warnings = https_enforcings + http_url_shorteners + [
59 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
60 "Appending .git is not necessary"),
61 # TODO enable in August 2015, when Google Code goes read-only
62 # (re.compile(r'.*://code\.google\.com/.*'),
63 # "code.google.com will be soon switching down, perhaps the project moved to github.com?"),
67 'Web Site': http_warnings + [
69 'Source Code': http_warnings + [
71 'Repo': https_enforcings + [
73 'Issue Tracker': http_warnings + [
74 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
75 "/issues is missing"),
77 'Donate': http_warnings + [
78 (re.compile(r'.*flattr\.com'),
79 "Flattr donation methods belong in the FlattrID flag"),
81 'Changelog': http_warnings + [
84 (re.compile(r'^(|None|Unknown)$'),
85 "No license specified"),
89 "Summary yet to be filled"),
90 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
91 "No need to specify that the app is Free Software"),
92 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
93 "No need to specify that the app is for Android"),
94 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
95 "Punctuation should be avoided"),
98 (re.compile(r'^No description available$'),
99 "Description yet to be filled"),
100 (re.compile(r'\s*[*#][^ .]'),
101 "Invalid bulleted list"),
103 "Unnecessary leading space"),
104 (re.compile(r'.*\s$'),
105 "Unnecessary trailing space"),
119 "Science & Education",
125 desc_url = re.compile("[^[]\[([^ ]+)( |\]|$)")
130 global config, options, curid, count
141 print ' %s' % message
144 # Parse command line...
145 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
146 parser.add_option("-v", "--verbose", action="store_true", default=False,
147 help="Spew out even more information than normal")
148 parser.add_option("-q", "--quiet", action="store_true", default=False,
149 help="Restrict output to warnings and errors")
150 (options, args) = parser.parse_args()
152 config = common.read_config(options)
155 allapps = metadata.read_metadata(xref=False)
156 apps = common.read_app_args(args, allapps, False)
158 filling_ucms = re.compile('^(Tags.*|RepoManifest.*)')
160 for appid, app in apps.iteritems():
165 count['app_total'] += 1
170 for build in app['builds']:
171 if not build['disable']:
172 # enabled_builds += 1
173 vercode = int(build['vercode'])
174 if lowest_vercode == -1 or vercode < lowest_vercode:
175 lowest_vercode = vercode
176 if not curbuild or int(build['vercode']) > int(curbuild['vercode']):
180 if (curbuild and curbuild['commit']
181 and app['Update Check Mode'] == 'RepoManifest'
182 and not curbuild['commit'].startswith('unknown')
183 and curbuild['vercode'] == app['Current Version Code']
184 and not curbuild['forcevercode']
185 and any(s in curbuild['commit'] for s in '.,_-/')):
186 warn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
187 curbuild['commit'], app['Update Check Mode']))
190 summ_chars = len(app['Summary'])
191 if summ_chars > config['char_limits']['Summary']:
192 warn("Summary of length %s is over the %i char limit" % (
193 summ_chars, config['char_limits']['Summary']))
196 if app['Web Site'] and app['Source Code']:
197 if app['Web Site'].lower() == app['Source Code'].lower():
198 warn("Website '%s' is just the app's source code link" % app['Web Site'])
200 if filling_ucms.match(app['Update Check Mode']):
201 if all(app[f] == metadata.app_defaults[f] for f in [
204 'Current Version Code',
206 warn("UCM is set but it looks like checkupdates hasn't been run yet")
208 if app['Update Check Name'] == appid:
209 warn("Update Check Name is set to the known app id - it can be removed")
211 cvc = int(app['Current Version Code'])
212 if cvc > 0 and cvc < lowest_vercode:
213 warn("Current Version Code is lower than any enabled build")
215 # Missing or incorrect categories
216 if not app['Categories']:
217 warn("Categories are not set")
218 for categ in app['Categories']:
219 if categ not in categories:
220 warn("Category '%s' is not valid" % categ)
222 if app['Name'] and app['Name'] == app['Auto Name']:
223 warn("Name '%s' is just the auto name" % app['Name'])
225 name = app['Name'] or app['Auto Name']
226 if app['Summary'] and name:
227 if app['Summary'].lower() == name.lower():
228 warn("Summary '%s' is just the app's name" % app['Summary'])
230 desc = app['Description']
231 if app['Summary'] and desc and len(desc) == 1:
232 if app['Summary'].lower() == desc[0].lower():
233 warn("Description '%s' is just the app's summary" % app['Summary'])
235 # Description size limit
236 desc_charcount = sum(len(l) for l in desc)
237 if desc_charcount > config['char_limits']['Description']:
238 warn("Description of length %s is over the %i char limit" % (
239 desc_charcount, config['char_limits']['Description']))
241 if (not desc[0] or not desc[-1]
242 or any(not desc[l - 1] and not desc[l] for l in range(1, len(desc)))):
243 warn("Description has an extra empty line")
245 # Check for lists using the wrong characters
246 validchars = ['*', '#']
249 for l in app['Description']:
253 for um in desc_url.finditer(l):
255 for m, r in http_warnings:
257 warn("URL '%s' in Description: %s" % (url, r))
259 c = l.decode('utf-8')[0]
262 if lcount > 3 and lchar not in validchars:
263 warn("Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar)
269 # Regex checks in all kinds of fields
270 for f in regex_warnings:
271 for m, r in regex_warnings[f]:
277 warn("%s '%s': %s" % (f, v, r))
278 elif type(v) == list:
281 warn("%s at line '%s': %s" % (f, l, r))
284 for build in app['builds']:
287 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
288 if build['commit'] and build['commit'].startswith(s):
289 warn("Branch '%s' used as commit in build '%s'" % (
290 s, build['version']))
291 for srclib in build['srclibs']:
292 ref = srclib.split('@')[1].split('/')[0]
293 if ref.startswith(s):
294 warn("Branch '%s' used as commit in srclib '%s'" % (
300 logging.info("Found a total of %i warnings in %i apps out of %i total." % (
301 count['warn'], count['app'], count['app_total']))
303 sys.exit(1 if count['warn'] > 0 else 0)
305 if __name__ == "__main__":