From ade5036e23f8e53c4153696e10abbaefef57d365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 11 Sep 2015 19:12:51 -0700 Subject: [PATCH] metadata: rewrite multiline field writing Now description text wrapping can be added. --- fdroidserver/metadata.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index b6f5911d..f034a6e3 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -265,6 +265,7 @@ class DescriptionFormatter: state = stNONE text_wiki = '' text_html = '' + text_txt = '' linkResolver = None def __init__(self, linkres): @@ -366,6 +367,7 @@ class DescriptionFormatter: def parseline(self, line): self.text_wiki += "%s\n" % line + self.text_txt += "%s\n" % line if not line: self.endcur() elif line.startswith('* '): @@ -397,6 +399,16 @@ class DescriptionFormatter: self.endcur() +# Parse multiple lines of description as written in a metadata file, returning +# a single string in text format and wrapped to 80 columns. +def description_txt(lines): + ps = DescriptionFormatter(None) + for line in lines: + ps.parseline(line) + ps.end() + return ps.text_txt + + # Parse multiple lines of description as written in a metadata file, returning # a single string in wiki format. Used for the Maintainer Notes field as well, # because it's the same format. @@ -1044,6 +1056,11 @@ def write_metadata(dest, app): t = metafieldtype(field) if t == 'list': value = ','.join(value) + elif t == 'multiline': + if type(value) == list: + value = '\n' + '\n'.join(value) + '\n.' + else: + value = '\n' + value + '.' mf.write("%s:%s\n" % (field, value)) def writefield_nonempty(field, value=None): @@ -1072,10 +1089,7 @@ def write_metadata(dest, app): writefield_nonempty('Name') writefield_nonempty('Auto Name') writefield('Summary') - writefield('Description', '') - for line in app['Description']: - mf.write("%s\n" % line) - mf.write('.\n') + writefield('Description', description_txt(app['Description'])) mf.write('\n') if app['Requires Root']: writefield('Requires Root', 'yes') @@ -1126,10 +1140,7 @@ def write_metadata(dest, app): mf.write('\n') if app['Maintainer Notes']: - writefield('Maintainer Notes', '') - for line in app['Maintainer Notes']: - mf.write("%s\n" % line) - mf.write('.\n') + writefield('Maintainer Notes', app['Maintainer Notes']) mf.write('\n') writefield_nonempty('Archive Policy')