chiark / gitweb /
Merge branch 'support-xml-json-yaml-for-metadata' into 'master'
[fdroidserver.git] / fdroidserver / rewritemeta.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 #
4 # rewritemeta.py - part of the FDroid server tools
5 # This cleans up the original .txt metadata file format.
6 # Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Affero General Public License for more details.
17 #
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 import os
22 from optparse import OptionParser
23 import logging
24 import common
25 import metadata
26
27 config = None
28 options = None
29
30
31 def main():
32
33     global config, options
34
35     # Parse command line...
36     parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
37     parser.add_option("-v", "--verbose", action="store_true", default=False,
38                       help="Spew out even more information than normal")
39     parser.add_option("-q", "--quiet", action="store_true", default=False,
40                       help="Restrict output to warnings and errors")
41     (options, args) = parser.parse_args()
42
43     config = common.read_config(options)
44
45     # Get all apps...
46     allapps = metadata.read_metadata(xref=True)
47     apps = common.read_app_args(args, allapps, False)
48
49     for appid, app in apps.iteritems():
50         metadatapath = app['metadatapath']
51         ext = os.path.splitext(metadatapath)[1][1:]
52         if ext == 'txt':
53             logging.info("Rewriting " + metadatapath)
54             metadata.write_metadata(metadatapath, app)
55         else:
56             logging.info("Ignoring %s file at '%s'"
57                          % (ext.upper(), metadatapath))
58
59     logging.info("Finished.")
60
61 if __name__ == "__main__":
62     main()