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
25 from collections import Counter
32 def enforce_https(domain):
33 return (re.compile(r'.*[^sS]://[^/]*' + re.escape(domain) + r'/.*'),
34 domain + " URLs should always use https://")
37 enforce_https('github.com'),
38 enforce_https('gitlab.com'),
39 enforce_https('gitorious.org'),
40 enforce_https('apache.org'),
41 enforce_https('google.com'),
42 enforce_https('svn.code.sf.net'),
43 enforce_https('googlecode.com'),
46 http_warnings = https_enforcings + [
47 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
48 "Appending .git is not necessary"),
49 # TODO enable in August 2015, when Google Code goes read-only
50 # (re.compile(r'.*://code\.google\.com/.*'),
51 # "code.google.com will be soon switching down, perhaps the project moved to github.com?"),
55 'Web Site': http_warnings + [
57 'Source Code': http_warnings + [
59 'Repo': https_enforcings + [
61 'Issue Tracker': http_warnings + [
62 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
63 "/issues is missing"),
65 'Changelog': http_warnings + [
68 (re.compile(r'^(|None|Unknown)$'),
69 "No license specified"),
73 "Summary yet to be filled"),
74 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
75 "No need to specify that the app is Free Software"),
76 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
77 "No need to specify that the app is for Android"),
78 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
79 "Punctuation should be avoided"),
82 (re.compile(r'^No description available$'),
83 "Description yet to be filled"),
84 (re.compile(r'\s*[*#][^ .]'),
85 "Invalid bulleted list"),
87 "Unnecessary leading space"),
88 (re.compile(r'.*\s$'),
89 "Unnecessary trailing space"),
103 "Science & Education",
112 global config, options, curid, count
123 print ' %s' % message
126 # Parse command line...
127 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
128 parser.add_option("-v", "--verbose", action="store_true", default=False,
129 help="Spew out even more information than normal")
130 parser.add_option("-q", "--quiet", action="store_true", default=False,
131 help="Restrict output to warnings and errors")
132 (options, args) = parser.parse_args()
134 config = common.read_config(options)
137 allapps = metadata.read_metadata(xref=False)
138 apps = common.read_app_args(args, allapps, False)
140 for appid, app in apps.iteritems():
145 count['app_total'] += 1
148 for build in app['builds']:
149 if not curbuild or int(build['vercode']) > int(curbuild['vercode']):
153 if (curbuild and curbuild['commit']
154 and app['Update Check Mode'] == 'RepoManifest'
155 and not curbuild['commit'].startswith('unknown')
156 and curbuild['vercode'] == app['Current Version Code']
157 and not curbuild['forcevercode']
158 and any(s in curbuild['commit'] for s in '.,_-/')):
159 warn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
160 curbuild['commit'], app['Update Check Mode']))
163 summ_chars = len(app['Summary'])
164 if summ_chars > config['char_limits']['Summary']:
165 warn("Summary of length %s is over the %i char limit" % (
166 summ_chars, config['char_limits']['Summary']))
169 if app['Web Site'] and app['Source Code']:
170 if app['Web Site'].lower() == app['Source Code'].lower():
171 warn("Website '%s' is just the app's source code link" % app['Web Site'])
173 # Missing or incorrect categories
174 if not app['Categories']:
175 warn("Categories are not set")
176 for categ in app['Categories']:
177 if categ not in categories:
178 warn("Category '%s' is not valid" % categ)
180 if app['Name'] and app['Name'] == app['Auto Name']:
181 warn("Name '%s' is just the auto name" % app['Name'])
183 name = app['Name'] or app['Auto Name']
184 if app['Summary'] and name:
185 if app['Summary'].lower() == name.lower():
186 warn("Summary '%s' is just the app's name" % app['Summary'])
188 desc = app['Description']
189 if app['Summary'] and desc and len(desc) == 1:
190 if app['Summary'].lower() == desc[0].lower():
191 warn("Description '%s' is just the app's summary" % app['Summary'])
193 # Description size limit
194 desc_charcount = sum(len(l) for l in desc)
195 if desc_charcount > config['char_limits']['Description']:
196 warn("Description of length %s is over the %i char limit" % (
197 desc_charcount, config['char_limits']['Description']))
199 if (not desc[0] or not desc[-1]
200 or any(not desc[l - 1] and not desc[l] for l in range(1, len(desc)))):
201 warn("Description has an extra empty line")
203 # Regex checks in all kinds of fields
204 for f in regex_warnings:
205 for m, r in regex_warnings[f]:
206 t = metadata.metafieldtype(f)
209 warn("%s '%s': %s" % (f, app[f], r))
210 elif t == 'multiline':
213 warn("%s at line '%s': %s" % (f, l, r))
216 for build in app['builds']:
219 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
220 if build['commit'] and build['commit'].startswith(s):
221 warn("Branch '%s' used as commit in build '%s'" % (
222 s, build['version']))
223 for srclib in build['srclibs']:
224 ref = srclib.split('@')[1].split('/')[0]
225 if ref.startswith(s):
226 warn("Branch '%s' used as commit in srclib '%s'" % (
232 logging.info("Found a total of %i warnings in %i apps out of %i total." % (
233 count['warn'], count['app'], count['app_total']))
235 if __name__ == "__main__":