mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-17 18:50:11 +02:00
lint: optionally check format
This commit is contained in:
parent
fa0dcf5449
commit
c2304b3315
@ -19,11 +19,13 @@
|
|||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import re
|
import re
|
||||||
import common
|
|
||||||
import metadata
|
|
||||||
import sys
|
import sys
|
||||||
from sets import Set
|
from sets import Set
|
||||||
|
|
||||||
|
import common
|
||||||
|
import metadata
|
||||||
|
import rewritemeta
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
options = None
|
options = None
|
||||||
|
|
||||||
@ -306,6 +308,8 @@ def main():
|
|||||||
# 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)
|
||||||
|
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")
|
parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
@ -337,6 +341,10 @@ def main():
|
|||||||
]:
|
]:
|
||||||
warns += check_func(app)
|
warns += check_func(app)
|
||||||
|
|
||||||
|
if options.format:
|
||||||
|
if not rewritemeta.proper_format(app):
|
||||||
|
warns.append("Run rewritemeta to fix formatting")
|
||||||
|
|
||||||
if warns:
|
if warns:
|
||||||
anywarns = True
|
anywarns = True
|
||||||
for warn in warns:
|
for warn in warns:
|
||||||
|
@ -33,6 +33,18 @@ config = None
|
|||||||
options = None
|
options = None
|
||||||
|
|
||||||
|
|
||||||
|
def proper_format(app):
|
||||||
|
s = StringIO()
|
||||||
|
# TODO: currently reading entire file again, should reuse first
|
||||||
|
# read in metadata.py
|
||||||
|
with open(app.metadatapath, 'r') as f:
|
||||||
|
cur_content = f.read()
|
||||||
|
metadata.write_txt_metadata(s, app)
|
||||||
|
content = s.getvalue()
|
||||||
|
s.close()
|
||||||
|
return content == cur_content
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global config, options
|
global config, options
|
||||||
@ -62,10 +74,9 @@ def main():
|
|||||||
parser.error("Must give a valid format to --to")
|
parser.error("Must give a valid format to --to")
|
||||||
|
|
||||||
for appid, app in apps.iteritems():
|
for appid, app in apps.iteritems():
|
||||||
metadatapath = app.metadatapath
|
base, ext = common.get_extension(app.metadatapath)
|
||||||
base, ext = common.get_extension(metadatapath)
|
|
||||||
if not options.to and ext not in supported:
|
if not options.to and ext not in supported:
|
||||||
logging.info("Ignoring %s file at '%s'" % (ext, metadatapath))
|
logging.info("Ignoring %s file at '%s'" % (ext, app.metadatapath))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
to_ext = ext
|
to_ext = ext
|
||||||
@ -73,23 +84,15 @@ def main():
|
|||||||
to_ext = options.to
|
to_ext = options.to
|
||||||
|
|
||||||
if options.list:
|
if options.list:
|
||||||
s = StringIO()
|
if not proper_format(app):
|
||||||
# TODO: currently reading entire file again, should reuse first
|
print app.metadatapath
|
||||||
# read in metadata.py
|
|
||||||
with open(metadatapath, 'r') as f:
|
|
||||||
cur_content = f.read()
|
|
||||||
metadata.write_txt_metadata(s, app)
|
|
||||||
content = s.getvalue()
|
|
||||||
s.close()
|
|
||||||
if content != cur_content:
|
|
||||||
print(metadatapath)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open(base + '.' + to_ext, 'w') as f:
|
with open(base + '.' + to_ext, 'w') as f:
|
||||||
metadata.write_metadata(to_ext, f, app)
|
metadata.write_metadata(to_ext, f, app)
|
||||||
|
|
||||||
if ext != to_ext:
|
if ext != to_ext:
|
||||||
os.remove(metadatapath)
|
os.remove(app.metadatapath)
|
||||||
|
|
||||||
logging.debug("Finished.")
|
logging.debug("Finished.")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user