mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Add -T / --timestamp option to insert the generation timestamp
This commit is contained in:
parent
5a2c7278cd
commit
f97cef2a38
1 changed files with 20 additions and 8 deletions
28
main.py
28
main.py
|
@ -164,6 +164,7 @@ Usage: {progname}
|
||||||
[--version] print this program's version
|
[--version] print this program's version
|
||||||
[-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
|
||||||
[-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
|
||||||
|
@ -272,7 +273,7 @@ Optimizer options (+ means active by default, - means inactive by default):
|
||||||
copy-paste-able to the viewer.
|
copy-paste-able to the viewer.
|
||||||
skippreproc + Skip preprocessor directives in the source as if they
|
skippreproc + Skip preprocessor directives in the source as if they
|
||||||
were comments. Not useful unless the script is itself
|
were comments. Not useful unless the script is itself
|
||||||
the output of a preprocessor like cpp, which inserts
|
the output of a preprocessor like GNU cpp, which inserts
|
||||||
directives like: # 123 "filename".
|
directives like: # 123 "filename".
|
||||||
explicitcast - Add explicit casts where they are implicit. This option
|
explicitcast - Add explicit casts where they are implicit. This option
|
||||||
is useless with 'optimize' and 'optsigns', and is of
|
is useless with 'optimize' and 'optsigns', and is of
|
||||||
|
@ -295,8 +296,9 @@ def main():
|
||||||
))
|
))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.gnu_getopt(sys.argv[1:], 'hO:o:p:P:H',
|
opts, args = getopt.gnu_getopt(sys.argv[1:], 'hO:o:p:P:HT',
|
||||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||||
|
'timestamp',
|
||||||
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
||||||
'avid=', 'avname=', 'assetid=', 'scriptname='))
|
'avid=', 'avname=', 'assetid=', 'scriptname='))
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
|
@ -312,6 +314,7 @@ def main():
|
||||||
preproc = 'none'
|
preproc = 'none'
|
||||||
predefines = True
|
predefines = True
|
||||||
script_header = ''
|
script_header = ''
|
||||||
|
script_timestamp = ''
|
||||||
mcpp_mode = False
|
mcpp_mode = False
|
||||||
preshow = False
|
preshow = False
|
||||||
|
|
||||||
|
@ -394,6 +397,9 @@ def main():
|
||||||
elif opt in ('-H', '--header'):
|
elif opt in ('-H', '--header'):
|
||||||
script_header = True
|
script_header = True
|
||||||
|
|
||||||
|
elif opt in ('-T', '--timestamp'):
|
||||||
|
script_timestamp = True
|
||||||
|
|
||||||
elif opt == '--avid':
|
elif opt == '--avid':
|
||||||
avid = arg
|
avid = arg
|
||||||
|
|
||||||
|
@ -428,6 +434,14 @@ def main():
|
||||||
if script_header:
|
if script_header:
|
||||||
script_header = ScriptHeader(script, avname)
|
script_header = ScriptHeader(script, avname)
|
||||||
|
|
||||||
|
if script_timestamp:
|
||||||
|
import time
|
||||||
|
tmp = time.time()
|
||||||
|
script_timestamp = time.strftime(
|
||||||
|
'// Generated on %Y-%m-%dT%H:%M:%S.{0:06d}Z\n'
|
||||||
|
.format(int(tmp % 1 * 1000000)), time.gmtime(tmp))
|
||||||
|
del tmp
|
||||||
|
|
||||||
if shortname == '':
|
if shortname == '':
|
||||||
shortname = os.path.basename(fname)
|
shortname = os.path.basename(fname)
|
||||||
|
|
||||||
|
@ -490,19 +504,17 @@ def main():
|
||||||
except EParse as e:
|
except EParse as e:
|
||||||
sys.stderr.write(e[0] + '\n')
|
sys.stderr.write(e[0] + '\n')
|
||||||
return 1
|
return 1
|
||||||
del p
|
del p, script
|
||||||
del script
|
|
||||||
|
|
||||||
opt = optimizer()
|
opt = optimizer()
|
||||||
ts = opt.optimize(ts, options)
|
ts = opt.optimize(ts, options)
|
||||||
del opt
|
del opt
|
||||||
|
|
||||||
outs = outscript()
|
outs = outscript()
|
||||||
script = script_header + outs.output(ts, options)
|
script = script_header + script_timestamp + outs.output(ts, options)
|
||||||
del outs
|
del outs, ts
|
||||||
del ts
|
|
||||||
|
|
||||||
del script_header
|
del script_header, script_timestamp
|
||||||
|
|
||||||
if outfile == '-':
|
if outfile == '-':
|
||||||
sys.stdout.write(script)
|
sys.stdout.write(script)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue