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
23 import common, metadata
30 (re.compile(r'.*[^sS]://github\.com/.*'),
31 "github URLs should always use https:// not http://"),
32 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
33 "code.google.com URLs should always use https:// not http://"),
36 (re.compile(r'.*[^sS]://github\.com/.*'),
37 "github URLs should always use https:// (not http://, git://, or git@)"),
38 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
39 "/source is missing"),
40 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
41 "code.google.com URLs should always use https:// not http://"),
42 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
43 "dl.google.com URLs should always use https:// not http://"),
44 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
45 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
48 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
49 "code.google.com URLs should always use https:// not http://"),
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://)"),
64 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
65 "/issues is missing"),
66 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
67 "code.google.com URLs should always use https:// not http://"),
68 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
69 "/issues is missing"),
70 (re.compile(r'.*[^sS]://github\.com/.*'),
71 "github URLs should always use https:// not http://"),
72 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
73 "gitorious URLs should always use https:// not http://"),
79 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
80 "Appending .git is not necessary"),
81 (re.compile(r'.*code\.google\.com/p/[^/]+/[^w]'),
82 "Possible incorrect path appended to google code project site"),
85 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
86 "Appending .git is not necessary"),
87 (re.compile(r'.*code\.google\.com/p/[^/]+/source/.*'),
88 "/source is often enough on its own"),
91 (re.compile(r'^http://.*'),
92 "if https:// is available, use it instead of http://"),
93 (re.compile(r'^svn://.*'),
94 "if https:// is available, use it instead of svn://"),
97 (re.compile(r'.*code\.google\.com/p/[^/]+/issues/.*'),
98 "/issues is often enough on its own"),
99 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
100 "/issues is often enough on its own"),
103 (re.compile(r'.*\bandroid\b.*', re.IGNORECASE),
104 "No need to specify that the app is for Android"),
105 (re.compile(r'.*\b(app|application)\b.*', re.IGNORECASE),
106 "No need to specify that the app is... an app"),
107 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
108 "No need to specify that the app is Free Software"),
109 (re.compile(r'.*[a-z0-9][.,!?][ $]'),
110 "Punctuation should be avoided"),
118 global config, options, appid
125 print ' %s' % message
132 # Parse command line...
133 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
134 parser.add_option("-p", "--pedantic", action="store_true", default=False,
135 help="Show pedantic warnings that might give false positives")
136 parser.add_option("-v", "--verbose", action="store_true", default=False,
137 help="Spew out even more information than normal")
138 (options, args) = parser.parse_args()
140 config = common.read_config(options)
143 allapps = metadata.read_metadata(xref=False)
144 apps = common.read_app_args(args, allapps, False)
153 for build in app['builds']:
154 if 'commit' in build and 'disable' not in build:
155 lastcommit = build['commit']
157 # Potentially incorrect UCM
158 if (app['Update Check Mode'] == 'RepoManifest' and
159 any(s in lastcommit for s in '.,_-/')):
160 pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
161 lastcommit, app['Update Check Mode']))
164 if app['License'] == 'Unknown':
165 warn("License was not properly set")
168 summ_chars = len(app['Summary'])
169 if summ_chars > config['char_limits']['Summary']:
170 warn("Summary of length %s is over the %i char limit" % (
171 summ_chars, config['char_limits']['Summary']))
175 for line in app['Description']:
176 if re.match(r'[ ]*[*#][^ .]', line):
177 warn("Invalid bulleted list: '%s'" % line)
178 desc_chars += len(line)
180 # Description size limit
181 if desc_chars > config['char_limits']['Description']:
182 warn("Description of length %s is over the %i char limit" % (
183 desc_chars, config['char_limits']['Description']))
185 # Regex checks in all kinds of fields
186 for f in regex_warnings:
187 for m, r in regex_warnings[f]:
189 warn("%s '%s': %s" % (f, app[f], r))
191 # Regex pedantic checks in all kinds of fields
193 for f in regex_pedantic:
194 for m, r in regex_pedantic[f]:
196 warn("%s '%s': %s" % (f, app[f], r))
199 for build in app['builds']:
200 for n in ['master', 'origin/', 'default', 'trunk']:
201 if 'commit' in build:
202 if build['commit'].startswith(n):
203 warn("Branch '%s' used as commit in build '%s'" % (
204 n, build['version']))
205 if 'srclibs' in build:
206 for srclib in build['srclibs']:
207 ref = srclib.split('@')[1].split('/')[0]
208 if ref.startswith(n):
209 warn("Branch '%s' used as commit in srclib '%s'" % (
215 logging.info("Finished.")
217 if __name__ == "__main__":