mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-17 18:50:11 +02:00
metadata: rewrite multiline field writing
Now description text wrapping can be added.
This commit is contained in:
parent
cd202e59b1
commit
ade5036e23
@ -265,6 +265,7 @@ class DescriptionFormatter:
|
|||||||
state = stNONE
|
state = stNONE
|
||||||
text_wiki = ''
|
text_wiki = ''
|
||||||
text_html = ''
|
text_html = ''
|
||||||
|
text_txt = ''
|
||||||
linkResolver = None
|
linkResolver = None
|
||||||
|
|
||||||
def __init__(self, linkres):
|
def __init__(self, linkres):
|
||||||
@ -366,6 +367,7 @@ class DescriptionFormatter:
|
|||||||
|
|
||||||
def parseline(self, line):
|
def parseline(self, line):
|
||||||
self.text_wiki += "%s\n" % line
|
self.text_wiki += "%s\n" % line
|
||||||
|
self.text_txt += "%s\n" % line
|
||||||
if not line:
|
if not line:
|
||||||
self.endcur()
|
self.endcur()
|
||||||
elif line.startswith('* '):
|
elif line.startswith('* '):
|
||||||
@ -397,6 +399,16 @@ class DescriptionFormatter:
|
|||||||
self.endcur()
|
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
|
# 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,
|
# a single string in wiki format. Used for the Maintainer Notes field as well,
|
||||||
# because it's the same format.
|
# because it's the same format.
|
||||||
@ -1044,6 +1056,11 @@ def write_metadata(dest, app):
|
|||||||
t = metafieldtype(field)
|
t = metafieldtype(field)
|
||||||
if t == 'list':
|
if t == 'list':
|
||||||
value = ','.join(value)
|
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))
|
mf.write("%s:%s\n" % (field, value))
|
||||||
|
|
||||||
def writefield_nonempty(field, value=None):
|
def writefield_nonempty(field, value=None):
|
||||||
@ -1072,10 +1089,7 @@ def write_metadata(dest, app):
|
|||||||
writefield_nonempty('Name')
|
writefield_nonempty('Name')
|
||||||
writefield_nonempty('Auto Name')
|
writefield_nonempty('Auto Name')
|
||||||
writefield('Summary')
|
writefield('Summary')
|
||||||
writefield('Description', '')
|
writefield('Description', description_txt(app['Description']))
|
||||||
for line in app['Description']:
|
|
||||||
mf.write("%s\n" % line)
|
|
||||||
mf.write('.\n')
|
|
||||||
mf.write('\n')
|
mf.write('\n')
|
||||||
if app['Requires Root']:
|
if app['Requires Root']:
|
||||||
writefield('Requires Root', 'yes')
|
writefield('Requires Root', 'yes')
|
||||||
@ -1126,10 +1140,7 @@ def write_metadata(dest, app):
|
|||||||
mf.write('\n')
|
mf.write('\n')
|
||||||
|
|
||||||
if app['Maintainer Notes']:
|
if app['Maintainer Notes']:
|
||||||
writefield('Maintainer Notes', '')
|
writefield('Maintainer Notes', app['Maintainer Notes'])
|
||||||
for line in app['Maintainer Notes']:
|
|
||||||
mf.write("%s\n" % line)
|
|
||||||
mf.write('.\n')
|
|
||||||
mf.write('\n')
|
mf.write('\n')
|
||||||
|
|
||||||
writefield_nonempty('Archive Policy')
|
writefield_nonempty('Archive Policy')
|
||||||
|
Loading…
Reference in New Issue
Block a user