#!/usr/bin/env python """ Change all net labels from a static list into global labels """ import os import re import sys import pprint from copy import copy import pcbnew labels = { 'rev02_01.sch': { 'FPGA_ENTROPY_DISABLE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 5450, 'y': 3550, 'ori': 0},], }, 'rev02_02.sch': { 'AMPLIFIED': [#{'t': 'GLabel', 'dir': 'UnSpc', 'x': 10300, 'y': 5000, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9650, 'y': 5000, 'ori': 0, 'x_pos': 400}], 'DIGITIZED_NOISE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 13400, 'y': 4800, 'ori': 0},], #'NOISE_IN': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3950, 'y': 5400, 'ori': 0},], #'NOISE_OUT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4500, 'y': 6000, 'ori': 0},], 'RAW_NOISE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6000, 'y': 5400, 'ori': 0, 'x_pos': 400},], #{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6750, 'y': 5400, 'ori': 0},], }, 'rev02_03.sch': { 'NRST': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 12760, 'y': 4230, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9400, 'y': 4600, 'ori': 0},], 'OSC_IN': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2700, 'y': 5800, 'ori': 1}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 6420, 'y': 4900, 'ori': 0},], 'OSC_OUT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3700, 'y': 5800, 'ori': 1}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 6420, 'y': 5000, 'ori': 0},], 'SWDCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 12760, 'y': 3930, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9400, 'y': 4700, 'ori': 0},], 'SWDIO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 12760, 'y': 4130, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9400, 'y': 4800, 'ori': 0},], }, 'rev02_05.sch': { 'ARM_FPGA_CFG_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4100, 'ori': 0},], 'ARM_FPGA_CFG_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4300, 'ori': 0},], 'ARM_FPGA_CFG_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4400, 'ori': 0},], 'ARM_FPGA_CFG_SCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4200, 'ori': 0},], 'FMC_CLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9990, 'y': 7100, 'ori': 0},], 'FMC_NL': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9990, 'y': 6800, 'ori': 0},], 'FMC_NOE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9990, 'y': 7200, 'ori': 0},], 'FMC_NWAIT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9990, 'y': 7400, 'ori': 0},], 'FMC_NWE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9990, 'y': 7300, 'ori': 0},], 'FMC_SDCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 13120, 'y': 6800, 'ori': 0},], 'FMC_SDNCAS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 13110, 'y': 7700, 'ori': 0},], 'FMC_SDNRAS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 13110, 'y': 7800, 'ori': 0},], 'FMC_SDNWE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 13120, 'y': 6900, 'ori': 0},], 'FPGA_CFG_CTRL_ARM_ENA': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6400, 'y': 2700, 'ori': 0},], 'FPGA_CFG_CTRL_FPGA_DIS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6400, 'y': 5100, 'ori': 0},], 'FPGA_DONE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6400, 'y': 7000, 'ori': 0},], 'FPGA_INIT_B': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6400, 'y': 6200, 'ori': 0},], 'FPGA_PROGRAM_B': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6400, 'y': 6300, 'ori': 0},], 'FT_CTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3000, 'ori': 0},], 'FT_DTR': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 2700, 'ori': 0},], 'FT_MGMT_CTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3700, 'ori': 0},], 'FT_MGMT_DTR': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3400, 'ori': 0},], 'FT_MGMT_RTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3800, 'ori': 0},], 'FT_MGMT_RXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3500, 'ori': 0},], 'FT_MGMT_TXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3600, 'ori': 0},], 'FT_RTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 3100, 'ori': 0},], 'FT_RXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 2800, 'ori': 0},], 'FT_TXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 2900, 'ori': 0},], 'KSM_PROM_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4700, 'ori': 0},], 'KSM_PROM_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4900, 'ori': 0},], 'KSM_PROM_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 5000, 'ori': 0},], 'KSM_PROM_SCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 4800, 'ori': 0},], 'RTC_MFP': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 6300, 'ori': 0},], 'RTC_SCL': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 6200, 'ori': 0},], 'RTC_SDA': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2250, 'y': 6100, 'ori': 0},], }, 'rev02_06.sch': { 'FMC_SDCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2700, 'y': 5000, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 5100, 'ori': 0},], 'FMC_SDNCAS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2700, 'y': 4400, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 4500, 'ori': 0},], 'FMC_SDNRAS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2700, 'y': 4500, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 4600, 'ori': 0},], 'FMC_SDNWE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2700, 'y': 6500, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 6600, 'ori': 0},], }, 'rev02_07.sch': { 'KSM_PROM_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6270, 'y': 5500, 'ori': 0},], 'KSM_PROM_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6270, 'y': 5600, 'ori': 0},], 'KSM_PROM_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 8600, 'y': 5800, 'ori': 0},], 'KSM_PROM_SCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 8600, 'y': 5700, 'ori': 0},], }, 'rev02_08.sch': { 'RTC_MFP': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9500, 'y': 5500, 'ori': 0},], 'RTC_SCL': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9500, 'y': 5600, 'ori': 0},], 'RTC_SDA': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9500, 'y': 5700, 'ori': 0},], }, 'rev02_09.sch': { 'DIFFPAIR': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2300, 'y': 3600, 'ori': 0, 'dim': 70}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 2270, 'y': 3400, 'ori': 0, 'dim': 70}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3660, 'y': 3600, 'ori': 0, 'dim': 70}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3660, 'y': 3400, 'ori': 0, 'dim': 70},], 'FT_CTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 3700, 'ori': 0},], 'FT_DTR': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 3800, 'ori': 0},], 'FT_REF': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6930, 'y': 4500, 'ori': 0},], 'FT_RESET': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6970, 'y': 4300, 'ori': 0},], 'FT_RTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9700, 'y': 3600, 'ori': 0},], 'FT_RXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 11200, 'y': 3500, 'ori': 0},], 'FT_TXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 11200, 'y': 3400, 'ori': 0},], 'FT_VCCA': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6200, 'y': 3800, 'ori': 0},], 'FT_VCCORE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6000, 'y': 3700, 'ori': 0},], 'FT_VPHY': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7550, 'y': 2800, 'ori': 0},], 'FT_VPLL': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7550, 'y': 2600, 'ori': 0},], 'FT_VREGIN': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6000, 'y': 3400, 'ori': 0},], 'USB_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4050, 'y': 3600, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 7090, 'y': 4000, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 13200, 'y': 6100, 'ori': 0},], 'USB_P': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4050, 'y': 3400, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 7090, 'y': 4100, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 12400, 'y': 6100, 'ori': 0},], }, 'rev02_10.sch': { 'DIFFPAIR': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2400, 'y': 3700, 'ori': 0, 'dim': 70}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 2370, 'y': 3500, 'ori': 0, 'dim': 70}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3760, 'y': 3500, 'ori': 0, 'dim': 70}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3760, 'y': 3700, 'ori': 0, 'dim': 70},], 'DM_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2100, 'y': 3600, 'ori': 0, 'dim': 60},], 'DM_P': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2100, 'y': 3500, 'ori': 0, 'dim': 60},], 'FT_MGMT_CTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9800, 'y': 3800, 'ori': 0},], 'FT_MGMT_DTR': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9800, 'y': 3900, 'ori': 0},], 'FT_MGMT_RTS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9800, 'y': 3700, 'ori': 0},], 'FT_MGMT_RXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 11300, 'y': 3600, 'ori': 0},], 'FT_MGMT_TXD': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 11300, 'y': 3500, 'ori': 0},], 'FT_MGMT_VPHY': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7650, 'y': 2900, 'ori': 0},], 'FT_MGMT_VPLL': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7650, 'y': 2700, 'ori': 0},], 'FT_MGMT_VREGIN': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6100, 'y': 3500, 'ori': 0},], 'USB_MGMT_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4150, 'y': 3700, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 6980, 'y': 4100, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 13300, 'y': 6200, 'ori': 0},], 'USB_MGMT_P': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4150, 'y': 3500, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 6980, 'y': 4200, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 12050, 'y': 6200, 'ori': 0},], }, 'rev02_11.sch': { 'AVR_PANIC': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 12500, 'y': 5100, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3170, 'y': 4800, 'ori': 0},], 'AVR_RESET': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9600, 'y': 5700, 'ori': 0},], 'MKM_AVR_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3070, 'y': 4900, 'ori': 0},], 'MKM_AVR_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 8440, 'y': 5100, 'ori': 0},], 'MKM_AVR_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 8440, 'y': 5000, 'ori': 0},], 'MKM_AVR_SCK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 8440, 'y': 5300, 'ori': 0},], 'MKM_CONTROL_AVR_ENA': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3070, 'y': 5000, 'ori': 0},], 'MKM_CONTROL_FPGA_DIS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3070, 'y': 5100, 'ori': 0},], }, 'rev02_12.sch': { 'MKM_AVR_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4800, 'y': 5200, 'ori': 0},], 'MKM_AVR_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7800, 'y': 5500, 'ori': 0},], 'MKM_AVR_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4800, 'y': 5400, 'ori': 0},], 'MKM_AVR_SCK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4800, 'y': 5300, 'ori': 0},], 'MKM_CONTROL_AVR_ENA': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4550, 'y': 5700, 'ori': 0},], 'MKM_CONTROL_FPGA_DIS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4480, 'y': 6800, 'ori': 0},], 'MKM_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 10140, 'y': 5400, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 7000, 'y': 5200, 'ori': 0},], 'MKM_FPGA_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4610, 'y': 6300, 'ori': 0},], 'MKM_FPGA_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6500, 'y': 6600, 'ori': 0},], 'MKM_FPGA_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4610, 'y': 6500, 'ori': 0},], 'MKM_FPGA_SCK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4610, 'y': 6400, 'ori': 0},], 'MKM_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 12800, 'y': 5200, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 4800, 'y': 5500, 'ori': 0},], 'MKM_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 10100, 'y': 5500, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 7000, 'y': 5400, 'ori': 0},], 'MKM_SCK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 10100, 'y': 5600, 'ori': 0}, {'t': 'GLabel', 'dir': 'UnSpc', 'x': 7000, 'y': 5300, 'ori': 0},], }, 'rev02_13.sch': { 'FPGA_CFG_SCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3340, 'y': 5400, 'ori': 0},], 'FPGA_DONE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 5400, 'y': 9500, 'ori': 0},], #'FPGA_DONE_INT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2900, 'y': 5100, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3700, 'y': 9500, 'ori': 0},], 'FPGA_INIT_B': [{'t': 'GLabel', 'dir': 'Input', 'x': 7130, 'y': 5600, 'ori': 2},], #'FPGA_INIT_B_INT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4800, 'y': 5400, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3340, 'y': 5200, 'ori': 0},], #'FPGA_JTAG_TCK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2900, 'y': 5800, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 8430, 'y': 8500, 'ori': 0},], #'FPGA_JTAG_TDI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2900, 'y': 5900, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 8430, 'y': 8700, 'ori': 0},], #'FPGA_JTAG_TDO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2900, 'y': 6000, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 8430, 'y': 8800, 'ori': 0},], #'FPGA_JTAG_TMS': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2900, 'y': 6100, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 8430, 'y': 8600, 'ori': 0},], #'FPGA_PROGRAM_B': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7010, 'y': 5100, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 3340, 'y': 5300, 'ori': 0},], }, 'rev02_15.sch': { 'ARM_FPGA_CFG_CS_N': [{'t': 'GLabel', 'dir': 'Input', 'x': 2980, 'y': 5630, 'ori': 0},], 'ARM_FPGA_CFG_MISO': [{'t': 'GLabel', 'dir': 'Output', 'x': 5160, 'y': 5930, 'ori': 2},], 'ARM_FPGA_CFG_MOSI': [{'t': 'GLabel', 'dir': 'Input', 'x': 2980, 'y': 5830, 'ori': 0},], 'ARM_FPGA_CFG_SCLK': [{'t': 'GLabel', 'dir': 'Input', 'x': 2980, 'y': 5730, 'ori': 0},], 'FPGA_CFG_CS_N': [{'t': 'GLabel', 'dir': 'Input', 'x': 3090, 'y': 6730, 'ori': 0},], 'FPGA_CFG_CTRL_ARM_ENA': [{'t': 'GLabel', 'dir': 'Input', 'x': 430, 'y': 6130, 'ori': 0},], 'FPGA_CFG_CTRL_FPGA_DIS': [{'t': 'GLabel', 'dir': 'Input', 'x': 430, 'y': 6430, 'ori': 0},], 'FPGA_CFG_MISO': [{'t': 'GLabel', 'dir': 'Output', 'x': 5160, 'y': 7030, 'ori': 2},], 'FPGA_CFG_MOSI': [{'t': 'GLabel', 'dir': 'Input', 'x': 3090, 'y': 6930, 'ori': 0},], 'FPGA_CFG_SCLK': [{'t': 'GLabel', 'dir': 'Input', 'x': 3090, 'y': 6830, 'ori': 0},], 'FPGA_GCLK': [{'t': 'GLabel', 'dir': 'Input', 'x': 6700, 'y': 9500, 'ori': 0},], #'FPGA_PROM_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6900, 'y': 6300, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 5160, 'y': 5630, 'ori': 0},], #'FPGA_PROM_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6900, 'y': 6400, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 2980, 'y': 5930, 'ori': 0},], #'FPGA_PROM_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9150, 'y': 6600, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 5160, 'y': 5830, 'ori': 0},], #'FPGA_PROM_SCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 9150, 'y': 6500, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 5160, 'y': 5730, 'ori': 0},], #'FPGA_PROM_W_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6900, 'y': 6500, 'ori': 0}, # {'t': 'GLabel', 'dir': 'UnSpc', 'x': 420, 'y': 6830, 'ori': 0},], #'SPI_A_TRISTATE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3360, 'y': 5510, 'ori': 1},], #'SPI_B_TRISTATE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3060, 'y': 7230, 'ori': 0},], }, 'rev02_17.sch': { 'FMC_CLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7200, 'y': 7800, 'ori': 0},], 'FMC_NOE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7200, 'y': 8700, 'ori': 0},], 'FMC_NWAIT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2220, 'y': 8700, 'ori': 0},], 'FMC_NWE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2220, 'y': 8800, 'ori': 0},], 'MKM_FPGA_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2230, 'y': 5900, 'ori': 0},], 'MKM_FPGA_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2230, 'y': 6200, 'ori': 0},], 'MKM_FPGA_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2230, 'y': 6100, 'ori': 0},], 'MKM_FPGA_SCK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2230, 'y': 6400, 'ori': 0},], }, 'rev02_18.sch': { 'POK_VCCAUX': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4000, 'y': 6200, 'ori': 3},], 'POK_VCCO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 4000, 'y': 9700, 'ori': 0},], 'PWR_ENA_VCCAUX': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 1900, 'y': 4740, 'ori': 1},], 'PWR_ENA_VCCO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 1400, 'y': 7500, 'ori': 0},], }, 'rev02_19.sch': { 'FPGA_ENTROPY_DISABLE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2100, 'y': 7200, 'ori': 0},], 'FPGA_GCLK': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2100, 'y': 7300, 'ori': 0},], }, 'rev02_20.sch': { 'DIGITIZED_NOISE': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2460, 'y': 7400, 'ori': 0},], 'FMC_NL': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2460, 'y': 8300, 'ori': 0},], 'FPGA_CFG_CS_N': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3600, 'y': 6200, 'ori': 0},], 'FPGA_CFG_MISO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3600, 'y': 5300, 'ori': 0},], 'FPGA_CFG_MOSI': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3600, 'y': 5200, 'ori': 0},], }, 'rev02_24.sch': { 'POK_VCCINT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 5350, 'y': 9100, 'ori': 0},], 'PWR_ENA_VCCINT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2700, 'y': 5900, 'ori': 0},], }, 'rev02_25.sch': { 'POK_VCCAUX': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 1540, 'y': 8700, 'ori': 0},], 'POK_VCCINT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 5100, 'y': 5300, 'ori': 0},], 'POK_VCCO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 6110, 'y': 8700, 'ori': 0},], 'PWR_ENA_VCCAUX': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 7250, 'y': 5300, 'ori': 0},], 'PWR_ENA_VCCINT': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 2660, 'y': 5300, 'ori': 0},], 'PWR_ENA_VCCO': [{'t': 'GLabel', 'dir': 'UnSpc', 'x': 3690, 'y': 8700, 'ori': 0},], }, } def update_text_line(prev, entrys): m = re.match('^Text Label (\d+) +(\d+) +(\d+) +(\d+) +~', prev) x, y, orient, dim = m.groups() x = int(x) y = int(y) orient = int(orient) dim = int(dim) for this in entrys: if this['x'] != x and this['y'] != y: #sys.stderr.write("Wrong X {} or Y {}: {!r}\n".format(this['x'], this['y'], this)) continue new = copy(this) if 'dim' not in new: new['dim'] = 48 if 'x_pos' in new: new['x'] = new['x'] + new['x_pos'] if this['t'] == 'GLabel': return 'Text GLabel {x:} {y:} {ori:} {dim:} {shape:} ~ 0'.format( x = new['x'], y = new['y'], ori = new['ori'], dim = new['dim'], shape = new['dir'], ) if this['t'] == 'Label': return 'Text Label {x:} {y:} {ori:} {dim:} ~ 0'.format( x = new['x'], y = new['y'], ori = new['ori'], dim = new['dim'], ) return prev def fix_labels(fn_in, fn_out, file_labels): in_ = open(fn_in) out = open(fn_out, 'w') prev = None print('Changing net labels to GLabel in {}'.format(fn_in)) for line in in_.readlines(): #print('R: {!r}'.format(line)) if prev is not None: while prev.endswith('\n'): prev = prev[:-1] text = line[:-1] if re.match('^[A-Z_]+', text): #m = re.match('^Text Label (.+) ~', prev) #prev = 'Text GLabel {} UnSpc ~ 0'.format(m.groups()[0]) if text in file_labels: new = update_text_line(prev, file_labels[text]) if new != prev: print("Label: {!r} OLD {!r}, NEW : {!r}".format(text, prev, new)) prev = new else: print("Label: {!r} UNCHANGED : {}".format(text, prev)) out.write(prev + '\n') prev = None elif line.startswith('Text Label '): prev = line continue out.write(line) return True def main(schemas): for this in schemas: fn = os.path.basename(this) file_labels = [] global labels if fn in labels: file_labels = labels[fn] if fix_labels(this, this + '.tmp', file_labels): os.rename(this + '.tmp', this) return True if __name__ == '__main__': try: if len(sys.argv) == 0: sys.stderr.write('Syntax: fix-labels.py *.sch\n') sys.exit(1) schemas = [x for x in sys.argv if x.endswith('.sch')] res = main(schemas) if res: sys.exit(0) sys.exit(1) except KeyboardInterrupt: pass