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
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('gitorious.org'),
38 enforce_https('apache.org'),
39 enforce_https('google.com'),
40 enforce_https('svn.code.sf.net'),
41 enforce_https('googlecode.com'),
44 http_warnings = https_enforcings + [
46 "HTTP links shouldn't end with a slash"),
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"),
64 # TODO enable in August 2015, when Google Code goes read-only
65 # (re.compile(r'.*://code\.google\.com/.*'),
66 # "code.google.com will be soon switching down, perhaps it moved to github.com?"),
68 'Changelog': http_warnings + [
71 (re.compile(r'^(|None|Unknown)$'),
72 "No license specified"),
76 "Summary yet to be filled"),
77 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
78 "No need to specify that the app is Free Software"),
79 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
80 "No need to specify that the app is for Android"),
81 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
82 "Punctuation should be avoided"),
85 (re.compile(r'^No description available$'),
86 "Description yet to be filled"),
87 (re.compile(r'\s*[*#][^ .]'),
88 "Invalid bulleted list"),
90 "Unnecessary leading space"),
91 (re.compile(r'.*\s$'),
92 "Unnecessary trailing space"),
98 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
99 "/issues is often enough on its own"),
106 global config, options, curid, count
117 print ' %s' % message
124 # Parse command line...
125 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
126 parser.add_option("-v", "--verbose", action="store_true", default=False,
127 help="Spew out even more information than normal")
128 parser.add_option("-q", "--quiet", action="store_true", default=False,
129 help="Restrict output to warnings and errors")
130 parser.add_option("-p", "--pedantic", action="store_true", default=False,
131 help="Show pedantic warnings that might give false positives")
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']):
152 # Potentially incorrect UCM
153 if (curbuild and curbuild['commit']
154 and app['Update Check Mode'] == 'RepoManifest'
155 and curbuild['commit'] != 'unknown - see disabled'
156 and any(s in curbuild['commit'] for s in '.,_-/')):
157 pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
158 curbuild['commit'], app['Update Check Mode']))
160 # Dangerous auto updates
161 if curbuild and app['Auto Update Mode'] != 'None':
162 for flag in ['target', 'srclibs', 'scanignore']:
164 pwarn("Auto Update Mode is enabled but '%s' is manually set at '%s'" % (flag, curbuild[flag]))
167 summ_chars = len(app['Summary'])
168 if summ_chars > config['char_limits']['Summary']:
169 warn("Summary of length %s is over the %i char limit" % (
170 summ_chars, config['char_limits']['Summary']))
173 if app['Web Site'] and app['Source Code']:
174 if app['Web Site'].lower() == app['Source Code'].lower():
175 warn("Website '%s' is just the app's source code link" % app['Web Site'])
177 # "None" still a category
178 if 'None' in app['Categories']:
179 warn("Category 'None' is is still present")
180 elif not app['Categories']:
181 warn("Categories are not set")
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))
215 # Regex pedantic checks in all kinds of fields
217 for f in regex_pedantic:
218 for m, r in regex_pedantic[f]:
220 warn("%s '%s': %s" % (f, app[f], r))
223 for build in app['builds']:
226 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
227 if build['commit'] and build['commit'].startswith(s):
228 warn("Branch '%s' used as commit in build '%s'" % (
229 s, build['version']))
230 for srclib in build['srclibs']:
231 ref = srclib.split('@')[1].split('/')[0]
232 if ref.startswith(s):
233 warn("Branch '%s' used as commit in srclib '%s'" % (
235 for s in ['git clone', 'git svn clone', 'svn checkout', 'svn co', 'hg clone']:
236 for flag in ['init', 'prebuild', 'build']:
240 # TODO: This should not be pedantic!
241 pwarn("'%s' used in %s '%s'" % (s, flag, build[flag]))
246 logging.info("Found a total of %i warnings in %i apps out of %i total." % (
247 count['warn'], count['app'], count['app_total']))
249 if __name__ == "__main__":