chiark / gitweb /
Make app['Categories'] a list, get unique categories via a set
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 19 Feb 2014 09:21:13 +0000 (10:21 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 19 Feb 2014 09:27:38 +0000 (10:27 +0100)
fdroidserver/metadata.py
fdroidserver/stats.py
fdroidserver/update.py

index ef6e8e8e86803ef29f2d24b1c499abc29bccb7e9..c78bcfee53973d84e7a5e825fa654b3881a4d502 100644 (file)
@@ -440,6 +440,8 @@ def read_metadata(xref=True, package=None, store=True):
 def metafieldtype(name):
     if name in ['Description', 'Maintainer Notes']:
         return 'multiline'
+    if name in ['Categories']:
+        return 'list'
     if name == 'Build Version':
         return 'build'
     if name == 'Build':
@@ -629,6 +631,8 @@ def parse_metadata(metafile):
                     raise MetaDataException("Unexpected text on same line as " + field + " in " + linedesc)
             elif fieldtype == 'string':
                 thisinfo[field] = value
+            elif fieldtype == 'list':
+                thisinfo[field] = [v.strip() for v in value.replace(';',',').split(',')]
             elif fieldtype == 'build':
                 if value.endswith("\\"):
                     mode = 2
index e4504f977f0f36c6335345e110398d8b5417da6a..e0692b5ebb6bb643ddebd94488f992e7c067b1aa 100644 (file)
@@ -204,10 +204,7 @@ def main():
     logging.info("Processing categories...")
     ctgs = Counter()
     for app in metaapps:
-        if app['Categories'] is None:
-            continue
-        categories = [c.strip() for c in app['Categories'].split(',')]
-        for category in categories:
+        for category in app['Categories']:
             ctgs[category] += 1;
     f = open('stats/categories.txt', 'w')
     for category in ctgs:
index 9fa6fdd47ba2d4e23150cd1dd81b447f8c95bcfe..d542aa6898155984450cd7f96a36b05a940f334d 100644 (file)
@@ -190,7 +190,7 @@ def update_wiki(apps, apks):
             wikidata += '\n[[Category:Apps that are disabled]]\n'
         if app['Update Check Mode'] == 'None' and not app['Disabled']:
             wikidata += '\n[[Category:Apps with no update check]]\n'
-        for appcat in [c.strip() for c in app['Categories'].split(',')]:
+        for appcat in app['Categories']:
             wikidata += '\n[[Category:{0}]]\n'.format(appcat)
 
         # We can't have underscores in the page name, even if they're in
@@ -689,12 +689,11 @@ def make_index(apps, apks, repodir, archive, categories):
                 metadata.description_html(app['Description'], linkres), doc, apel)
         addElement('license', app['License'], doc, apel)
         if 'Categories' in app:
-            appcategories = [c.strip() for c in app['Categories'].split(',')]
-            addElement('categories', ','.join(appcategories), doc, apel)
+            addElement('categories', ','.join(app["Categories"]), doc, apel)
             # We put the first (primary) category in LAST, which will have
             # the desired effect of making clients that only understand one
             # category see that one.
-            addElement('category', appcategories[0], doc, apel)
+            addElement('category', app["Categories"][0], doc, apel)
         addElement('web', app['Web Site'], doc, apel)
         addElement('source', app['Source Code'], doc, apel)
         addElement('tracker', app['Issue Tracker'], doc, apel)
@@ -895,12 +894,9 @@ def main():
     apps = metadata.read_metadata()
 
     # Generate a list of categories...
-    categories = []
+    categories = set()
     for app in apps:
-        cats = app['Categories'].split(',')
-        for cat in cats:
-            if cat not in categories:
-                categories.append(cat)
+        categories.update(app['Categories'])
 
     # Read known apks data (will be updated and written back when we've finished)
     knownapks = common.KnownApks()