Make app['Categories'] a list, get unique categories via a set

This commit is contained in:
Daniel Martí 2014-02-19 10:21:13 +01:00
parent be7c6aceec
commit 3483bad392
3 changed files with 10 additions and 13 deletions

View file

@ -440,6 +440,8 @@ def read_metadata(xref=True, package=None, store=True):
def metafieldtype(name): def metafieldtype(name):
if name in ['Description', 'Maintainer Notes']: if name in ['Description', 'Maintainer Notes']:
return 'multiline' return 'multiline'
if name in ['Categories']:
return 'list'
if name == 'Build Version': if name == 'Build Version':
return 'build' return 'build'
if name == 'Build': if name == 'Build':
@ -629,6 +631,8 @@ def parse_metadata(metafile):
raise MetaDataException("Unexpected text on same line as " + field + " in " + linedesc) raise MetaDataException("Unexpected text on same line as " + field + " in " + linedesc)
elif fieldtype == 'string': elif fieldtype == 'string':
thisinfo[field] = value thisinfo[field] = value
elif fieldtype == 'list':
thisinfo[field] = [v.strip() for v in value.replace(';',',').split(',')]
elif fieldtype == 'build': elif fieldtype == 'build':
if value.endswith("\\"): if value.endswith("\\"):
mode = 2 mode = 2

View file

@ -204,10 +204,7 @@ def main():
logging.info("Processing categories...") logging.info("Processing categories...")
ctgs = Counter() ctgs = Counter()
for app in metaapps: for app in metaapps:
if app['Categories'] is None: for category in app['Categories']:
continue
categories = [c.strip() for c in app['Categories'].split(',')]
for category in categories:
ctgs[category] += 1; ctgs[category] += 1;
f = open('stats/categories.txt', 'w') f = open('stats/categories.txt', 'w')
for category in ctgs: for category in ctgs:

View file

@ -190,7 +190,7 @@ def update_wiki(apps, apks):
wikidata += '\n[[Category:Apps that are disabled]]\n' wikidata += '\n[[Category:Apps that are disabled]]\n'
if app['Update Check Mode'] == 'None' and not app['Disabled']: if app['Update Check Mode'] == 'None' and not app['Disabled']:
wikidata += '\n[[Category:Apps with no update check]]\n' 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) wikidata += '\n[[Category:{0}]]\n'.format(appcat)
# We can't have underscores in the page name, even if they're in # 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) metadata.description_html(app['Description'], linkres), doc, apel)
addElement('license', app['License'], doc, apel) addElement('license', app['License'], doc, apel)
if 'Categories' in app: if 'Categories' in app:
appcategories = [c.strip() for c in app['Categories'].split(',')] addElement('categories', ','.join(app["Categories"]), doc, apel)
addElement('categories', ','.join(appcategories), doc, apel)
# We put the first (primary) category in LAST, which will have # We put the first (primary) category in LAST, which will have
# the desired effect of making clients that only understand one # the desired effect of making clients that only understand one
# category see that 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('web', app['Web Site'], doc, apel)
addElement('source', app['Source Code'], doc, apel) addElement('source', app['Source Code'], doc, apel)
addElement('tracker', app['Issue Tracker'], doc, apel) addElement('tracker', app['Issue Tracker'], doc, apel)
@ -895,12 +894,9 @@ def main():
apps = metadata.read_metadata() apps = metadata.read_metadata()
# Generate a list of categories... # Generate a list of categories...
categories = [] categories = set()
for app in apps: for app in apps:
cats = app['Categories'].split(',') categories.update(app['Categories'])
for cat in cats:
if cat not in categories:
categories.append(cat)
# Read known apks data (will be updated and written back when we've finished) # Read known apks data (will be updated and written back when we've finished)
knownapks = common.KnownApks() knownapks = common.KnownApks()