chiark / gitweb /
support app metadata in YAML format
[fdroidserver.git] / fdroidserver / metadata.py
index 10976871edc474128e777365fedd6891a560540c..fe45c896aa274983bcdd1a8234038859f874af08 100644 (file)
@@ -25,6 +25,15 @@ import glob
 import cgi
 import logging
 
+import yaml
+# use libyaml if it is available
+try:
+    from yaml import CLoader
+    YamlLoader = CLoader
+except ImportError:
+    from yaml import Loader
+    YamlLoader = Loader
+
 # use the C implementation when available
 import xml.etree.cElementTree as ElementTree
 
@@ -500,6 +509,11 @@ def read_metadata(xref=True):
         check_metadata(appinfo)
         apps[appid] = appinfo
 
+    for metafile in sorted(glob.glob(os.path.join('metadata', '*.yaml'))):
+        appid, appinfo = parse_yaml_metadata(metafile)
+        check_metadata(appinfo)
+        apps[appid] = appinfo
+
     if xref:
         # Parse all descriptions at load time, just to ensure cross-referencing
         # errors are caught early rather than when they hit the build server.
@@ -572,9 +586,11 @@ def split_list_values(s):
     return [v for v in l if v]
 
 
-def get_default_app_info_list():
+def get_default_app_info_list(appid=None):
     thisinfo = {}
     thisinfo.update(app_defaults)
+    if appid is not None:
+        thisinfo['id'] = appid
 
     # General defaults...
     thisinfo['builds'] = []
@@ -706,8 +722,7 @@ def _decode_dict(data):
 def parse_json_metadata(metafile):
 
     appid = os.path.basename(metafile)[0:-5]  # strip path and .json
-    thisinfo = get_default_app_info_list()
-    thisinfo['id'] = appid
+    thisinfo = get_default_app_info_list(appid)
 
     # fdroid metadata is only strings and booleans, no floats or ints. And
     # json returns unicode, and fdroidserver still uses plain python strings
@@ -725,8 +740,7 @@ def parse_json_metadata(metafile):
 def parse_xml_metadata(metafile):
 
     appid = os.path.basename(metafile)[0:-4]  # strip path and .xml
-    thisinfo = get_default_app_info_list()
-    thisinfo['id'] = appid
+    thisinfo = get_default_app_info_list(appid)
 
     tree = ElementTree.ElementTree(file=metafile)
     root = tree.getroot()
@@ -774,6 +788,18 @@ def parse_xml_metadata(metafile):
     return (appid, thisinfo)
 
 
+def parse_yaml_metadata(metafile):
+
+    appid = os.path.basename(metafile)[0:-5]  # strip path and .yaml
+    thisinfo = get_default_app_info_list(appid)
+
+    yamlinfo = yaml.load(open(metafile, 'r'), Loader=YamlLoader)
+    thisinfo.update(yamlinfo)
+    post_metadata_parse(thisinfo)
+
+    return (appid, thisinfo)
+
+
 def parse_txt_metadata(metafile):
 
     appid = None