michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: '''Parses a given application.ini file and outputs the corresponding michael@0: XULAppData structure as a C++ header file''' michael@0: michael@0: import ConfigParser michael@0: import sys michael@0: michael@0: def main(file): michael@0: config = ConfigParser.RawConfigParser() michael@0: config.read(file) michael@0: flags = set() michael@0: try: michael@0: if config.getint('XRE', 'EnableExtensionManager') == 1: michael@0: flags.add('NS_XRE_ENABLE_EXTENSION_MANAGER') michael@0: except: pass michael@0: try: michael@0: if config.getint('XRE', 'EnableProfileMigrator') == 1: michael@0: flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR') michael@0: except: pass michael@0: try: michael@0: if config.getint('Crash Reporter', 'Enabled') == 1: michael@0: flags.add('NS_XRE_ENABLE_CRASH_REPORTER') michael@0: except: pass michael@0: appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s)) michael@0: appdata['flags'] = ' | '.join(flags) if flags else '0' michael@0: appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL' michael@0: expected = ('App:vendor', 'App:name', 'App:version', 'App:buildid', michael@0: 'App:id', 'Gecko:minversion', 'Gecko:maxversion') michael@0: missing = [var for var in expected if var not in appdata] michael@0: if missing: michael@0: print >>sys.stderr, \ michael@0: "Missing values in %s: %s" % (file, ', '.join(missing)) michael@0: sys.exit(1) michael@0: michael@0: if not 'Crash Reporter:serverurl' in appdata: michael@0: appdata['Crash Reporter:serverurl'] = '' michael@0: michael@0: print '''#include "nsXREAppData.h" michael@0: static const nsXREAppData sAppData = { michael@0: sizeof(nsXREAppData), michael@0: NULL, // directory michael@0: "%(App:vendor)s", michael@0: "%(App:name)s", michael@0: "%(App:version)s", michael@0: "%(App:buildid)s", michael@0: "%(App:id)s", michael@0: NULL, // copyright michael@0: %(flags)s, michael@0: NULL, // xreDirectory michael@0: "%(Gecko:minversion)s", michael@0: "%(Gecko:maxversion)s", michael@0: "%(Crash Reporter:serverurl)s", michael@0: %(App:profile)s michael@0: };''' % appdata michael@0: michael@0: if __name__ == '__main__': michael@0: if len(sys.argv) != 1: michael@0: main(sys.argv[1]) michael@0: else: michael@0: print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]