mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-02 08:08:20 +00:00
Add command line option -y/--python-exception, revert previous commit.
By default, catch exceptions and report them without a stack trace. When this option is specified, raise an actual Python exception (should show a strack trace). Note: diff for this patch is best seen with -b (ignore-whitespace-change).
This commit is contained in:
parent
26b49b0807
commit
e5ffe56fec
1 changed files with 152 additions and 139 deletions
29
main.py
29
main.py
|
@ -174,6 +174,7 @@ Usage: {progname}
|
||||||
[-o|--output=<filename>] output to file rather than stdout
|
[-o|--output=<filename>] output to file rather than stdout
|
||||||
[-H|--header] add the script as a comment in Firestorm format
|
[-H|--header] add the script as a comment in Firestorm format
|
||||||
[-T|--timestamp] add a timestamp as a comment at the beginning
|
[-T|--timestamp] add a timestamp as a comment at the beginning
|
||||||
|
[-y|--python-exceptions] when an exception is raised, show a stack trace
|
||||||
[-p|--preproc=mode] run external preprocessor (see below for modes)
|
[-p|--preproc=mode] run external preprocessor (see below for modes)
|
||||||
(resets the preprocessor command line so far)
|
(resets the preprocessor command line so far)
|
||||||
[-P|--prearg=<arg>] add parameter to preprocessor's command line
|
[-P|--prearg=<arg>] add parameter to preprocessor's command line
|
||||||
|
@ -337,9 +338,9 @@ def main(argv):
|
||||||
% (b"', '".join(options - validoptions)).decode('utf8'))
|
% (b"', '".join(options - validoptions)).decode('utf8'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HT',
|
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTy',
|
||||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||||
'timestamp',
|
'timestamp','python-exceptions',
|
||||||
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
||||||
'avid=', 'avname=', 'assetid=', 'shortname='))
|
'avid=', 'avname=', 'assetid=', 'shortname='))
|
||||||
except getopt.GetoptError as e:
|
except getopt.GetoptError as e:
|
||||||
|
@ -359,6 +360,7 @@ def main(argv):
|
||||||
script_timestamp = ''
|
script_timestamp = ''
|
||||||
mcpp_mode = False
|
mcpp_mode = False
|
||||||
preshow = False
|
preshow = False
|
||||||
|
raise_exception = False
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if type(opt) is unicode:
|
if type(opt) is unicode:
|
||||||
|
@ -402,6 +404,9 @@ def main(argv):
|
||||||
elif opt in ('-o', '--output'):
|
elif opt in ('-o', '--output'):
|
||||||
outfile = arg
|
outfile = arg
|
||||||
|
|
||||||
|
elif opt in ('-y', '--python-exceptions'):
|
||||||
|
raise_exception = True
|
||||||
|
|
||||||
elif opt in ('-p', '--preproc'):
|
elif opt in ('-p', '--preproc'):
|
||||||
preproc = arg.lower()
|
preproc = arg.lower()
|
||||||
supported = ('ext', 'mcpp', 'gcpp', 'none')
|
supported = ('ext', 'mcpp', 'gcpp', 'none')
|
||||||
|
@ -470,6 +475,8 @@ def main(argv):
|
||||||
shortname = arg
|
shortname = arg
|
||||||
del opts
|
del opts
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
if 'lso' in options:
|
if 'lso' in options:
|
||||||
lslopt.lslcommon.LSO = True
|
lslopt.lslcommon.LSO = True
|
||||||
options.remove('lso')
|
options.remove('lso')
|
||||||
|
@ -548,12 +555,12 @@ def main(argv):
|
||||||
|
|
||||||
if preproc != 'none':
|
if preproc != 'none':
|
||||||
# At this point, for the external preprocessor to work we need the
|
# At this point, for the external preprocessor to work we need the
|
||||||
# script as a byte array, not as unicode, but it should be valid UTF-8.
|
# script as a byte array, not as unicode, but it should be UTF-8.
|
||||||
script = PreparePreproc(script)
|
script = PreparePreproc(script)
|
||||||
if mcpp_mode:
|
if mcpp_mode:
|
||||||
# As a special treatment for mcpp, we force it to output its macros
|
# As a special treatment for mcpp, we force it to output its
|
||||||
# so we can read if USE_xxx are defined. With GCC that is achieved
|
# macros so we can read if USE_xxx are defined. With GCC that
|
||||||
# with -dN but with mcpp there's no command line option.
|
# is achieved with -dN, but mcpp has no command line option.
|
||||||
script += '\n#pragma MCPP put_defines\n'
|
script += '\n#pragma MCPP put_defines\n'
|
||||||
|
|
||||||
# Invoke the external preprocessor
|
# Invoke the external preprocessor
|
||||||
|
@ -568,8 +575,8 @@ def main(argv):
|
||||||
del p, status
|
del p, status
|
||||||
|
|
||||||
# This method is very imperfect, in several senses. However, since
|
# This method is very imperfect, in several senses. However, since
|
||||||
# it's applied to the output of the preprocessor, all of the concerns
|
# it's applied to the output of the preprocessor, all of the
|
||||||
# should be addressed:
|
# concerns should be addressed:
|
||||||
# - \s includes \n, but \n should not be allowed.
|
# - \s includes \n, but \n should not be allowed.
|
||||||
# - Comments preceding the directive should not cause problems.
|
# - Comments preceding the directive should not cause problems.
|
||||||
# e.g.: /* test */ #directive
|
# e.g.: /* test */ #directive
|
||||||
|
@ -613,6 +620,12 @@ def main(argv):
|
||||||
outf.close()
|
outf.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if raise_exception:
|
||||||
|
raise
|
||||||
|
sys.stderr.write(e.__class__.__name__ + ': ' + str(e) + '\n')
|
||||||
|
return 1
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ret = main(sys.argv)
|
ret = main(sys.argv)
|
||||||
if ret:
|
if ret:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue