appini_header.py 2.3 KB

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