Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | '''Parses a given application.ini file and outputs the corresponding |
michael@0 | 6 | XULAppData structure as a C++ header file''' |
michael@0 | 7 | |
michael@0 | 8 | import ConfigParser |
michael@0 | 9 | import sys |
michael@0 | 10 | |
michael@0 | 11 | def main(file): |
michael@0 | 12 | config = ConfigParser.RawConfigParser() |
michael@0 | 13 | config.read(file) |
michael@0 | 14 | flags = set() |
michael@0 | 15 | try: |
michael@0 | 16 | if config.getint('XRE', 'EnableExtensionManager') == 1: |
michael@0 | 17 | flags.add('NS_XRE_ENABLE_EXTENSION_MANAGER') |
michael@0 | 18 | except: pass |
michael@0 | 19 | try: |
michael@0 | 20 | if config.getint('XRE', 'EnableProfileMigrator') == 1: |
michael@0 | 21 | flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR') |
michael@0 | 22 | except: pass |
michael@0 | 23 | try: |
michael@0 | 24 | if config.getint('Crash Reporter', 'Enabled') == 1: |
michael@0 | 25 | flags.add('NS_XRE_ENABLE_CRASH_REPORTER') |
michael@0 | 26 | except: pass |
michael@0 | 27 | appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s)) |
michael@0 | 28 | appdata['flags'] = ' | '.join(flags) if flags else '0' |
michael@0 | 29 | appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL' |
michael@0 | 30 | expected = ('App:vendor', 'App:name', 'App:version', 'App:buildid', |
michael@0 | 31 | 'App:id', 'Gecko:minversion', 'Gecko:maxversion') |
michael@0 | 32 | missing = [var for var in expected if var not in appdata] |
michael@0 | 33 | if missing: |
michael@0 | 34 | print >>sys.stderr, \ |
michael@0 | 35 | "Missing values in %s: %s" % (file, ', '.join(missing)) |
michael@0 | 36 | sys.exit(1) |
michael@0 | 37 | |
michael@0 | 38 | if not 'Crash Reporter:serverurl' in appdata: |
michael@0 | 39 | appdata['Crash Reporter:serverurl'] = '' |
michael@0 | 40 | |
michael@0 | 41 | print '''#include "nsXREAppData.h" |
michael@0 | 42 | static const nsXREAppData sAppData = { |
michael@0 | 43 | sizeof(nsXREAppData), |
michael@0 | 44 | NULL, // directory |
michael@0 | 45 | "%(App:vendor)s", |
michael@0 | 46 | "%(App:name)s", |
michael@0 | 47 | "%(App:version)s", |
michael@0 | 48 | "%(App:buildid)s", |
michael@0 | 49 | "%(App:id)s", |
michael@0 | 50 | NULL, // copyright |
michael@0 | 51 | %(flags)s, |
michael@0 | 52 | NULL, // xreDirectory |
michael@0 | 53 | "%(Gecko:minversion)s", |
michael@0 | 54 | "%(Gecko:maxversion)s", |
michael@0 | 55 | "%(Crash Reporter:serverurl)s", |
michael@0 | 56 | %(App:profile)s |
michael@0 | 57 | };''' % appdata |
michael@0 | 58 | |
michael@0 | 59 | if __name__ == '__main__': |
michael@0 | 60 | if len(sys.argv) != 1: |
michael@0 | 61 | main(sys.argv[1]) |
michael@0 | 62 | else: |
michael@0 | 63 | print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0] |