generate_symbols.py: switched from contextlib to subprocess
Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
This commit is contained in:
parent
2b90c3e2a6
commit
35b26faa05
|
@ -19,20 +19,12 @@
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import symbolator
|
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import errno
|
import errno
|
||||||
import contextlib
|
import contextlib
|
||||||
import traceback
|
import traceback
|
||||||
|
import subprocess
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def redirect_argv(args):
|
|
||||||
sys._argv = sys.argv
|
|
||||||
sys.argv = args
|
|
||||||
yield
|
|
||||||
sys.argv = sys._argv
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
@ -108,20 +100,23 @@ def main(argv):
|
||||||
print(f'The {out_filename} already exists')
|
print(f'The {out_filename} already exists')
|
||||||
return errno.EEXIST
|
return errno.EEXIST
|
||||||
|
|
||||||
arguments = (f'--libname {libname} --title -t -o {out_filename}' +
|
program = ('symbolator' +
|
||||||
f' --output-as-filename -i {str(symbol_v_file)}' +
|
f' --libname {libname} --title -t -o {out_filename}' +
|
||||||
' --format svg')
|
f' --output-as-filename -i {str(symbol_v_file)}' +
|
||||||
with redirect_argv(arguments.split(' ')):
|
' --format svg')
|
||||||
try:
|
res = subprocess.run(
|
||||||
symbolator.main()
|
program.split(' '),
|
||||||
except Exception:
|
stdout=subprocess.PIPE,
|
||||||
print(
|
stderr=subprocess.STDOUT
|
||||||
f'Failed to run: symbolator {arguments}',
|
)
|
||||||
file=sys.stderr
|
if res.returncode != 0:
|
||||||
)
|
print(
|
||||||
print('Error message:\n', file=sys.stderr)
|
f'Failed to run: {program}',
|
||||||
traceback.print_exc()
|
file=sys.stderr
|
||||||
err.write(f'{symbol_v_file}\n')
|
)
|
||||||
|
print('STDOUT:\n', file=sys.stderr)
|
||||||
|
print(res.stdout.decode())
|
||||||
|
err.write(f'{symbol_v_file}\n')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue