gecko-dev/build/appini_header.py
Andrew Halberstadt f354075c7a Bug 1434430 - [flake8] Fix blank 'except' statements r=rwood
This is a new issue that gets linted with flake8 3.5.0. Basically you should
never use a blank except: statement.

This will catch all exceptions, including KeyboardInterrupt and SystemExit
(which is likely not intended). If a catch all is needed, use
`except: Exception`.  If you *really* mean to also catch KeyboardInterrupt et
al, use `except: BaseException`.

Of course, being specific is often better than a catch all.

MozReview-Commit-ID: FKx80MLO4RN

--HG--
extra : rebase_source : 7c74a7d0d81f2c984b47aff3a0ee3448b791177b
2018-01-31 14:32:08 -05:00

64 lines
2.3 KiB
Python

# 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 http://mozilla.org/MPL/2.0/.
'''Parses a given application.ini file and outputs the corresponding
StaticXREAppData structure as a C++ header file'''
import ConfigParser
import sys
def main(output, file):
config = ConfigParser.RawConfigParser()
config.read(file)
flags = set()
try:
if config.getint('XRE', 'EnableProfileMigrator') == 1:
flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
except Exception:
pass
try:
if config.getint('Crash Reporter', 'Enabled') == 1:
flags.add('NS_XRE_ENABLE_CRASH_REPORTER')
except Exception:
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))
sys.exit(1)
if 'Crash Reporter:serverurl' not in appdata:
appdata['Crash Reporter:serverurl'] = ''
output.write('''#include "mozilla/XREAppData.h"
static const mozilla::StaticXREAppData sAppData = {
"%(App:vendor)s",
"%(App:name)s",
"%(App:remotingname)s",
"%(App:version)s",
"%(App:buildid)s",
"%(App:id)s",
NULL, // copyright
%(flags)s,
"%(Gecko:minversion)s",
"%(Gecko:maxversion)s",
"%(Crash Reporter:serverurl)s",
%(App:profile)s
};''' % appdata)
if __name__ == '__main__':
if len(sys.argv) != 1:
main(sys.stdout, sys.argv[1])
else:
print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]