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/.
5 '''Parses a given application.ini file and outputs the corresponding
6 StaticXREAppData structure as a C++ header file'''
12 def main(output
, file):
13 config
= ConfigParser
.RawConfigParser()
17 if config
.getint('XRE', 'EnableProfileMigrator') == 1:
18 flags
.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
22 if config
.getint('Crash Reporter', 'Enabled') == 1:
23 flags
.add('NS_XRE_ENABLE_CRASH_REPORTER')
26 appdata
= dict(("%s:%s" % (s
, o
), config
.get(s
, o
))
27 for s
in config
.sections() for o
in config
.options(s
))
28 appdata
['flags'] = ' | '.join(flags
) if flags
else '0'
29 appdata
['App:profile'] = ('"%s"' % appdata
['App:profile']
30 if 'App:profile' in appdata
else 'NULL')
31 expected
= ('App:vendor', 'App:name', 'App:remotingname', 'App:version', 'App:buildid',
32 'App:id', 'Gecko:minversion', 'Gecko:maxversion')
33 missing
= [var
for var
in expected
if var
not in appdata
]
36 "Missing values in %s: %s" % (file, ', '.join(missing
))
39 if 'Crash Reporter:serverurl' not in appdata
:
40 appdata
['Crash Reporter:serverurl'] = ''
42 if 'App:sourcerepository' in appdata
and 'App:sourcestamp' in appdata
:
43 appdata
['App:sourceurl'] = '"%(App:sourcerepository)s/rev/%(App:sourcestamp)s"' % appdata
45 appdata
['App:sourceurl'] = 'NULL'
47 output
.write('''#include "mozilla/XREAppData.h"
48 static const mozilla::StaticXREAppData sAppData = {
51 "%(App:remotingname)s",
57 "%(Gecko:minversion)s",
58 "%(Gecko:maxversion)s",
59 "%(Crash Reporter:serverurl)s",
66 if __name__
== '__main__':
67 if len(sys
.argv
) != 1:
68 main(sys
.stdout
, sys
.argv
[1])
70 print >>sys
.stderr
, "Usage: %s /path/to/application.ini" % sys
.argv
[0]