mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-04 14:30:11 +01:00
Open metadata files in only one place
Also get rid of the useless get_default_app_info func.
This commit is contained in:
parent
c2304b3315
commit
013315bf10
@ -174,8 +174,7 @@ def main():
|
|||||||
config = common.read_config(options)
|
config = common.read_config(options)
|
||||||
|
|
||||||
apps = metadata.read_metadata()
|
apps = metadata.read_metadata()
|
||||||
app = metadata.get_default_app_info()
|
app = metadata.App()
|
||||||
app.id = None
|
|
||||||
app.UpdateCheckMode = "Tags"
|
app.UpdateCheckMode = "Tags"
|
||||||
|
|
||||||
root_dir = None
|
root_dir = None
|
||||||
|
@ -952,15 +952,19 @@ def parse_metadata(metadatapath):
|
|||||||
raise MetaDataException('"%s" is not an accepted format, convert to: %s' % (
|
raise MetaDataException('"%s" is not an accepted format, convert to: %s' % (
|
||||||
metadatapath, ', '.join(accepted)))
|
metadatapath, ', '.join(accepted)))
|
||||||
|
|
||||||
app = None
|
app = App()
|
||||||
|
app.metadatapath = metadatapath
|
||||||
|
app.id, _ = common.get_extension(os.path.basename(metadatapath))
|
||||||
|
|
||||||
|
with open(metadatapath, 'r') as mf:
|
||||||
if ext == 'txt':
|
if ext == 'txt':
|
||||||
app = parse_txt_metadata(metadatapath)
|
parse_txt_metadata(mf, app)
|
||||||
elif ext == 'json':
|
elif ext == 'json':
|
||||||
app = parse_json_metadata(metadatapath)
|
parse_json_metadata(mf, app)
|
||||||
elif ext == 'xml':
|
elif ext == 'xml':
|
||||||
app = parse_xml_metadata(metadatapath)
|
parse_xml_metadata(mf, app)
|
||||||
elif ext == 'yaml':
|
elif ext == 'yaml':
|
||||||
app = parse_yaml_metadata(metadatapath)
|
parse_yaml_metadata(mf, app)
|
||||||
else:
|
else:
|
||||||
raise MetaDataException('Unknown metadata format: %s' % metadatapath)
|
raise MetaDataException('Unknown metadata format: %s' % metadatapath)
|
||||||
|
|
||||||
@ -968,16 +972,12 @@ def parse_metadata(metadatapath):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def parse_json_metadata(metadatapath):
|
def parse_json_metadata(mf, app):
|
||||||
|
|
||||||
app = get_default_app_info(metadatapath)
|
|
||||||
|
|
||||||
# fdroid metadata is only strings and booleans, no floats or ints. And
|
# fdroid metadata is only strings and booleans, no floats or ints. And
|
||||||
# json returns unicode, and fdroidserver still uses plain python strings
|
# json returns unicode, and fdroidserver still uses plain python strings
|
||||||
# TODO create schema using https://pypi.python.org/pypi/jsonschema
|
# TODO create schema using https://pypi.python.org/pypi/jsonschema
|
||||||
jsoninfo = None
|
jsoninfo = json.load(mf, object_hook=_decode_dict,
|
||||||
with open(metadatapath, 'r') as f:
|
|
||||||
jsoninfo = json.load(f, object_hook=_decode_dict,
|
|
||||||
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)
|
||||||
@ -987,11 +987,9 @@ def parse_json_metadata(metadatapath):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def parse_xml_metadata(metadatapath):
|
def parse_xml_metadata(mf, app):
|
||||||
|
|
||||||
app = get_default_app_info(metadatapath)
|
tree = ElementTree.ElementTree(file=mf)
|
||||||
|
|
||||||
tree = ElementTree.ElementTree(file=metadatapath)
|
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
if root.tag != 'resources':
|
if root.tag != 'resources':
|
||||||
@ -1021,13 +1019,9 @@ def parse_xml_metadata(metadatapath):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def parse_yaml_metadata(metadatapath):
|
def parse_yaml_metadata(mf, app):
|
||||||
|
|
||||||
app = get_default_app_info(metadatapath)
|
yamlinfo = yaml.load(mf, Loader=YamlLoader)
|
||||||
|
|
||||||
yamlinfo = None
|
|
||||||
with open(metadatapath, 'r') as f:
|
|
||||||
yamlinfo = yaml.load(f, Loader=YamlLoader)
|
|
||||||
app.update_fields(yamlinfo)
|
app.update_fields(yamlinfo)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@ -1036,7 +1030,7 @@ build_line_sep = re.compile(r'(?<!\\),')
|
|||||||
build_cont = re.compile(r'^[ \t]')
|
build_cont = re.compile(r'^[ \t]')
|
||||||
|
|
||||||
|
|
||||||
def parse_txt_metadata(metadatapath):
|
def parse_txt_metadata(mf, app):
|
||||||
|
|
||||||
linedesc = None
|
linedesc = None
|
||||||
|
|
||||||
@ -1092,9 +1086,6 @@ def parse_txt_metadata(metadatapath):
|
|||||||
app.comments[key] = list(curcomments)
|
app.comments[key] = list(curcomments)
|
||||||
del curcomments[:]
|
del curcomments[:]
|
||||||
|
|
||||||
app = get_default_app_info(metadatapath)
|
|
||||||
metafile = open(metadatapath, "r")
|
|
||||||
|
|
||||||
mode = 0
|
mode = 0
|
||||||
buildlines = []
|
buildlines = []
|
||||||
multiline_lines = []
|
multiline_lines = []
|
||||||
@ -1103,9 +1094,9 @@ def parse_txt_metadata(metadatapath):
|
|||||||
vc_seen = set()
|
vc_seen = set()
|
||||||
|
|
||||||
c = 0
|
c = 0
|
||||||
for line in metafile:
|
for line in mf:
|
||||||
c += 1
|
c += 1
|
||||||
linedesc = "%s:%d" % (metafile.name, c)
|
linedesc = "%s:%d" % (mf.name, c)
|
||||||
line = line.rstrip('\r\n')
|
line = line.rstrip('\r\n')
|
||||||
if mode == 3:
|
if mode == 3:
|
||||||
if build_cont.match(line):
|
if build_cont.match(line):
|
||||||
@ -1197,11 +1188,10 @@ def parse_txt_metadata(metadatapath):
|
|||||||
add_comments('build:' + app.builds[-1].vercode)
|
add_comments('build:' + app.builds[-1].vercode)
|
||||||
mode = 0
|
mode = 0
|
||||||
add_comments(None)
|
add_comments(None)
|
||||||
metafile.close()
|
|
||||||
|
|
||||||
# Mode at end of file should always be 0
|
# Mode at end of file should always be 0
|
||||||
if mode == 1:
|
if mode == 1:
|
||||||
raise MetaDataException(f + " not terminated in " + metafile.name)
|
raise MetaDataException(f + " not terminated in " + mf.name)
|
||||||
if mode == 2:
|
if mode == 2:
|
||||||
raise MetaDataException("Unterminated continuation in " + metafile.name)
|
raise MetaDataException("Unterminated continuation in " + metafile.name)
|
||||||
if mode == 3:
|
if mode == 3:
|
||||||
|
Loading…
Reference in New Issue
Block a user