author Mike Shal <>
Fri, 29 Apr 2016 13:45:07 -0400
changeset 296329 5c0ca5b6fd4133a9aa2cb66b2765209debb53d1d
parent 212205 1416eeab79a2fcf08934f221c839d6d97b07c931
child 325678 eae2252a519f3ac5850f5110a6a1be45891ea5e9
permissions -rw-r--r--
Bug 1269787 - Move rule to; r=glandium MozReview-Commit-ID: 5tly7JYA2f7

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

'''Parses a given application.ini file and outputs the corresponding
   XULAppData structure as a C++ header file'''

import ConfigParser
import sys

def main(output, file):
    config = ConfigParser.RawConfigParser()
    flags = set()
        if config.getint('XRE', 'EnableProfileMigrator') == 1:
    except: pass
        if config.getint('Crash Reporter', 'Enabled') == 1:
    except: pass
    appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s))
    appdata['flags'] = ' | '.join(flags) if flags else '0'
    appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL'
    expected = ('App:vendor', 'App:name', 'App:remotingname', 'App:version', 'App:buildid',
                'App:id', 'Gecko:minversion', 'Gecko:maxversion')
    missing = [var for var in expected if var not in appdata]
    if missing:
        print >>sys.stderr, \
            "Missing values in %s: %s" % (file, ', '.join(missing))

    if not 'Crash Reporter:serverurl' in appdata:
        appdata['Crash Reporter:serverurl'] = ''

    output.write('''#include "nsXREAppData.h"
             static const nsXREAppData sAppData = {
                 NULL, // directory
                 NULL, // copyright
                 NULL, // xreDirectory
                 "%(Crash Reporter:serverurl)s",
             };''' % appdata)

if __name__ == '__main__':
    if len(sys.argv) != 1:
        main(sys.stdout, sys.argv[1])
        print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]