1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-04 14:30:11 +01:00

Simplify post_metadata_parse usage

This commit is contained in:
Daniel Martí 2015-12-02 22:29:31 +01:00
parent c975531d87
commit 528e45d22b

View File

@ -793,13 +793,6 @@ def post_metadata_parse(app):
if type(v) in (float, int): if type(v) in (float, int):
app.set_field(f, str(v)) app.set_field(f, str(v))
# convert to the odd internal format
for f in ('Description', 'Maintainer Notes'):
v = app.get_field(f)
if isinstance(v, basestring):
text = v.rstrip().lstrip()
app.set_field(f, text.split('\n'))
for build in app.builds: for build in app.builds:
for k in build_flags: for k in build_flags:
v = build.get_flag(k) v = build.get_flag(k)
@ -820,6 +813,13 @@ def post_metadata_parse(app):
if isinstance(v, bool) and v: if isinstance(v, bool) and v:
build.set_flag(k, 'yes') build.set_flag(k, 'yes')
# convert to the odd internal format
for f in ('Description', 'Maintainer Notes'):
v = app.get_field(f)
if isinstance(v, basestring):
text = v.rstrip().lstrip()
app.set_field(f, text.split('\n'))
if not app.Description: if not app.Description:
app.Description = ['No description available'] app.Description = ['No description available']
@ -891,17 +891,21 @@ def parse_metadata(metadatapath):
+ 'convert to: ' + ', '.join(accepted)) + 'convert to: ' + ', '.join(accepted))
sys.exit(1) sys.exit(1)
app = None
if ext == 'txt': if ext == 'txt':
return parse_txt_metadata(metadatapath) app = parse_txt_metadata(metadatapath)
if ext == 'json': elif ext == 'json':
return parse_json_metadata(metadatapath) app = parse_json_metadata(metadatapath)
if ext == 'xml': elif ext == 'xml':
return parse_xml_metadata(metadatapath) app = parse_xml_metadata(metadatapath)
if ext == 'yaml': elif ext == 'yaml':
return parse_yaml_metadata(metadatapath) app = parse_yaml_metadata(metadatapath)
else:
logging.critical('Unknown metadata format: ' + metadatapath)
sys.exit(1)
logging.critical('Unknown metadata format: ' + metadatapath) post_metadata_parse(app)
sys.exit(1) return app
def parse_json_metadata(metadatapath): def parse_json_metadata(metadatapath):
@ -916,8 +920,6 @@ def parse_json_metadata(metadatapath):
parse_int=lambda s: s, parse_int=lambda s: s,
parse_float=lambda s: s) parse_float=lambda s: s)
app.update_fields(jsoninfo) app.update_fields(jsoninfo)
post_metadata_parse(app)
return app return app
@ -956,8 +958,6 @@ def parse_xml_metadata(metadatapath):
else: else:
app.RequiresRoot = False app.RequiresRoot = False
post_metadata_parse(app)
return app return app
@ -967,8 +967,6 @@ def parse_yaml_metadata(metadatapath):
yamlinfo = yaml.load(open(metadatapath, 'r'), Loader=YamlLoader) yamlinfo = yaml.load(open(metadatapath, 'r'), Loader=YamlLoader)
app.update_fields(yamlinfo) app.update_fields(yamlinfo)
post_metadata_parse(app)
return app return app
@ -1156,8 +1154,6 @@ def parse_txt_metadata(metadatapath):
elif mode == 3: elif mode == 3:
raise MetaDataException("Unterminated build in " + metafile.name) raise MetaDataException("Unterminated build in " + metafile.name)
post_metadata_parse(app)
return app return app