1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-03 17:50:11 +02:00

Merge branch 'yaml-template' into 'master'

update: remove ruamel requirement, and improve '--create-metadata'

Closes #343

See merge request !300
This commit is contained in:
Michael Pöhn 2017-07-06 15:29:19 +00:00
commit 747ac52a62
2 changed files with 28 additions and 11 deletions

View File

@ -1051,9 +1051,11 @@ def write_yaml(mf, app):
# next iteration will need to insert a newline
insert_newline = True
else:
if (hasattr(app, field) and getattr(app, field)) or field is 'Builds':
if app.get(field) or field is 'Builds':
# .txt calls it 'builds' internally, everywhere else its 'Builds'
if field is 'Builds':
cm.update({field: _builds_to_yaml(app)})
if app.get('builds'):
cm.update({field: _builds_to_yaml(app)})
elif field is 'CurrentVersionCode':
cm.update({field: _field_to_yaml(TYPE_INT, getattr(app, field))})
else:

View File

@ -1761,17 +1761,32 @@ def main():
if apk['packageName'] not in apps:
if options.create_metadata:
with open(os.path.join('metadata', apk['packageName'] + '.yml'), 'w') as f:
app = metadata.App()
# this should use metadata.App() and
# metadata.write_yaml(), but since ruamel.yaml
# 0.13 is not widely distributed yet, and it's
# special tricks are not really needed here, this
# uses the plain YAML lib
app = dict()
if 'name' in apk:
app.Name = apk['name']
app.Summary = apk['name']
app['Name'] = apk['name']
else:
logging.warn(apk['packageName'] + ' does not have a name! Using package name instead.')
app.Name = apk['packageName']
app.Summary = apk['packageName']
app.CurrentVersionCode = 2147483647 # Java's Integer.MAX_VALUE
app.Categories = [os.path.basename(os.path.dirname(os.getcwd()))]
metadata.write_yaml(f, app)
logging.warning(apk['packageName'] + ' does not have a name! Using package name instead.')
app['Name'] = apk['packageName']
app['Categories'] = [os.path.basename(os.getcwd())]
# include some blanks as part of the template
app['AuthorName'] = ''
app['Summary'] = ''
app['WebSite'] = ''
app['IssueTracker'] = ''
app['SourceCode'] = ''
app['CurrentVersionCode'] = 2147483647 # Java's Integer.MAX_VALUE
try:
import ruamel.yaml
assert ruamel.yaml # silence pyflakes
metadata.write_yaml(f, metadata.App(app))
except ImportError:
import yaml
yaml.dump(app, f, default_flow_style=False)
logging.info("Generated skeleton metadata for " + apk['packageName'])
newmetadata = True
else: