Add --bom command-line option to prefix the script with a BOM

This commit is contained in:
Sei Lisa 2018-05-11 22:37:09 +02:00
parent c3be2bd216
commit 1d7142a698

10
main.py
View file

@ -218,6 +218,7 @@ Usage: {progname}
[--assetid=<UUID>] * specify the asset UUID of the script [--assetid=<UUID>] * specify the asset UUID of the script
[--shortname=<name>] * specify the script's short file name [--shortname=<name>] * specify the script's short file name
[--prettify] Prettify source file. Disables all -O options. [--prettify] Prettify source file. Disables all -O options.
[--bom] Prefix script with a UTF-8 byte-order mark
filename input file filename input file
Options marked with * are used to define the preprocessor macros __AGENTID__, Options marked with * are used to define the preprocessor macros __AGENTID__,
@ -384,7 +385,7 @@ def main(argv):
try: try:
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTyb:L:', opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTyb:L:',
('optimizer-options=', 'help', 'version', 'output=', 'header', ('optimizer-options=', 'help', 'version', 'output=', 'header',
'timestamp', 'python-exceptions', 'prettify', 'timestamp', 'python-exceptions', 'prettify', 'bom',
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow', 'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
'avid=', 'avname=', 'assetid=', 'shortname=', 'builtins=' 'avid=', 'avname=', 'assetid=', 'shortname=', 'builtins='
'libdata=')) 'libdata='))
@ -407,6 +408,7 @@ def main(argv):
preshow = False preshow = False
raise_exception = False raise_exception = False
prettify = False prettify = False
bom = False
builtins = None builtins = None
libdata = None libdata = None
@ -509,6 +511,9 @@ def main(argv):
elif opt == '--prettify': elif opt == '--prettify':
prettify = True prettify = True
elif opt == '--bom':
bom = True
del opts del opts
if prettify: if prettify:
@ -684,6 +689,9 @@ def main(argv):
del script_header, script_timestamp del script_header, script_timestamp
if bom:
script = b'\xEF\xBB\xBF' + script
if outfile == '-': if outfile == '-':
sys.stdout.write(script) sys.stdout.write(script)
else: else: