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 (re.compile(r'.*[^sS]://github\.com/.*'),
33 "github URLs should always use https:// not http://"),
34 # TODO enable in August 2015, when Google Code goes read-only
35 # (re.compile(r'.*://code\.google\.com/.*'),
36 # "code.google.com will be soon switching down, perhaps it moved to github.com?"),
39 (re.compile(r'.*[^sS]://github\.com/.*'),
40 "github URLs should always use https:// (not http://, git://, or git@)"),
41 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
42 "dl.google.com URLs should always use https:// not http://"),
43 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
44 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
45 # TODO enable in August 2015, when Google Code goes read-only
46 # (re.compile(r'.*://code\.google\.com/.*'),
47 # "code.google.com will be soon switching down, perhaps it moved to github.com?"),
50 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
51 "dl.google.com URLs should always use https:// not http://"),
52 (re.compile(r'.*[^sS]://github\.com/.*'),
53 "github URLs should always use https:// (not http://, git://, or git@)"),
54 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
55 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
56 (re.compile(r'.*[^sS]://[^.]*\.googlecode\.com/svn/?.*'),
57 "Google Code SVN URLs should always use https:// (not http:// or svn://)"),
58 (re.compile(r'.*[^sS]://svn\.apache\.org/repos/?.*'),
59 "Apache SVN URLs should always use https:// (not http:// or svn://)"),
60 (re.compile(r'.*[^sS]://svn\.code\.sf\.net/.*'),
61 "Sourceforge SVN URLs should always use https:// (not http:// or svn://)"),
62 # TODO enable in August 2015, when Google Code goes read-only
63 # (re.compile(r'.*://code\.google\.com/.*'),
64 # "code.google.com will be soon switching down, perhaps it moved to github.com?"),
67 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
68 "/issues is missing"),
69 (re.compile(r'.*[^sS]://github\.com/.*'),
70 "github URLs should always use https:// not http://"),
71 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
72 "gitorious URLs should always use https:// not http://"),
73 # TODO enable in August 2015, when Google Code goes read-only
74 # (re.compile(r'.*://code\.google\.com/.*'),
75 # "code.google.com will be soon switching down, perhaps it moved to github.com?"),
78 (re.compile(r'^(|None|Unknown)$'),
79 "No license specified"),
83 "Summary yet to be filled"),
84 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
85 "No need to specify that the app is Free Software"),
86 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
87 "No need to specify that the app is for Android"),
90 (re.compile(r'^No description available$'),
91 "Description yet to be filled"),
92 (re.compile(r'\s*[*#][^ .]'),
93 "Invalid bulleted list"),
95 "Unnecessary leading space"),
96 (re.compile(r'.*\s$'),
97 "Unnecessary trailing space"),
103 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
104 "Appending .git is not necessary"),
107 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
108 "Appending .git is not necessary"),
111 (re.compile(r'^http://.*'),
112 "use https:// if available"),
113 (re.compile(r'^svn://.*'),
114 "use https:// if available"),
117 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
118 "/issues is often enough on its own"),
121 (re.compile(r'.*[a-z0-9][.!?][ $]'),
122 "Punctuation should be avoided"),
129 global config, options, curid, count
140 print ' %s' % message
147 # Parse command line...
148 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
149 parser.add_option("-v", "--verbose", action="store_true", default=False,
150 help="Spew out even more information than normal")
151 parser.add_option("-q", "--quiet", action="store_true", default=False,
152 help="Restrict output to warnings and errors")
153 parser.add_option("-p", "--pedantic", action="store_true", default=False,
154 help="Show pedantic warnings that might give false positives")
155 (options, args) = parser.parse_args()
157 config = common.read_config(options)
160 allapps = metadata.read_metadata(xref=False)
161 apps = common.read_app_args(args, allapps, False)
163 for appid, app in apps.iteritems():
168 count['app_total'] += 1
171 for build in app['builds']:
172 if not curbuild or int(build['vercode']) > int(curbuild['vercode']):
175 # Potentially incorrect UCM
176 if (curbuild and curbuild['commit']
177 and app['Update Check Mode'] == 'RepoManifest'
178 and curbuild['commit'] != 'unknown - see disabled'
179 and any(s in curbuild['commit'] for s in '.,_-/')):
180 pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
181 curbuild['commit'], app['Update Check Mode']))
183 # Dangerous auto updates
184 if curbuild and app['Auto Update Mode'] != 'None':
185 for flag in ['target', 'srclibs', 'scanignore']:
187 pwarn("Auto Update Mode is enabled but '%s' is manually set at '%s'" % (flag, curbuild[flag]))
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 # "None" still a category
201 if 'None' in app['Categories']:
202 warn("Category 'None' is is still present")
203 elif not app['Categories']:
204 warn("Categories are not set")
206 name = app['Name'] or app['Auto Name']
207 if app['Summary'] and name:
208 if app['Summary'].lower() == name.lower():
209 warn("Summary '%s' is just the app's name" % app['Summary'])
211 desc = app['Description']
212 if app['Summary'] and desc and len(desc) == 1:
213 if app['Summary'].lower() == desc[0].lower():
214 warn("Description '%s' is just the app's summary" % app['Summary'])
216 # Description size limit
217 desc_charcount = sum(len(l) for l in desc)
218 if desc_charcount > config['char_limits']['Description']:
219 warn("Description of length %s is over the %i char limit" % (
220 desc_charcount, config['char_limits']['Description']))
222 if (not desc[0] or not desc[-1]
223 or any(not desc[l - 1] and not desc[l] for l in range(1, len(desc)))):
224 warn("Description has an extra empty line")
226 # Regex checks in all kinds of fields
227 for f in regex_warnings:
228 for m, r in regex_warnings[f]:
229 t = metadata.metafieldtype(f)
232 warn("%s '%s': %s" % (f, app[f], r))
233 elif t == 'multiline':
236 warn("%s at line '%s': %s" % (f, l, r))
238 # Regex pedantic checks in all kinds of fields
240 for f in regex_pedantic:
241 for m, r in regex_pedantic[f]:
243 warn("%s '%s': %s" % (f, app[f], r))
246 for build in app['builds']:
249 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
250 if build['commit'] and build['commit'].startswith(s):
251 warn("Branch '%s' used as commit in build '%s'" % (
252 s, build['version']))
253 for srclib in build['srclibs']:
254 ref = srclib.split('@')[1].split('/')[0]
255 if ref.startswith(s):
256 warn("Branch '%s' used as commit in srclib '%s'" % (
258 for s in ['git clone', 'git svn clone', 'svn checkout', 'svn co', 'hg clone']:
259 for flag in ['init', 'prebuild', 'build']:
263 # TODO: This should not be pedantic!
264 pwarn("'%s' used in %s '%s'" % (s, flag, build[flag]))
269 logging.info("Found a total of %i warnings in %i apps out of %i total." % (
270 count['warn'], count['app'], count['app_total']))
272 if __name__ == "__main__":