chiark / gitweb /
Centralise management of srclib metadata
[fdroidserver.git] / fdroidserver / metadata.py
index 5b0753859c1bcb7714c9af23e4ee16af55ccb17b..6d4982abc1e1a5a9ec3421e9769d26f071f31ae4 100644 (file)
@@ -23,7 +23,7 @@ import glob
 import cgi
 import logging
 
-srclibs = []
+srclibs = {}
 
 class MetaDataException(Exception):
     def __init__(self, value):
@@ -421,6 +421,28 @@ def parse_srclib(metafile):
     return thisinfo
 
 
+def read_srclibs():
+    """Read all srclib metadata.
+
+    The information read will be accessible as metadata.srclibs, which is a
+    dictionary, keyed on srclib name, with the values each being a dictionary
+    in the same format as that returned by the parse_srclib function.
+
+    A MetaDataException is raised if there are any problems with the srclib
+    metadata.
+    """
+    global srclibs
+    srclibs = {}
+
+    srcdir = 'srclibs'
+    if not os.path.exists(srcdir):
+        os.makedirs(srcdir)
+
+    for metafile in sorted(glob.glob(os.path.join(srcdir, '*.txt'))):
+        srclibname = os.path.basename(metafile[:-4])
+        srclibs[srclibname] = parse_srclib(metafile)
+
+
 # Read all metadata. Returns a list of 'app' objects (which are dictionaries as
 # returned by the parse_metadata function.
 def read_metadata(xref=True):