From 35199ce0e1c5879513f37672335a14ff59d6169d Mon Sep 17 00:00:00 2001 From: Grzegorz Latosinski Date: Tue, 17 Nov 2020 00:04:08 +0100 Subject: [PATCH] Added script for generating Symbolator diagrams Signed-off-by: Grzegorz Latosinski --- .../skywater_pdk/generate_symbolator_plots.py | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py diff --git a/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py new file mode 100644 index 0000000..c879d8b --- /dev/null +++ b/scripts/python-skywater-pdk/skywater_pdk/generate_symbolator_plots.py @@ -0,0 +1,95 @@ +import sys +import symbolator +import argparse +from pathlib import Path +import errno +import contextlib +import traceback + + +@contextlib.contextmanager +def redirect_argv(args): + sys._argv = sys.argv + sys.argv = args + yield + sys.argv = sys._argv + + +def main(argv): + parser = argparse.ArgumentParser(prog=argv[0]) + parser.add_argument( + 'libraries_dir', + help='Path to the libraries directory of skywater-pdk', + type=Path + ) + parser.add_argument( + 'output_dir', + help='Path to the output directory', + type=Path + ) + parser.add_argument( + '--libname', + help='Library name to generate the Symbolator diagrams for', + type=str + ) + parser.add_argument( + '--version', + help='Version for which the Symbolator diagrams should be generated', + type=str + ) + parser.add_argument( + '--create-dirs', + help='Create directories for output when not present', + action='store_true' + ) + + args = parser.parse_args(argv[1:]) + + libraries_dir = args.libraries_dir + + symbol_v_files = libraries_dir.rglob('*.symbol.v') + + for symbol_v_file in symbol_v_files: + 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)}') + libname = symbol_v_file.parts[1] + out_filename = (args.output_dir / + symbol_v_file.resolve() + .relative_to(libraries_dir.resolve())) + out_filename = out_filename.with_suffix('.svg') + out_dir = out_filename.parent + + if not out_dir.exists(): + if args.create_dirs: + out_dir.mkdir(parents=True) + else: + print(f'The output directory {str(out_dir)} is missing') + print('Run the script with --create-dirs to make directories') + return errno.ENOENT + + if out_filename.exists(): + print(f'The {out_filename} already exists') + return errno.EEXIST + + arguments = (f'--libname {libname} --title -t -o {out_filename}' + + f' --output-as-filename -i {str(symbol_v_file)}' + + ' --format svg') + with redirect_argv(arguments.split(' ')): + try: + symbolator.main() + except Exception: + print( + f'Failed to run: symbolator {arguments}', + file=sys.stderr + ) + print('Error message:\n', file=sys.stderr) + traceback.print_exc() + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv))