chiark / gitweb /
rename metadata.write_metadata() to match metadata.parse_*_metadata()
authorHans-Christoph Steiner <hans@eds.org>
Mon, 10 Aug 2015 20:29:17 +0000 (22:29 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 23 Mar 2016 16:16:28 +0000 (17:16 +0100)
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.

fdroidserver/checkupdates.py
fdroidserver/import.py
fdroidserver/metadata.py
fdroidserver/rewritemeta.py

index 7adfcbb3c03481f43bb7f673818dda6259467d54..e22a6e0f1e1c593343eddcd909f7d4e148921783 100644 (file)
@@ -492,8 +492,7 @@ def checkupdates_app(app, first=True):
 
     if commitmsg:
         metadatapath = os.path.join('metadata', app.id + '.txt')
-        with open(metadatapath, 'w') as f:
-            metadata.write_metadata('txt', f, app)
+        metadata.write_metadata(metadatapath, app)
         if options.commit:
             logging.info("Commiting update for " + metadatapath)
             gitcmd = ["git", "commit", "-m", commitmsg]
index 3b80e485cca797c81fd281bcfe4b25caca8abdcf..247a42c4a4b981ab6ecb9eda4b5933780a644bd2 100644 (file)
@@ -243,8 +243,7 @@ def main():
         f.write(app.RepoType + ' ' + app.Repo)
 
     metadatapath = os.path.join('metadata', package + '.txt')
-    with open(metadatapath, 'w') as f:
-        metadata.write_metadata('txt', f, app)
+    metadata.write_metadata(metadatapath, app)
     logging.info("Wrote " + metadatapath)
 
 
index bbaccd91ba37b82cc06a4f5eaac870654a832b37..722e1710a29bed277360dc804fd96e70207b3eef 100644 (file)
@@ -1270,7 +1270,7 @@ def write_plaintext_metadata(mf, app, w_comment, w_field, w_build):
 #
 # 'mf'      - Writer interface (file, StringIO, ...)
 # 'app'     - The app data
-def write_txt_metadata(mf, app):
+def write_txt(mf, app):
 
     def w_comment(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)
 
 
-def write_yaml_metadata(mf, app):
+def write_yaml(mf, app):
 
     def w_comment(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)
 
 
-def write_metadata(fmt, mf, app):
-    if fmt == 'txt':
-        return write_txt_metadata(mf, app)
-    if fmt == 'yaml':
-        return write_yaml_metadata(mf, app)
-    raise MetaDataException("Unknown metadata format given")
+def write_metadata(metadatapath, app):
+    _, ext = fdroidserver.common.get_extension(metadatapath)
+    accepted = fdroidserver.common.config['accepted_formats']
+    if ext not in accepted:
+        raise MetaDataException('Cannot write "%s", not an accepted format, use: %s' % (
+            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)
index 971ab18cb597d5899dc2a646bf850e4004f974c0..75888a23b28bf84f199963993cd6931aed4bf82b 100644 (file)
@@ -84,8 +84,7 @@ def main():
                 print(app.metadatapath)
             continue
 
-        with open(base + '.' + to_ext, 'w') as f:
-            metadata.write_metadata(to_ext, f, app)
+        metadata.write_metadata(base + '.' + to_ext, app)
 
         if ext != to_ext:
             os.remove(app.metadatapath)