chiark / gitweb /
metadata: rewrite multiline field writing
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 12 Sep 2015 02:12:51 +0000 (19:12 -0700)
committerDaniel Martí <mvdan@mvdan.cc>
Sat, 12 Sep 2015 02:12:51 +0000 (19:12 -0700)
Now description text wrapping can be added.

fdroidserver/metadata.py

index b6f5911dd83f9559e91bf0e5cb3aba1447120ed7..f034a6e3183e62328cf7d9a6f1855743eebcb608 100644 (file)
@@ -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')