mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-17 18:50:11 +02:00
metadata: rename metafile to metadatapath when it is a path
To keep the code clear, change the code to use separate variables for the path to the metadata file, and for the file object of the opened metadata.
This commit is contained in:
parent
285c06d156
commit
6f334558df
@ -493,14 +493,14 @@ def checkupdates_app(app, first=True):
|
|||||||
logging.warn('Invalid auto update mode "' + mode + '" on ' + app['id'])
|
logging.warn('Invalid auto update mode "' + mode + '" on ' + app['id'])
|
||||||
|
|
||||||
if commitmsg:
|
if commitmsg:
|
||||||
metafile = os.path.join('metadata', app['id'] + '.txt')
|
metadatapath = os.path.join('metadata', app['id'] + '.txt')
|
||||||
metadata.write_metadata(metafile, app)
|
metadata.write_metadata(metadatapath, app)
|
||||||
if options.commit:
|
if options.commit:
|
||||||
logging.info("Commiting update for " + metafile)
|
logging.info("Commiting update for " + metadatapath)
|
||||||
gitcmd = ["git", "commit", "-m", commitmsg]
|
gitcmd = ["git", "commit", "-m", commitmsg]
|
||||||
if 'auto_author' in config:
|
if 'auto_author' in config:
|
||||||
gitcmd.extend(['--author', config['auto_author']])
|
gitcmd.extend(['--author', config['auto_author']])
|
||||||
gitcmd.extend(["--", metafile])
|
gitcmd.extend(["--", metadatapath])
|
||||||
if subprocess.call(gitcmd) != 0:
|
if subprocess.call(gitcmd) != 0:
|
||||||
logging.error("Git commit failed")
|
logging.error("Git commit failed")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -234,9 +234,9 @@ def main():
|
|||||||
with open('build/.fdroidvcs-' + package, 'w') as f:
|
with open('build/.fdroidvcs-' + package, 'w') as f:
|
||||||
f.write(repotype + ' ' + repo)
|
f.write(repotype + ' ' + repo)
|
||||||
|
|
||||||
metafile = os.path.join('metadata', package + '.txt')
|
metadatapath = os.path.join('metadata', package + '.txt')
|
||||||
metadata.write_metadata(metafile, app)
|
metadata.write_metadata(metadatapath, app)
|
||||||
logging.info("Wrote " + metafile)
|
logging.info("Wrote " + metadatapath)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -418,11 +418,9 @@ def description_html(lines, linkres):
|
|||||||
return ps.text_html
|
return ps.text_html
|
||||||
|
|
||||||
|
|
||||||
def parse_srclib(metafile):
|
def parse_srclib(metadatapath):
|
||||||
|
|
||||||
thisinfo = {}
|
thisinfo = {}
|
||||||
if metafile and not isinstance(metafile, file):
|
|
||||||
metafile = open(metafile, "r")
|
|
||||||
|
|
||||||
# Defaults for fields that come from metadata
|
# Defaults for fields that come from metadata
|
||||||
thisinfo['Repo Type'] = ''
|
thisinfo['Repo Type'] = ''
|
||||||
@ -430,9 +428,11 @@ def parse_srclib(metafile):
|
|||||||
thisinfo['Subdir'] = None
|
thisinfo['Subdir'] = None
|
||||||
thisinfo['Prepare'] = None
|
thisinfo['Prepare'] = None
|
||||||
|
|
||||||
if metafile is None:
|
if not os.path.exists(metadatapath):
|
||||||
return thisinfo
|
return thisinfo
|
||||||
|
|
||||||
|
metafile = open(metadatapath, "r")
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
for line in metafile:
|
for line in metafile:
|
||||||
n += 1
|
n += 1
|
||||||
@ -475,9 +475,9 @@ def read_srclibs():
|
|||||||
if not os.path.exists(srcdir):
|
if not os.path.exists(srcdir):
|
||||||
os.makedirs(srcdir)
|
os.makedirs(srcdir)
|
||||||
|
|
||||||
for metafile in sorted(glob.glob(os.path.join(srcdir, '*.txt'))):
|
for metadatapath in sorted(glob.glob(os.path.join(srcdir, '*.txt'))):
|
||||||
srclibname = os.path.basename(metafile[:-4])
|
srclibname = os.path.basename(metadatapath[:-4])
|
||||||
srclibs[srclibname] = parse_srclib(metafile)
|
srclibs[srclibname] = parse_srclib(metadatapath)
|
||||||
|
|
||||||
|
|
||||||
# Read all metadata. Returns a list of 'app' objects (which are dictionaries as
|
# Read all metadata. Returns a list of 'app' objects (which are dictionaries as
|
||||||
@ -494,23 +494,23 @@ def read_metadata(xref=True):
|
|||||||
if not os.path.exists(basedir):
|
if not os.path.exists(basedir):
|
||||||
os.makedirs(basedir)
|
os.makedirs(basedir)
|
||||||
|
|
||||||
for metafile in sorted(glob.glob(os.path.join('metadata', '*.txt'))):
|
for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.txt'))):
|
||||||
appid, appinfo = parse_txt_metadata(metafile)
|
appid, appinfo = parse_txt_metadata(metadatapath)
|
||||||
check_metadata(appinfo)
|
check_metadata(appinfo)
|
||||||
apps[appid] = appinfo
|
apps[appid] = appinfo
|
||||||
|
|
||||||
for metafile in sorted(glob.glob(os.path.join('metadata', '*.json'))):
|
for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.json'))):
|
||||||
appid, appinfo = parse_json_metadata(metafile)
|
appid, appinfo = parse_json_metadata(metadatapath)
|
||||||
check_metadata(appinfo)
|
check_metadata(appinfo)
|
||||||
apps[appid] = appinfo
|
apps[appid] = appinfo
|
||||||
|
|
||||||
for metafile in sorted(glob.glob(os.path.join('metadata', '*.xml'))):
|
for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.xml'))):
|
||||||
appid, appinfo = parse_xml_metadata(metafile)
|
appid, appinfo = parse_xml_metadata(metadatapath)
|
||||||
check_metadata(appinfo)
|
check_metadata(appinfo)
|
||||||
apps[appid] = appinfo
|
apps[appid] = appinfo
|
||||||
|
|
||||||
for metafile in sorted(glob.glob(os.path.join('metadata', '*.yaml'))):
|
for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.yaml'))):
|
||||||
appid, appinfo = parse_yaml_metadata(metafile)
|
appid, appinfo = parse_yaml_metadata(metadatapath)
|
||||||
check_metadata(appinfo)
|
check_metadata(appinfo)
|
||||||
apps[appid] = appinfo
|
apps[appid] = appinfo
|
||||||
|
|
||||||
@ -586,8 +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(metafile=None):
|
def get_default_app_info_list(metadatapath):
|
||||||
appid = os.path.splitext(os.path.basename(metafile))[0]
|
appid = os.path.splitext(os.path.basename(metadatapath))[0]
|
||||||
thisinfo = {}
|
thisinfo = {}
|
||||||
thisinfo.update(app_defaults)
|
thisinfo.update(app_defaults)
|
||||||
if appid is not None:
|
if appid is not None:
|
||||||
@ -666,7 +666,7 @@ def post_metadata_parse(thisinfo):
|
|||||||
|
|
||||||
# Parse metadata for a single application.
|
# Parse metadata for a single application.
|
||||||
#
|
#
|
||||||
# 'metafile' - the filename to read. The package id for the application comes
|
# 'metadatapath' - the filename to read. The package id for the application comes
|
||||||
# from this filename. Pass None to get a blank entry.
|
# from this filename. Pass None to get a blank entry.
|
||||||
#
|
#
|
||||||
# Returns a dictionary containing all the details of the application. There are
|
# Returns a dictionary containing all the details of the application. There are
|
||||||
@ -720,14 +720,14 @@ def _decode_dict(data):
|
|||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
def parse_json_metadata(metafile):
|
def parse_json_metadata(metadatapath):
|
||||||
|
|
||||||
appid, thisinfo = get_default_app_info_list(metafile)
|
appid, thisinfo = get_default_app_info_list(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 = json.load(open(metafile, 'r'),
|
jsoninfo = json.load(open(metadatapath, 'r'),
|
||||||
object_hook=_decode_dict,
|
object_hook=_decode_dict,
|
||||||
parse_int=lambda s: s,
|
parse_int=lambda s: s,
|
||||||
parse_float=lambda s: s)
|
parse_float=lambda s: s)
|
||||||
@ -737,15 +737,15 @@ def parse_json_metadata(metafile):
|
|||||||
return (appid, thisinfo)
|
return (appid, thisinfo)
|
||||||
|
|
||||||
|
|
||||||
def parse_xml_metadata(metafile):
|
def parse_xml_metadata(metadatapath):
|
||||||
|
|
||||||
appid, thisinfo = get_default_app_info_list(metafile)
|
appid, thisinfo = get_default_app_info_list(metadatapath)
|
||||||
|
|
||||||
tree = ElementTree.ElementTree(file=metafile)
|
tree = ElementTree.ElementTree(file=metadatapath)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
if root.tag != 'resources':
|
if root.tag != 'resources':
|
||||||
logging.critical(metafile + ' does not have root as <resources></resources>!')
|
logging.critical(metadatapath + ' does not have root as <resources></resources>!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
supported_metadata = app_defaults.keys()
|
supported_metadata = app_defaults.keys()
|
||||||
@ -787,18 +787,18 @@ def parse_xml_metadata(metafile):
|
|||||||
return (appid, thisinfo)
|
return (appid, thisinfo)
|
||||||
|
|
||||||
|
|
||||||
def parse_yaml_metadata(metafile):
|
def parse_yaml_metadata(metadatapath):
|
||||||
|
|
||||||
appid, thisinfo = get_default_app_info_list(metafile)
|
appid, thisinfo = get_default_app_info_list(metadatapath)
|
||||||
|
|
||||||
yamlinfo = yaml.load(open(metafile, 'r'), Loader=YamlLoader)
|
yamlinfo = yaml.load(open(metadatapath, 'r'), Loader=YamlLoader)
|
||||||
thisinfo.update(yamlinfo)
|
thisinfo.update(yamlinfo)
|
||||||
post_metadata_parse(thisinfo)
|
post_metadata_parse(thisinfo)
|
||||||
|
|
||||||
return (appid, thisinfo)
|
return (appid, thisinfo)
|
||||||
|
|
||||||
|
|
||||||
def parse_txt_metadata(metafile):
|
def parse_txt_metadata(metadatapath):
|
||||||
|
|
||||||
linedesc = None
|
linedesc = None
|
||||||
|
|
||||||
@ -874,8 +874,8 @@ def parse_txt_metadata(metafile):
|
|||||||
thisinfo['comments'].append([key, comment])
|
thisinfo['comments'].append([key, comment])
|
||||||
del curcomments[:]
|
del curcomments[:]
|
||||||
|
|
||||||
appid, thisinfo = get_default_app_info_list(metafile)
|
appid, thisinfo = get_default_app_info_list(metadatapath)
|
||||||
metafile = open(metafile, "r")
|
metafile = open(metadatapath, "r")
|
||||||
|
|
||||||
mode = 0
|
mode = 0
|
||||||
buildlines = []
|
buildlines = []
|
||||||
|
Loading…
Reference in New Issue
Block a user