Tim Edwards | 68fc4e6 | 2021-06-12 22:31:21 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # sp_to_spice --- |
| 4 | # |
| 5 | # This script runs as a filter to foundry_install.sh and converts file |
| 6 | # names ending with ".sp" to ".spice". If the file has multiple extensions |
| 7 | # then all are stripped before adding ".spice". |
| 8 | # |
| 9 | # This script is a filter to be run by setting the name of this script as |
| 10 | # the value to "filter=" for the model install in the sky130 Makefile. |
| 11 | |
| 12 | import os |
| 13 | import sys |
| 14 | |
| 15 | def filter(inname): |
| 16 | |
| 17 | filepath = os.path.split(inname)[0] |
| 18 | filename = os.path.split(inname)[1] |
| 19 | |
| 20 | filebits = filename.split('.') |
| 21 | newname = filebits[0] + '.spice' |
| 22 | outname = os.path.join(filepath, newname) |
| 23 | if not os.path.isfile(inname): |
| 24 | print('No such file ' + inname) |
| 25 | return 1 |
| 26 | |
| 27 | print('Renaming file ' + filename + ' to ' + newname) |
| 28 | os.rename(inname, outname) |
| 29 | return 0 |
| 30 | |
| 31 | if __name__ == '__main__': |
| 32 | |
| 33 | # This script expects to get one argument, which is the input file. |
| 34 | # The script renames the file. |
| 35 | |
| 36 | options = [] |
| 37 | arguments = [] |
| 38 | for item in sys.argv[1:]: |
| 39 | if item.find('-', 0) == 0: |
| 40 | options.append(item[1:]) |
| 41 | else: |
| 42 | arguments.append(item) |
| 43 | |
| 44 | if len(arguments) > 0: |
| 45 | infilename = arguments[0] |
| 46 | else: |
| 47 | sys.exit(1) |
| 48 | |
| 49 | result = filter(infilename) |
| 50 | sys.exit(result) |