Added possibility to log files where Symbolator failed to generate plots

Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
This commit is contained in:
Grzegorz Latosinski 2020-11-17 00:26:20 +01:00
parent 35199ce0e1
commit 60e4b48110
1 changed files with 44 additions and 35 deletions

View File

@ -42,6 +42,11 @@ def main(argv):
help='Create directories for output when not present', help='Create directories for output when not present',
action='store_true' action='store_true'
) )
parser.add_argument(
'--failed-inputs',
help='Path to files for which Symbolator failed to generate diagram',
type=Path
)
args = parser.parse_args(argv[1:]) args = parser.parse_args(argv[1:])
@ -49,45 +54,49 @@ def main(argv):
symbol_v_files = libraries_dir.rglob('*.symbol.v') symbol_v_files = libraries_dir.rglob('*.symbol.v')
for symbol_v_file in symbol_v_files: nc = contextlib.nullcontext()
if args.libname and args.libname != symbol_v_file.parts[1]:
continue
if args.version and args.version != symbol_v_file.parts[2]:
continue
print(f'===> {str(symbol_v_file)}') with open(args.failed_inputs, 'w') if args.failed_inputs else nc as err:
libname = symbol_v_file.parts[1] for symbol_v_file in symbol_v_files:
out_filename = (args.output_dir / if args.libname and args.libname != symbol_v_file.parts[1]:
symbol_v_file.resolve() continue
.relative_to(libraries_dir.resolve())) if args.version and args.version != symbol_v_file.parts[2]:
out_filename = out_filename.with_suffix('.svg') continue
out_dir = out_filename.parent
if not out_dir.exists(): print(f'===> {str(symbol_v_file)}')
if args.create_dirs: libname = symbol_v_file.parts[1]
out_dir.mkdir(parents=True) out_filename = (args.output_dir /
else: symbol_v_file.resolve()
print(f'The output directory {str(out_dir)} is missing') .relative_to(libraries_dir.resolve()))
print('Run the script with --create-dirs to make directories') out_filename = out_filename.with_suffix('.svg')
return errno.ENOENT out_dir = out_filename.parent
if out_filename.exists(): if not out_dir.exists():
print(f'The {out_filename} already exists') if args.create_dirs:
return errno.EEXIST out_dir.mkdir(parents=True)
else:
print(f'The output directory {str(out_dir)} is missing')
print('Run the script with --create-dirs')
return errno.ENOENT
arguments = (f'--libname {libname} --title -t -o {out_filename}' + if out_filename.exists():
f' --output-as-filename -i {str(symbol_v_file)}' + print(f'The {out_filename} already exists')
' --format svg') return errno.EEXIST
with redirect_argv(arguments.split(' ')):
try: arguments = (f'--libname {libname} --title -t -o {out_filename}' +
symbolator.main() f' --output-as-filename -i {str(symbol_v_file)}' +
except Exception: ' --format svg')
print( with redirect_argv(arguments.split(' ')):
f'Failed to run: symbolator {arguments}', try:
file=sys.stderr symbolator.main()
) except Exception:
print('Error message:\n', file=sys.stderr) print(
traceback.print_exc() f'Failed to run: symbolator {arguments}',
file=sys.stderr
)
print('Error message:\n', file=sys.stderr)
traceback.print_exc()
err.write(f'{symbol_v_file}\n')
return 0 return 0