# along with this program. If not, see <http://www.gnu.org/licenses/>.
from argparse import ArgumentParser
+import glob
import os
import re
import sys
+from . import _
from . import common
from . import metadata
from . import rewritemeta
enforce_https('bitbucket.org'),
enforce_https('apache.org'),
enforce_https('google.com'),
+ enforce_https('git.code.sf.net'),
enforce_https('svn.code.sf.net'),
+ enforce_https('anongit.kde.org'),
+ enforce_https('savannah.nongnu.org'),
+ enforce_https('git.savannah.nongnu.org'),
+ enforce_https('download.savannah.nongnu.org'),
+ enforce_https('savannah.gnu.org'),
+ enforce_https('git.savannah.gnu.org'),
+ enforce_https('download.savannah.gnu.org'),
]
def forbid_shortener(domain):
return (re.compile(r'https?://[^/]*' + re.escape(domain) + r'/.*'),
- "URL shorteners should not be used")
+ _("URL shorteners should not be used"))
http_url_shorteners = [
+ forbid_shortener('1url.com'),
+ forbid_shortener('adf.ly'),
+ forbid_shortener('bc.vc'),
+ forbid_shortener('bit.do'),
+ forbid_shortener('bit.ly'),
+ forbid_shortener('bitly.com'),
+ forbid_shortener('budurl.com'),
+ forbid_shortener('buzurl.com'),
+ forbid_shortener('cli.gs'),
+ forbid_shortener('cur.lv'),
+ forbid_shortener('cutt.us'),
+ forbid_shortener('db.tt'),
+ forbid_shortener('filoops.info'),
forbid_shortener('goo.gl'),
- forbid_shortener('t.co'),
- forbid_shortener('ur1.ca'),
forbid_shortener('is.gd'),
- forbid_shortener('bit.ly'),
+ forbid_shortener('ity.im'),
+ forbid_shortener('j.mp'),
+ forbid_shortener('l.gg'),
+ forbid_shortener('lnkd.in'),
+ forbid_shortener('moourl.com'),
+ forbid_shortener('ow.ly'),
+ forbid_shortener('para.pt'),
+ forbid_shortener('po.st'),
+ forbid_shortener('q.gs'),
+ forbid_shortener('qr.ae'),
+ forbid_shortener('qr.net'),
+ forbid_shortener('rdlnk.com'),
+ forbid_shortener('scrnch.me'),
+ forbid_shortener('short.nr'),
+ forbid_shortener('sn.im'),
+ forbid_shortener('snipurl.com'),
+ forbid_shortener('su.pr'),
+ forbid_shortener('t.co'),
forbid_shortener('tiny.cc'),
+ forbid_shortener('tinyarrows.com'),
forbid_shortener('tinyurl.com'),
+ forbid_shortener('tr.im'),
+ forbid_shortener('tweez.me'),
+ forbid_shortener('twitthis.com'),
+ forbid_shortener('twurl.nl'),
+ forbid_shortener('tyn.ee'),
+ forbid_shortener('u.bb'),
+ forbid_shortener('u.to'),
+ forbid_shortener('ur1.ca'),
+ forbid_shortener('urlof.site'),
+ forbid_shortener('v.gd'),
+ forbid_shortener('vzturl.com'),
+ forbid_shortener('x.co'),
+ forbid_shortener('xrl.us'),
+ forbid_shortener('yourls.org'),
+ forbid_shortener('zip.net'),
+ forbid_shortener('✩.ws'),
+ forbid_shortener('➡.ws'),
]
http_checks = https_enforcings + http_url_shorteners + [
(re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
- "Appending .git is not necessary"),
+ _("Appending .git is not necessary")),
(re.compile(r'.*://[^/]*(github|gitlab|bitbucket|rawgit)[^/]*/([^/]+/){1,3}master'),
- "Use /HEAD instead of /master to point at a file in the default branch"),
+ _("Use /HEAD instead of /master to point at a file in the default branch")),
]
regex_checks = {
'Repo': https_enforcings,
'IssueTracker': http_checks + [
(re.compile(r'.*github\.com/[^/]+/[^/]+/*$'),
- "/issues is missing"),
+ _("/issues is missing")),
(re.compile(r'.*gitlab\.com/[^/]+/[^/]+/*$'),
- "/issues is missing"),
+ _("/issues is missing")),
],
'Donate': http_checks + [
(re.compile(r'.*flattr\.com'),
- "Flattr donation methods belong in the FlattrID flag"),
+ _("Flattr donation methods belong in the FlattrID flag")),
+ (re.compile(r'.*liberapay\.com'),
+ _("Liberapay donation methods belong in the LiberapayID flag")),
],
'Changelog': http_checks,
'Author Name': [
(re.compile(r'^\s'),
- "Unnecessary leading space"),
+ _("Unnecessary leading space")),
(re.compile(r'.*\s$'),
- "Unnecessary trailing space"),
+ _("Unnecessary trailing space")),
],
'Summary': [
- (re.compile(r'^$'),
- "Summary yet to be filled"),
(re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
- "No need to specify that the app is Free Software"),
+ _("No need to specify that the app is Free Software")),
(re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
- "No need to specify that the app is for Android"),
+ _("No need to specify that the app is for Android")),
(re.compile(r'.*[a-z0-9][.!?]( |$)'),
- "Punctuation should be avoided"),
+ _("Punctuation should be avoided")),
(re.compile(r'^\s'),
- "Unnecessary leading space"),
+ _("Unnecessary leading space")),
(re.compile(r'.*\s$'),
- "Unnecessary trailing space"),
+ _("Unnecessary trailing space")),
],
- 'Description': [
- (re.compile(r'^No description available$'),
- "Description yet to be filled"),
+ 'Description': https_enforcings + http_url_shorteners + [
(re.compile(r'\s*[*#][^ .]'),
- "Invalid bulleted list"),
+ _("Invalid bulleted list")),
(re.compile(r'^\s'),
- "Unnecessary leading space"),
+ _("Unnecessary leading space")),
(re.compile(r'.*\s$'),
- "Unnecessary trailing space"),
- (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
- "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
- (re.compile(r'(^|.* )https?://[^ ]+'),
- "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
+ _("Unnecessary trailing space")),
+ (re.compile(r'.*<(applet|base|body|button|embed|form|head|html|iframe|img|input|link|object|picture|script|source|style|svg|video).*', re.IGNORECASE),
+ _("Forbidden HTML tags")),
+ (re.compile(r'''.*\s+src=["']javascript:.*'''),
+ _("Javascript in HTML src attributes")),
],
}
and lastbuild.versionCode == app.CurrentVersionCode
and not lastbuild.forcevercode
and any(s in lastbuild.commit for s in '.,_-/')):
- yield "Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
- lastbuild.commit, app.UpdateCheckMode)
+ yield _("Last used commit '{commit}' looks like a tag, but Update Check Mode is '{ucm}'")\
+ .format(commit=lastbuild.commit, ucm=app.UpdateCheckMode)
def check_char_limits(app):
limits = config['char_limits']
if len(app.Summary) > limits['summary']:
- yield "Summary of length %s is over the %i char limit" % (
- len(app.Summary), limits['summary'])
+ yield _("Summary of length {length} is over the {limit} char limit")\
+ .format(length=len(app.Summary), limit=limits['summary'])
if len(app.Description) > limits['description']:
- yield "Description of length %s is over the %i char limit" % (
- len(app.Description), limits['description'])
+ yield _("Description of length {length} is over the {limit} char limit")\
+ .format(length=len(app.Description), limit=limits['description'])
def check_old_links(app):
for f in ['WebSite', 'SourceCode', 'IssueTracker', 'Changelog']:
v = app.get(f)
if any(s in v for s in old_sites):
- yield "App is in '%s' but has a link to '%s'" % (app.Repo, v)
+ yield _("App is in '{repo}' but has a link to {url}")\
+ .format(repo=app.Repo, url=v)
def check_useless_fields(app):
if app.UpdateCheckName == app.id:
- yield "Update Check Name is set to the known app id - it can be removed"
+ yield _("Update Check Name is set to the known app id - it can be removed")
filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
def check_checkupdates_ran(app):
if filling_ucms.match(app.UpdateCheckMode):
if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == '0':
- yield "UCM is set but it looks like checkupdates hasn't been run yet"
+ yield _("UCM is set but it looks like checkupdates hasn't been run yet")
def check_empty_fields(app):
if not app.Categories:
- yield "Categories are not set"
+ yield _("Categories are not set")
all_categories = set([
def check_categories(app):
for categ in app.Categories:
if categ not in all_categories:
- yield "Category '%s' is not valid" % categ
+ yield _("Category '%s' is not valid" % categ)
def check_duplicates(app):
if app.Name and app.Name == app.AutoName:
- yield "Name '%s' is just the auto name - remove it" % app.Name
+ yield _("Name '%s' is just the auto name - remove it") % app.Name
links_seen = set()
for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
continue
v = v.lower()
if v in links_seen:
- yield "Duplicate link in '%s': %s" % (f, v)
+ yield _("Duplicate link in '{field}': {url}").format(field=f, url=v)
else:
links_seen.add(v)
name = app.Name or app.AutoName
if app.Summary and name:
if app.Summary.lower() == name.lower():
- yield "Summary '%s' is just the app's name" % app.Summary
+ yield _("Summary '%s' is just the app's name") % app.Summary
if app.Summary and app.Description and len(app.Description) == 1:
if app.Summary.lower() == app.Description[0].lower():
- yield "Description '%s' is just the app's summary" % app.Summary
+ yield _("Description '%s' is just the app's summary") % app.Summary
seenlines = set()
for l in app.Description.splitlines():
if len(l) < 1:
continue
if l in seenlines:
- yield "Description has a duplicate line"
+ yield _("Description has a duplicate line")
seenlines.add(l)
url = um.group(1)
for m, r in http_checks:
if m.match(url):
- yield "URL '%s' in Description: %s" % (url, r)
+ yield _("URL {url} in Description: {error}").format(url=url, error=r)
def check_bulleted_lists(app):
if l[0] == lchar and l[1] == ' ':
lcount += 1
if lcount > 2 and lchar not in validchars:
- yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
+ yield _("Description has a list (%s) but it isn't bulleted (*) nor numbered (#)") % lchar
break
else:
lchar = l[0]
def check_builds(app):
+ supported_flags = set(metadata.build_flags)
+ # needed for YAML and JSON
for build in app.builds:
if build.disable:
if build.disable.startswith('Generated by import.py'):
- yield "Build generated by `fdroid import` - remove disable line once ready"
+ yield _("Build generated by `fdroid import` - remove disable line once ready")
continue
for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
if build.commit and build.commit.startswith(s):
- yield "Branch '%s' used as commit in build '%s'" % (s, build.versionName)
+ yield _("Branch '{branch}' used as commit in build '{versionName}'")\
+ .format(branch=s, versionName=build.versionName)
for srclib in build.srclibs:
- ref = srclib.split('@')[1].split('/')[0]
- if ref.startswith(s):
- yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
+ if '@' in srclib:
+ ref = srclib.split('@')[1].split('/')[0]
+ if ref.startswith(s):
+ yield _("Branch '{branch}' used as commit in srclib '{srclib}'")\
+ .format(branch=s, srclib=srclib)
+ else:
+ yield _('srclibs missing name and/or @') + ' (srclibs: ' + srclib + ')'
+ for key in build.keys():
+ if key not in supported_flags:
+ yield _('%s is not an accepted build field') % key
def check_files_dir(app):
for name in os.listdir(dir_path):
path = os.path.join(dir_path, name)
if not (os.path.isfile(path) or name == 'signatures' or locale_pattern.match(name)):
- yield "Found non-file at %s" % path
+ yield _("Found non-file at %s") % path
continue
files.add(name)
for build in app.builds:
for fname in build.patch:
if fname not in files:
- yield "Unknown file %s in build '%s'" % (fname, build.versionName)
+ yield _("Unknown file '{filename}' in build '{versionName}'")\
+ .format(filename=fname, versionName=build.versionName)
else:
used.add(fname)
for name in files.difference(used):
if locale_pattern.match(name):
continue
- yield "Unused file at %s" % os.path.join(dir_path, name)
+ yield _("Unused file at %s") % os.path.join(dir_path, name)
def check_format(app):
if options.format and not rewritemeta.proper_format(app):
- yield "Run rewritemeta to fix formatting"
+ yield _("Run rewritemeta to fix formatting")
def check_license_tag(app):
'''Ensure all license tags are in https://spdx.org/license-list'''
if app.License.rstrip('+') not in SPDX:
- yield 'Invalid license tag "%s"! Use only tags from https://spdx.org/license-list' \
+ yield _('Invalid license tag "%s"! Use only tags from https://spdx.org/license-list') \
% (app.License)
def check_extlib_dir(apps):
dir_path = os.path.join('build', 'extlib')
- files = set()
- for root, dirs, names in os.walk(dir_path):
- for name in names:
- files.add(os.path.join(root, name)[len(dir_path) + 1:])
+ unused_extlib_files = set()
+ for root, dirs, files in os.walk(dir_path):
+ for name in files:
+ unused_extlib_files.add(os.path.join(root, name)[len(dir_path) + 1:])
used = set()
for app in apps:
for build in app.builds:
for path in build.extlibs:
- if path not in files:
- yield "%s: Unknown extlib %s in build '%s'" % (app.id, path, build.versionName)
+ if path not in unused_extlib_files:
+ yield _("{appid}: Unknown extlib {path} in build '{versionName}'")\
+ .format(appid=app.id, path=path, versionName=build.versionName)
else:
used.add(path)
- for path in files.difference(used):
+ for path in unused_extlib_files.difference(used):
if any(path.endswith(s) for s in [
'.gitignore',
'source.txt', 'origin.txt', 'md5.txt',
'NOTICE', 'NOTICE.txt',
]):
continue
- yield "Unused extlib at %s" % os.path.join(dir_path, path)
+ yield _("Unused extlib at %s") % os.path.join(dir_path, path)
+
+
+def check_for_unsupported_metadata_files(basedir=""):
+ """Checks whether any non-metadata files are in metadata/"""
+
+ global config
+
+ return_value = False
+ formats = config['accepted_formats']
+ for f in glob.glob(basedir + 'metadata/*') + glob.glob(basedir + 'metadata/.*'):
+ if os.path.isdir(f):
+ exists = False
+ for t in formats:
+ exists = exists or os.path.exists(f + '.' + t)
+ if not exists:
+ print(_('"%s/" has no matching metadata file!') % f)
+ return_value = True
+ elif not os.path.splitext(f)[1][1:] in formats:
+ print('"' + f.replace(basedir, '')
+ + '" is not a supported file format: (' + ','.join(formats) + ')')
+ return_value = True
+
+ return return_value
def main():
parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
common.setup_global_opts(parser)
parser.add_argument("-f", "--format", action="store_true", default=False,
- help="Also warn about formatting issues, like rewritemeta -l")
- parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
+ help=_("Also warn about formatting issues, like rewritemeta -l"))
+ parser.add_argument("appid", nargs='*', help=_("applicationId in the form APPID"))
metadata.add_metadata_arguments(parser)
options = parser.parse_args()
metadata.warnings_action = options.W
allapps = metadata.read_metadata(xref=True)
apps = common.read_app_args(options.appid, allapps, False)
- anywarns = False
+ anywarns = check_for_unsupported_metadata_files()
apps_check_funcs = []
if len(options.appid) == 0: