chiark / gitweb /
Make write_metadata take a writer
[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 from argparse import ArgumentParser
22 import logging
23 import common
24 import metadata
25
26 config = None
27 options = None
28
29
30 def main():
31
32     global config, options
33
34     # Parse command line...
35     parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
36     common.setup_global_opts(parser)
37     parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
38     options = parser.parse_args()
39
40     config = common.read_config(options)
41
42     # Get all apps...
43     allapps = metadata.read_metadata(xref=True)
44     apps = common.read_app_args(options.appid, allapps, False)
45
46     for appid, app in apps.iteritems():
47         metadatapath = app['metadatapath']
48         ext = common.get_extension(metadatapath)
49         if ext not in ['txt']:
50             logging.info("Ignoring %s file at '%s'"
51                          % (ext.upper(), metadatapath))
52             continue
53         logging.debug("Rewriting " + metadatapath)
54         with open(metadatapath, 'w') as f:
55             metadata.write_metadata(f, app)
56
57     logging.debug("Finished.")
58
59 if __name__ == "__main__":
60     main()