generate_symbols.py: switched from contextlib to subprocess

Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
This commit is contained in:
Grzegorz Latosinski 2020-11-18 17:19:44 +01:00
parent 2b90c3e2a6
commit 35b26faa05
1 changed files with 18 additions and 23 deletions

View File

@ -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,19 +100,22 @@ 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' --libname {libname} --title -t -o {out_filename}' +
f' --output-as-filename -i {str(symbol_v_file)}' + f' --output-as-filename -i {str(symbol_v_file)}' +
' --format svg') ' --format svg')
with redirect_argv(arguments.split(' ')): res = subprocess.run(
try: program.split(' '),
symbolator.main() stdout=subprocess.PIPE,
except Exception: stderr=subprocess.STDOUT
)
if res.returncode != 0:
print( print(
f'Failed to run: symbolator {arguments}', f'Failed to run: {program}',
file=sys.stderr file=sys.stderr
) )
print('Error message:\n', file=sys.stderr) print('STDOUT:\n', file=sys.stderr)
traceback.print_exc() print(res.stdout.decode())
err.write(f'{symbol_v_file}\n') err.write(f'{symbol_v_file}\n')
return 0 return 0