mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 15:00:30 +03:00
Merge branch 'lint-unused-files' into 'master'
lint: error on unused files For now, this is just patch files. See merge request !124
This commit is contained in:
commit
bad9c3e804
1 changed files with 87 additions and 26 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -309,12 +310,67 @@ def check_builds(app):
|
||||||
yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
|
yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
|
||||||
|
|
||||||
|
|
||||||
|
def check_files_dir(app):
|
||||||
|
dir_path = os.path.join('metadata', app.id)
|
||||||
|
if not os.path.isdir(dir_path):
|
||||||
|
return
|
||||||
|
files = set()
|
||||||
|
for name in os.listdir(dir_path):
|
||||||
|
path = os.path.join(dir_path, name)
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
yield "Found non-file at %s" % path
|
||||||
|
continue
|
||||||
|
files.add(name)
|
||||||
|
|
||||||
|
used = set()
|
||||||
|
for build in app.builds:
|
||||||
|
for fname in build.patch:
|
||||||
|
if fname not in files:
|
||||||
|
yield "Unknown file %s in build '%s'" % (fname, build.version)
|
||||||
|
else:
|
||||||
|
used.add(fname)
|
||||||
|
|
||||||
|
for name in files.difference(used):
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
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:])
|
||||||
|
|
||||||
|
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.version)
|
||||||
|
else:
|
||||||
|
used.add(path)
|
||||||
|
|
||||||
|
for path in files.difference(used):
|
||||||
|
if any(path.endswith(s) for s in [
|
||||||
|
'.gitignore',
|
||||||
|
'source.txt', 'origin.txt', 'md5.txt',
|
||||||
|
'LICENSE', 'LICENSE.txt',
|
||||||
|
'COPYING', 'COPYING.txt',
|
||||||
|
'NOTICE', 'NOTICE.txt',
|
||||||
|
]):
|
||||||
|
continue
|
||||||
|
yield "Unused extlib at %s" % os.path.join(dir_path, path)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global config, options
|
global config, options
|
||||||
|
|
||||||
anywarns = False
|
|
||||||
|
|
||||||
# Parse command line...
|
# Parse command line...
|
||||||
parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
|
parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
|
||||||
common.setup_global_opts(parser)
|
common.setup_global_opts(parser)
|
||||||
|
|
@ -329,13 +385,21 @@ def main():
|
||||||
allapps = metadata.read_metadata(xref=True)
|
allapps = metadata.read_metadata(xref=True)
|
||||||
apps = common.read_app_args(options.appid, allapps, False)
|
apps = common.read_app_args(options.appid, allapps, False)
|
||||||
|
|
||||||
|
anywarns = False
|
||||||
|
|
||||||
|
apps_check_funcs = [
|
||||||
|
check_extlib_dir,
|
||||||
|
]
|
||||||
|
for check_func in apps_check_funcs:
|
||||||
|
for warn in check_func(apps.values()):
|
||||||
|
anywarns = True
|
||||||
|
print(warn)
|
||||||
|
|
||||||
for appid, app in apps.items():
|
for appid, app in apps.items():
|
||||||
if app.Disabled:
|
if app.Disabled:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
warns = []
|
app_check_funcs = [
|
||||||
|
|
||||||
for check_func in [
|
|
||||||
check_regexes,
|
check_regexes,
|
||||||
check_ucm_tags,
|
check_ucm_tags,
|
||||||
check_char_limits,
|
check_char_limits,
|
||||||
|
|
@ -348,16 +412,13 @@ def main():
|
||||||
check_mediawiki_links,
|
check_mediawiki_links,
|
||||||
check_bulleted_lists,
|
check_bulleted_lists,
|
||||||
check_builds,
|
check_builds,
|
||||||
]:
|
check_files_dir,
|
||||||
warns += check_func(app)
|
check_format,
|
||||||
|
]
|
||||||
|
|
||||||
if options.format:
|
for check_func in app_check_funcs:
|
||||||
if not rewritemeta.proper_format(app):
|
for warn in check_func(app):
|
||||||
warns.append("Run rewritemeta to fix formatting")
|
|
||||||
|
|
||||||
if warns:
|
|
||||||
anywarns = True
|
anywarns = True
|
||||||
for warn in warns:
|
|
||||||
print("%s: %s" % (appid, warn))
|
print("%s: %s" % (appid, warn))
|
||||||
|
|
||||||
if anywarns:
|
if anywarns:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue