rename metadata.write_metadata() to match metadata.parse_*_metadata()

This changes the function name to include the format of the metadata file,
and also changes the order of the args to match the parse_*_metadata()
functions.
This commit is contained in:
Hans-Christoph Steiner 2015-08-10 22:29:17 +02:00
parent 3b20153cd7
commit 994488ad47
4 changed files with 18 additions and 14 deletions

View file

@ -492,8 +492,7 @@ def checkupdates_app(app, first=True):
if commitmsg: if commitmsg:
metadatapath = os.path.join('metadata', app.id + '.txt') metadatapath = os.path.join('metadata', app.id + '.txt')
with open(metadatapath, 'w') as f: metadata.write_metadata(metadatapath, app)
metadata.write_metadata('txt', f, app)
if options.commit: if options.commit:
logging.info("Commiting update for " + metadatapath) logging.info("Commiting update for " + metadatapath)
gitcmd = ["git", "commit", "-m", commitmsg] gitcmd = ["git", "commit", "-m", commitmsg]

View file

@ -243,8 +243,7 @@ def main():
f.write(app.RepoType + ' ' + app.Repo) f.write(app.RepoType + ' ' + app.Repo)
metadatapath = os.path.join('metadata', package + '.txt') metadatapath = os.path.join('metadata', package + '.txt')
with open(metadatapath, 'w') as f: metadata.write_metadata(metadatapath, app)
metadata.write_metadata('txt', f, app)
logging.info("Wrote " + metadatapath) logging.info("Wrote " + metadatapath)

View file

@ -1270,7 +1270,7 @@ def write_plaintext_metadata(mf, app, w_comment, w_field, w_build):
# #
# '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(mf, app):
def w_comment(line): def w_comment(line):
mf.write("# %s\n" % line) mf.write("# %s\n" % line)
@ -1313,7 +1313,7 @@ def write_txt_metadata(mf, app):
write_plaintext_metadata(mf, app, w_comment, w_field, w_build) write_plaintext_metadata(mf, app, w_comment, w_field, w_build)
def write_yaml_metadata(mf, app): def write_yaml(mf, app):
def w_comment(line): def w_comment(line):
mf.write("# %s\n" % line) mf.write("# %s\n" % line)
@ -1377,9 +1377,16 @@ def write_yaml_metadata(mf, app):
write_plaintext_metadata(mf, app, w_comment, w_field, w_build) write_plaintext_metadata(mf, app, w_comment, w_field, w_build)
def write_metadata(fmt, mf, app): def write_metadata(metadatapath, app):
if fmt == 'txt': _, ext = fdroidserver.common.get_extension(metadatapath)
return write_txt_metadata(mf, app) accepted = fdroidserver.common.config['accepted_formats']
if fmt == 'yaml': if ext not in accepted:
return write_yaml_metadata(mf, app) raise MetaDataException('Cannot write "%s", not an accepted format, use: %s' % (
raise MetaDataException("Unknown metadata format given") metadatapath, ', '.join(accepted)))
with open(metadatapath, 'w') as mf:
if ext == 'txt':
return write_txt(mf, app)
elif ext == 'yaml':
return write_yaml(mf, app)
raise MetaDataException('Unknown metadata format: %s' % metadatapath)

View file

@ -84,8 +84,7 @@ def main():
print(app.metadatapath) print(app.metadatapath)
continue continue
with open(base + '.' + to_ext, 'w') as f: metadata.write_metadata(base + '.' + to_ext, app)
metadata.write_metadata(to_ext, f, app)
if ext != to_ext: if ext != to_ext:
os.remove(app.metadatapath) os.remove(app.metadatapath)