Tim Edwards | 1c74f85 | 2021-06-09 16:46:50 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | #-------------------------------------------------------------------- |
| 4 | # Workaround for the problem that xyce does not like having "vt" |
| 5 | # as a subcircuit parameter name, because it is a xyce reserved |
| 6 | # name. Change the parameter name in the one file that uses it. |
| 7 | # This script is not robust, and depends on the fact that the |
| 8 | # one file that declares "vt" does not have any corner model files, |
| 9 | # and the characters "vt" do not appear in any other context. |
| 10 | #-------------------------------------------------------------------- |
| 11 | |
| 12 | import os |
| 13 | import re |
| 14 | import sys |
| 15 | |
| 16 | if len(sys.argv) <= 1: |
| 17 | print('Usage: xyce_hack.py <path_to_file>') |
| 18 | sys.exit(1) |
| 19 | |
| 20 | else: |
| 21 | infile_name = sys.argv[1] |
| 22 | |
| 23 | filepath = os.path.split(infile_name)[0] |
| 24 | outfile_name = os.path.join(filepath, 'temp') |
| 25 | |
| 26 | infile = open(infile_name, 'r') |
| 27 | outfile = open(outfile_name, 'w') |
| 28 | |
| 29 | line_number = 0 |
| 30 | replaced_something = False |
| 31 | for line in infile: |
| 32 | line_number += 1 |
| 33 | |
| 34 | if 'vt' in line: |
| 35 | newline = re.sub('vt', 'local_vt', line) |
| 36 | replaced_something = True |
| 37 | else: |
| 38 | newline = line |
| 39 | |
| 40 | outfile.write(newline) |
| 41 | |
| 42 | infile.close() |
| 43 | outfile.close() |
| 44 | if replaced_something: |
| 45 | print("Something was replaced in '{}'".format(infile_name)) |
| 46 | os.rename(outfile_name, infile_name) |
| 47 | else: |
| 48 | print("Nothing was replaced in '{}'.".format(infile_name)) |
| 49 | os.remove(outfile_name) |
| 50 | |