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('gitlab.com'),
38 enforce_https('gitorious.org'),
39 enforce_https('apache.org'),
40 enforce_https('google.com'),
41 enforce_https('svn.code.sf.net'),
42 enforce_https('googlecode.com'),
45 http_warnings = https_enforcings + [
46 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
47 "Appending .git is not necessary"),
48 # TODO enable in August 2015, when Google Code goes read-only
49 # (re.compile(r'.*://code\.google\.com/.*'),
50 # "code.google.com will be soon switching down, perhaps the project moved to github.com?"),
54 'Web Site': http_warnings + [
56 'Source Code': http_warnings + [
58 'Repo': https_enforcings + [
60 'Issue Tracker': http_warnings + [
61 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
62 "/issues is missing"),
64 'Changelog': http_warnings + [
67 (re.compile(r'^(|None|Unknown)$'),
68 "No license specified"),
72 "Summary yet to be filled"),
73 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
74 "No need to specify that the app is Free Software"),
75 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
76 "No need to specify that the app is for Android"),
77 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
78 "Punctuation should be avoided"),
81 (re.compile(r'^No description available$'),
82 "Description yet to be filled"),
83 (re.compile(r'\s*[*#][^ .]'),
84 "Invalid bulleted list"),
86 "Unnecessary leading space"),
87 (re.compile(r'.*\s$'),
88 "Unnecessary trailing space"),
95 global config, options, curid, count
106 print ' %s' % message
113 # Parse command line...
114 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
115 parser.add_option("-v", "--verbose", action="store_true", default=False,
116 help="Spew out even more information than normal")
117 parser.add_option("-q", "--quiet", action="store_true", default=False,
118 help="Restrict output to warnings and errors")
119 parser.add_option("-p", "--pedantic", action="store_true", default=False,
120 help="Show pedantic warnings that might give false positives")
121 (options, args) = parser.parse_args()
123 config = common.read_config(options)
126 allapps = metadata.read_metadata(xref=False)
127 apps = common.read_app_args(args, allapps, False)
129 for appid, app in apps.iteritems():
134 count['app_total'] += 1
137 for build in app['builds']:
138 if not curbuild or int(build['vercode']) > int(curbuild['vercode']):
141 # Potentially incorrect UCM
142 if (curbuild and curbuild['commit']
143 and app['Update Check Mode'] == 'RepoManifest'
144 and not curbuild['commit'].startswith('unknown')
145 and curbuild['vercode'] == app['Current Version Code']
146 and any(s in curbuild['commit'] for s in '.,_-/')):
147 warn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
148 curbuild['commit'], app['Update Check Mode']))
150 # Dangerous auto updates
151 if curbuild and app['Auto Update Mode'] != 'None':
152 for flag in ['target', 'srclibs', 'scanignore']:
154 pwarn("Auto Update Mode is enabled but '%s' is manually set at '%s'" % (flag, curbuild[flag]))
157 summ_chars = len(app['Summary'])
158 if summ_chars > config['char_limits']['Summary']:
159 warn("Summary of length %s is over the %i char limit" % (
160 summ_chars, config['char_limits']['Summary']))
163 if app['Web Site'] and app['Source Code']:
164 if app['Web Site'].lower() == app['Source Code'].lower():
165 warn("Website '%s' is just the app's source code link" % app['Web Site'])
167 # "None" still a category
168 if 'None' in app['Categories']:
169 warn("Category 'None' is is still present")
170 elif not app['Categories']:
171 warn("Categories are not set")
173 if app['Name'] and app['Name'] == app['Auto Name']:
174 warn("Name '%s' is just the auto name" % app['Name'])
176 name = app['Name'] or app['Auto Name']
177 if app['Summary'] and name:
178 if app['Summary'].lower() == name.lower():
179 warn("Summary '%s' is just the app's name" % app['Summary'])
181 desc = app['Description']
182 if app['Summary'] and desc and len(desc) == 1:
183 if app['Summary'].lower() == desc[0].lower():
184 warn("Description '%s' is just the app's summary" % app['Summary'])
186 # Description size limit
187 desc_charcount = sum(len(l) for l in desc)
188 if desc_charcount > config['char_limits']['Description']:
189 warn("Description of length %s is over the %i char limit" % (
190 desc_charcount, config['char_limits']['Description']))
192 if (not desc[0] or not desc[-1]
193 or any(not desc[l - 1] and not desc[l] for l in range(1, len(desc)))):
194 warn("Description has an extra empty line")
196 # Regex checks in all kinds of fields
197 for f in regex_warnings:
198 for m, r in regex_warnings[f]:
199 t = metadata.metafieldtype(f)
202 warn("%s '%s': %s" % (f, app[f], r))
203 elif t == 'multiline':
206 warn("%s at line '%s': %s" % (f, l, r))
209 for build in app['builds']:
212 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
213 if build['commit'] and build['commit'].startswith(s):
214 warn("Branch '%s' used as commit in build '%s'" % (
215 s, build['version']))
216 for srclib in build['srclibs']:
217 ref = srclib.split('@')[1].split('/')[0]
218 if ref.startswith(s):
219 warn("Branch '%s' used as commit in srclib '%s'" % (
225 logging.info("Found a total of %i warnings in %i apps out of %i total." % (
226 count['warn'], count['app'], count['app_total']))
228 if __name__ == "__main__":