mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-16 07:52:35 +03:00
Add basic yaml metadata writing
This commit is contained in:
parent
082e275aa1
commit
1aa891c4fd
3 changed files with 160 additions and 96 deletions
|
@ -369,10 +369,10 @@ def read_app_args(args, allapps, allow_vercodes=False):
|
||||||
|
|
||||||
|
|
||||||
def get_extension(filename):
|
def get_extension(filename):
|
||||||
_, ext = os.path.splitext(filename)
|
base, ext = os.path.splitext(filename)
|
||||||
if not ext:
|
if not ext:
|
||||||
return ''
|
return base, ''
|
||||||
return ext.lower()[1:]
|
return base, ext.lower()[1:]
|
||||||
|
|
||||||
|
|
||||||
def has_extension(filename, ext):
|
def has_extension(filename, ext):
|
||||||
|
|
|
@ -877,8 +877,6 @@ def parse_txt_metadata(apps, metadatapath):
|
||||||
value = pv == 'yes'
|
value = pv == 'yes'
|
||||||
if value:
|
if value:
|
||||||
thisbuild[pk] = True
|
thisbuild[pk] = True
|
||||||
else:
|
|
||||||
logging.debug("...ignoring bool flag %s" % p)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise MetaDataException("Unrecognised build flag type '%s' at %s in %s"
|
raise MetaDataException("Unrecognised build flag type '%s' at %s in %s"
|
||||||
|
@ -1038,23 +1036,89 @@ def parse_txt_metadata(apps, metadatapath):
|
||||||
return (appid, thisinfo)
|
return (appid, thisinfo)
|
||||||
|
|
||||||
|
|
||||||
|
def write_metadata(mf, app, w_comment, w_field, w_build):
|
||||||
|
|
||||||
|
def w_field_nonempty(field, value=None):
|
||||||
|
if value is None:
|
||||||
|
value = app[field]
|
||||||
|
if value:
|
||||||
|
w_field(field, value)
|
||||||
|
|
||||||
|
w_field_nonempty('Disabled')
|
||||||
|
if app['AntiFeatures']:
|
||||||
|
w_field('AntiFeatures')
|
||||||
|
w_field_nonempty('Provides')
|
||||||
|
w_field('Categories')
|
||||||
|
w_field('License')
|
||||||
|
w_field('Web Site')
|
||||||
|
w_field('Source Code')
|
||||||
|
w_field('Issue Tracker')
|
||||||
|
w_field_nonempty('Changelog')
|
||||||
|
w_field_nonempty('Donate')
|
||||||
|
w_field_nonempty('FlattrID')
|
||||||
|
w_field_nonempty('Bitcoin')
|
||||||
|
w_field_nonempty('Litecoin')
|
||||||
|
mf.write('\n')
|
||||||
|
w_field_nonempty('Name')
|
||||||
|
w_field_nonempty('Auto Name')
|
||||||
|
w_field('Summary')
|
||||||
|
w_field('Description', description_txt(app['Description']))
|
||||||
|
mf.write('\n')
|
||||||
|
if app['Requires Root']:
|
||||||
|
w_field('Requires Root', 'yes')
|
||||||
|
mf.write('\n')
|
||||||
|
if app['Repo Type']:
|
||||||
|
w_field('Repo Type')
|
||||||
|
w_field('Repo')
|
||||||
|
if app['Binaries']:
|
||||||
|
w_field('Binaries')
|
||||||
|
mf.write('\n')
|
||||||
|
|
||||||
|
for build in sorted_builds(app['builds']):
|
||||||
|
|
||||||
|
if build['version'] == "Ignore":
|
||||||
|
continue
|
||||||
|
|
||||||
|
w_comment('build:' + build['vercode'])
|
||||||
|
w_build(build)
|
||||||
|
mf.write('\n')
|
||||||
|
|
||||||
|
if app['Maintainer Notes']:
|
||||||
|
w_field('Maintainer Notes', app['Maintainer Notes'])
|
||||||
|
mf.write('\n')
|
||||||
|
|
||||||
|
w_field_nonempty('Archive Policy')
|
||||||
|
w_field('Auto Update Mode')
|
||||||
|
w_field('Update Check Mode')
|
||||||
|
w_field_nonempty('Update Check Ignore')
|
||||||
|
w_field_nonempty('Vercode Operation')
|
||||||
|
w_field_nonempty('Update Check Name')
|
||||||
|
w_field_nonempty('Update Check Data')
|
||||||
|
if app['Current Version']:
|
||||||
|
w_field('Current Version')
|
||||||
|
w_field('Current Version Code')
|
||||||
|
mf.write('\n')
|
||||||
|
if app['No Source Since']:
|
||||||
|
w_field('No Source Since')
|
||||||
|
mf.write('\n')
|
||||||
|
w_comment(None)
|
||||||
|
|
||||||
|
|
||||||
# Write a metadata file in txt format.
|
# Write a metadata file in txt format.
|
||||||
#
|
#
|
||||||
# 'mf' - Writer interface (file, StringIO, ...)
|
# 'mf' - Writer interface (file, StringIO, ...)
|
||||||
# 'app' - The app data
|
# 'app' - The app data
|
||||||
def write_txt_metadata(mf, app):
|
def write_txt_metadata(mf, app):
|
||||||
|
|
||||||
def writecomments(key):
|
def w_comment(key):
|
||||||
written = 0
|
written = 0
|
||||||
for pf, comment in app['comments']:
|
for pf, comment in app['comments']:
|
||||||
if pf == key:
|
if pf == key:
|
||||||
mf.write("%s\n" % comment)
|
mf.write("%s\n" % comment)
|
||||||
written += 1
|
written += 1
|
||||||
if written > 0:
|
|
||||||
logging.debug("...writing comments for " + (key or 'EOF'))
|
|
||||||
|
|
||||||
def writefield(field, value=None):
|
def w_field(field, value=None):
|
||||||
writecomments(field)
|
w_comment(field)
|
||||||
if value is None:
|
if value is None:
|
||||||
value = app[field]
|
value = app[field]
|
||||||
t = metafieldtype(field)
|
t = metafieldtype(field)
|
||||||
|
@ -1067,96 +1131,84 @@ def write_txt_metadata(mf, app):
|
||||||
value = '\n' + value + '\n.'
|
value = '\n' + value + '\n.'
|
||||||
mf.write("%s:%s\n" % (field, value))
|
mf.write("%s:%s\n" % (field, value))
|
||||||
|
|
||||||
def writefield_nonempty(field, value=None):
|
def w_build(build):
|
||||||
if value is None:
|
|
||||||
value = app[field]
|
|
||||||
if value:
|
|
||||||
writefield(field, value)
|
|
||||||
|
|
||||||
writefield_nonempty('Disabled')
|
|
||||||
if app['AntiFeatures']:
|
|
||||||
writefield('AntiFeatures')
|
|
||||||
writefield_nonempty('Provides')
|
|
||||||
writefield('Categories')
|
|
||||||
writefield('License')
|
|
||||||
writefield('Web Site')
|
|
||||||
writefield('Source Code')
|
|
||||||
writefield('Issue Tracker')
|
|
||||||
writefield_nonempty('Changelog')
|
|
||||||
writefield_nonempty('Donate')
|
|
||||||
writefield_nonempty('FlattrID')
|
|
||||||
writefield_nonempty('Bitcoin')
|
|
||||||
writefield_nonempty('Litecoin')
|
|
||||||
mf.write('\n')
|
|
||||||
writefield_nonempty('Name')
|
|
||||||
writefield_nonempty('Auto Name')
|
|
||||||
writefield('Summary')
|
|
||||||
writefield('Description', description_txt(app['Description']))
|
|
||||||
mf.write('\n')
|
|
||||||
if app['Requires Root']:
|
|
||||||
writefield('Requires Root', 'yes')
|
|
||||||
mf.write('\n')
|
|
||||||
if app['Repo Type']:
|
|
||||||
writefield('Repo Type')
|
|
||||||
writefield('Repo')
|
|
||||||
if app['Binaries']:
|
|
||||||
writefield('Binaries')
|
|
||||||
mf.write('\n')
|
|
||||||
for build in sorted_builds(app['builds']):
|
|
||||||
|
|
||||||
if build['version'] == "Ignore":
|
|
||||||
continue
|
|
||||||
|
|
||||||
writecomments('build:' + build['vercode'])
|
|
||||||
mf.write("Build:%s,%s\n" % (build['version'], build['vercode']))
|
mf.write("Build:%s,%s\n" % (build['version'], build['vercode']))
|
||||||
|
|
||||||
def write_builditem(key, value):
|
for key in flag_defaults:
|
||||||
|
value = build[key]
|
||||||
if key in ['version', 'vercode']:
|
if not value:
|
||||||
return
|
continue
|
||||||
|
|
||||||
if value == flag_defaults[key]:
|
if value == flag_defaults[key]:
|
||||||
return
|
continue
|
||||||
|
|
||||||
t = flagtype(key)
|
t = flagtype(key)
|
||||||
|
v = ' %s=' % key
|
||||||
logging.debug("...writing {0} : {1}".format(key, value))
|
|
||||||
outline = ' %s=' % key
|
|
||||||
|
|
||||||
if t == 'string':
|
if t == 'string':
|
||||||
outline += value
|
v += value
|
||||||
elif t == 'bool':
|
elif t == 'bool':
|
||||||
outline += 'yes'
|
v += 'yes'
|
||||||
elif t == 'script':
|
elif t == 'script':
|
||||||
outline += '&& \\\n '.join([s.lstrip() for s in value.split('&& ')])
|
v += '&& \\\n '.join([s.lstrip() for s in value.split('&& ')])
|
||||||
elif t == 'list':
|
elif t == 'list':
|
||||||
outline += ','.join(value) if type(value) == list else value
|
v += ','.join(value) if type(value) == list else value
|
||||||
|
|
||||||
outline += '\n'
|
mf.write(v)
|
||||||
mf.write(outline)
|
mf.write('\n')
|
||||||
|
|
||||||
for flag in flag_defaults:
|
write_metadata(mf, app, w_comment, w_field, w_build)
|
||||||
value = build[flag]
|
|
||||||
if value:
|
|
||||||
write_builditem(flag, value)
|
|
||||||
mf.write('\n')
|
|
||||||
|
|
||||||
if app['Maintainer Notes']:
|
|
||||||
writefield('Maintainer Notes', app['Maintainer Notes'])
|
|
||||||
mf.write('\n')
|
|
||||||
|
|
||||||
writefield_nonempty('Archive Policy')
|
def write_yaml_metadata(mf, app):
|
||||||
writefield('Auto Update Mode')
|
|
||||||
writefield('Update Check Mode')
|
def w_comment(key):
|
||||||
writefield_nonempty('Update Check Ignore')
|
pass
|
||||||
writefield_nonempty('Vercode Operation')
|
|
||||||
writefield_nonempty('Update Check Name')
|
def w_field(field, value=None, prefix='', t=None):
|
||||||
writefield_nonempty('Update Check Data')
|
w_comment(field)
|
||||||
if app['Current Version']:
|
if value is None:
|
||||||
writefield('Current Version')
|
value = app[field]
|
||||||
writefield('Current Version Code')
|
if t is None:
|
||||||
mf.write('\n')
|
t = metafieldtype(field)
|
||||||
if app['No Source Since']:
|
v = ''
|
||||||
writefield('No Source Since')
|
if t == 'list':
|
||||||
mf.write('\n')
|
v = '\n'
|
||||||
writecomments(None)
|
for e in value:
|
||||||
|
v += prefix + ' - ' + e + '\n'
|
||||||
|
elif t == 'multiline':
|
||||||
|
v = ' |\n'
|
||||||
|
lines = []
|
||||||
|
if type(value) == list:
|
||||||
|
lines = value
|
||||||
|
else:
|
||||||
|
lines = value.splitlines()
|
||||||
|
for l in lines:
|
||||||
|
if l:
|
||||||
|
v += prefix + ' ' + l + '\n'
|
||||||
|
else:
|
||||||
|
v += '\n'
|
||||||
|
else:
|
||||||
|
v = ' ' + value + '\n'
|
||||||
|
|
||||||
|
mf.write("%s%s:%s" % (prefix, field, v))
|
||||||
|
|
||||||
|
global first_build
|
||||||
|
first_build = True
|
||||||
|
|
||||||
|
def w_build(build):
|
||||||
|
global first_build
|
||||||
|
if first_build:
|
||||||
|
mf.write("builds:\n")
|
||||||
|
first_build = False
|
||||||
|
|
||||||
|
w_field('versionName', build['version'], ' - ', 'string')
|
||||||
|
w_field('versionCode', build['vercode'], ' ', 'strsng')
|
||||||
|
for key in flag_defaults:
|
||||||
|
value = build[key]
|
||||||
|
if not value:
|
||||||
|
continue
|
||||||
|
if value == flag_defaults[key]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
w_field(key, value, ' ', flagtype(key))
|
||||||
|
|
||||||
|
write_metadata(mf, app, w_comment, w_field, w_build)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import StringIO
|
import StringIO
|
||||||
|
|
||||||
|
@ -38,6 +39,8 @@ def main():
|
||||||
common.setup_global_opts(parser)
|
common.setup_global_opts(parser)
|
||||||
parser.add_argument("-l", "--list", action="store_true", default=False,
|
parser.add_argument("-l", "--list", action="store_true", default=False,
|
||||||
help="List files that would be reformatted")
|
help="List files that would be reformatted")
|
||||||
|
parser.add_argument("-t", "--to", default='txt',
|
||||||
|
help="Rewrite to a specific format")
|
||||||
parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
|
parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
@ -47,12 +50,14 @@ def main():
|
||||||
allapps = metadata.read_metadata(xref=True)
|
allapps = metadata.read_metadata(xref=True)
|
||||||
apps = common.read_app_args(options.appid, allapps, False)
|
apps = common.read_app_args(options.appid, allapps, False)
|
||||||
|
|
||||||
|
if options.list and options.to:
|
||||||
|
parser.error("Cannot use --list and --to at the same time")
|
||||||
|
|
||||||
for appid, app in apps.iteritems():
|
for appid, app in apps.iteritems():
|
||||||
metadatapath = app['metadatapath']
|
metadatapath = app['metadatapath']
|
||||||
ext = common.get_extension(metadatapath)
|
base, ext = common.get_extension(metadatapath)
|
||||||
if ext not in ['txt']:
|
if not options.to and ext not in ['txt', 'yaml']:
|
||||||
logging.info("Ignoring %s file at '%s'"
|
logging.info("Ignoring %s file at '%s'" % (ext, metadatapath))
|
||||||
% (ext.upper(), metadatapath))
|
|
||||||
continue
|
continue
|
||||||
logging.debug("Rewriting " + metadatapath)
|
logging.debug("Rewriting " + metadatapath)
|
||||||
if options.list:
|
if options.list:
|
||||||
|
@ -66,9 +71,16 @@ def main():
|
||||||
s.close()
|
s.close()
|
||||||
if content != cur_content:
|
if content != cur_content:
|
||||||
print(metadatapath)
|
print(metadatapath)
|
||||||
else:
|
continue
|
||||||
with open(metadatapath, 'w') as f:
|
|
||||||
|
if options.to == 'txt':
|
||||||
|
with open(base+'.txt', 'w') as f:
|
||||||
metadata.write_txt_metadata(f, app)
|
metadata.write_txt_metadata(f, app)
|
||||||
|
elif options.to == 'yaml':
|
||||||
|
# with open(base+'.yaml', 'w') as f:
|
||||||
|
# metadata.write_yaml_metadata(f, app)
|
||||||
|
metadata.write_yaml_metadata(sys.stdout, app)
|
||||||
|
break
|
||||||
|
|
||||||
logging.debug("Finished.")
|
logging.debug("Finished.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue