mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 15:13:27 +02:00
metadata: use unified method for getting default app metadata dict
This puts process of setting up the defaults for the internal dict that represents a parsed app into a single method that is reused for all metadata formats.
This commit is contained in:
parent
32e257d742
commit
285c06d156
@ -586,7 +586,8 @@ def split_list_values(s):
|
|||||||
return [v for v in l if v]
|
return [v for v in l if v]
|
||||||
|
|
||||||
|
|
||||||
def get_default_app_info_list(appid=None):
|
def get_default_app_info_list(metafile=None):
|
||||||
|
appid = os.path.splitext(os.path.basename(metafile))[0]
|
||||||
thisinfo = {}
|
thisinfo = {}
|
||||||
thisinfo.update(app_defaults)
|
thisinfo.update(app_defaults)
|
||||||
if appid is not None:
|
if appid is not None:
|
||||||
@ -596,7 +597,7 @@ def get_default_app_info_list(appid=None):
|
|||||||
thisinfo['builds'] = []
|
thisinfo['builds'] = []
|
||||||
thisinfo['comments'] = []
|
thisinfo['comments'] = []
|
||||||
|
|
||||||
return thisinfo
|
return appid, thisinfo
|
||||||
|
|
||||||
|
|
||||||
def post_metadata_parse(thisinfo):
|
def post_metadata_parse(thisinfo):
|
||||||
@ -721,8 +722,7 @@ def _decode_dict(data):
|
|||||||
|
|
||||||
def parse_json_metadata(metafile):
|
def parse_json_metadata(metafile):
|
||||||
|
|
||||||
appid = os.path.basename(metafile)[0:-5] # strip path and .json
|
appid, thisinfo = get_default_app_info_list(metafile)
|
||||||
thisinfo = get_default_app_info_list(appid)
|
|
||||||
|
|
||||||
# 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
|
||||||
@ -739,8 +739,7 @@ def parse_json_metadata(metafile):
|
|||||||
|
|
||||||
def parse_xml_metadata(metafile):
|
def parse_xml_metadata(metafile):
|
||||||
|
|
||||||
appid = os.path.basename(metafile)[0:-4] # strip path and .xml
|
appid, thisinfo = get_default_app_info_list(metafile)
|
||||||
thisinfo = get_default_app_info_list(appid)
|
|
||||||
|
|
||||||
tree = ElementTree.ElementTree(file=metafile)
|
tree = ElementTree.ElementTree(file=metafile)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
@ -790,8 +789,7 @@ def parse_xml_metadata(metafile):
|
|||||||
|
|
||||||
def parse_yaml_metadata(metafile):
|
def parse_yaml_metadata(metafile):
|
||||||
|
|
||||||
appid = os.path.basename(metafile)[0:-5] # strip path and .yaml
|
appid, thisinfo = get_default_app_info_list(metafile)
|
||||||
thisinfo = get_default_app_info_list(appid)
|
|
||||||
|
|
||||||
yamlinfo = yaml.load(open(metafile, 'r'), Loader=YamlLoader)
|
yamlinfo = yaml.load(open(metafile, 'r'), Loader=YamlLoader)
|
||||||
thisinfo.update(yamlinfo)
|
thisinfo.update(yamlinfo)
|
||||||
@ -802,7 +800,6 @@ def parse_yaml_metadata(metafile):
|
|||||||
|
|
||||||
def parse_txt_metadata(metafile):
|
def parse_txt_metadata(metafile):
|
||||||
|
|
||||||
appid = None
|
|
||||||
linedesc = None
|
linedesc = None
|
||||||
|
|
||||||
def add_buildflag(p, thisbuild):
|
def add_buildflag(p, thisbuild):
|
||||||
@ -877,14 +874,8 @@ def parse_txt_metadata(metafile):
|
|||||||
thisinfo['comments'].append([key, comment])
|
thisinfo['comments'].append([key, comment])
|
||||||
del curcomments[:]
|
del curcomments[:]
|
||||||
|
|
||||||
thisinfo = get_default_app_info_list()
|
appid, thisinfo = get_default_app_info_list(metafile)
|
||||||
if metafile:
|
metafile = open(metafile, "r")
|
||||||
if not isinstance(metafile, file):
|
|
||||||
metafile = open(metafile, "r")
|
|
||||||
appid = metafile.name[9:-4]
|
|
||||||
thisinfo['id'] = appid
|
|
||||||
else:
|
|
||||||
return appid, thisinfo
|
|
||||||
|
|
||||||
mode = 0
|
mode = 0
|
||||||
buildlines = []
|
buildlines = []
|
||||||
|
Loading…
Reference in New Issue
Block a user