322 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			322 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # 本脚本的功能为重命名当前文件夹下的文件,其重命名的依据为预先定义的列表。
 | ||
| # 将该脚本放置到fpga_image_xxx/reg/head目录下执行即可。
 | ||
| 
 | ||
| # 文件的改动如下:
 | ||
| #   1.soc/macro目录下头文件去掉名称中的"_m"。
 | ||
| #   2.soc/struct目录下的头文件名加上"_s",同时更改文件中的文件名宏定义。
 | ||
| #   3.gpio_mtx_signal.h更改为gpio_mtx_sig.h,调整文件中sfc、smc相关信号宏定义,向前兼容(详见list_mtx_sig变量)。
 | ||
| #   4.soc/phy目录更改为plc/phy目录,删除目录下的struct文件夹,重命名macro文件夹为parse_reg,去掉parse_reg目录下文件名称中的"_m"。
 | ||
| #   5.soc/mac目录更改为plc/mac目录,删除目录下的struct文件夹,重命名macro文件夹为parse_reg,去掉parse_reg目录下文件名称中的"_m"。
 | ||
| #   6.调整mac相关宏定义,向前兼容,主要涉及mac相关头文件以及chip_reg_base.h(详见list_reg_operation、list_reg_base)
 | ||
| #   7.删除所有空文件夹
 | ||
| 
 | ||
| # 当前版本需要额外拷贝的文件为:ly68s32xx.h efuse_mapping.h hw_war.h ds35x1gaxxx.h gd25lq16x.h
 | ||
| 
 | ||
| # 当前列表对应的fpga image版本为 kunlun3_mpw_fpga_img_auto_export_1992_220530_1501
 | ||
| 
 | ||
| import os
 | ||
| import sys
 | ||
| import shutil
 | ||
| 
 | ||
| g_list_rename = [
 | ||
|     ["chip_irq_vector.h", "chip_irq_vector.h"],
 | ||
|     ["chip_reg_base.h", "chip_reg_base.h"],
 | ||
|     ["gpio_mtx_signal.h", "gpio_mtx_sig.h"],
 | ||
|     ["rfplc_reg_base.h", "rfplc_reg_base.h"],
 | ||
|     ["soc\\phy", "plc\\phy"],
 | ||
|     ["soc\\mac", "plc\\mac"],
 | ||
| 
 | ||
|     ["soc\\macro\\ada_reg_m.h", "soc\\macro\\ada_reg.h"],
 | ||
|     ["soc\\macro\\ahb_lite_reg_m.h", "soc\\macro\\ahb_rf.h"],
 | ||
|     ["soc\\macro\\ahb_l_reg_m.h", "soc\\macro\\ahb_l_reg.h"],
 | ||
|     # cache IP有更新,头文件名称去掉了apb_,这里为了减少改动,依然保留apb_
 | ||
|     ["soc\\macro\\cache_reg_m.h", "soc\\macro\\apb_cache_reg.h"],
 | ||
|     ["soc\\macro\\apb_lite_reg_m.h", "soc\\macro\\apb_glb_reg.h"],
 | ||
|     ["soc\\macro\\dig_pin_reg_m.h", "soc\\macro\\pin_rf.h"],
 | ||
|     ["soc\\macro\\dma_reg_m.h", "soc\\macro\\dma_reg.h"],
 | ||
|     ["soc\\macro\\dtop_ana_inf_reg_m.h", "soc\\macro\\ana_dig_wrap_rf.h"],
 | ||
|     ["soc\\macro\\fdma_mst_reg_m.h", "soc\\macro\\fdma_mst_reg.h"],
 | ||
|     ["soc\\macro\\gpio_mtx_reg_m.h", "soc\\macro\\gpio_mtx_reg.h"],
 | ||
|     ["soc\\macro\\gpio_reg_m.h", "soc\\macro\\gpio_reg.h"],
 | ||
|     ["soc\\macro\\gtmr_reg_m.h", "soc\\macro\\gtmr_reg.h"],
 | ||
|     ["soc\\macro\\i2c_master_reg_m.h", "soc\\macro\\i2c_reg.h"],
 | ||
|     ["soc\\macro\\intc_reg_m.h", "soc\\macro\\intc_reg.h"],
 | ||
|     ["soc\\macro\\ledc_reg_m.h", "soc\\macro\\ledc_reg.h"],
 | ||
|     ["soc\\macro\\mail_box_reg_m.h", "soc\\macro\\mail_box_rf.h"],
 | ||
|     # 去掉了pmu
 | ||
|     # ["soc\\macro\\pmu_ana_inf_reg_m.h", "soc\\macro\\ana_pmu_wrap_rf.h"],
 | ||
|     # ["soc\\macro\\pmu_reg_m.h", "soc\\macro\\pmu_rf.h"],
 | ||
|     ["soc\\macro\\pwm_reg_m.h", "soc\\macro\\pwm_reg.h"],
 | ||
|     # sadc寄存器变更为sar_adc_reg_m.h
 | ||
|     # ["soc\\macro\\sadc0_reg_m.h", "soc\\macro\\sadc0_reg.h"],
 | ||
|     # ["soc\\macro\\sadc1_reg_m.h", "soc\\macro\\sadc1_reg.h"],
 | ||
|     ["soc\\macro\\sar_adc_reg_m.h", "soc\\macro\\sar_adc_reg.h"],
 | ||
|     ["soc\\macro\\sec_sys_reg_m.h", "soc\\macro\\sec_sys_rf.h"],
 | ||
|     ["soc\\macro\\sfc_reg_m.h", "soc\\macro\\sfc_rf.h"],
 | ||
|     ["soc\\macro\\smc_reg_m.h", "soc\\macro\\smc_rf.h"],
 | ||
|     ["soc\\macro\\spinlock_reg_m.h", "soc\\macro\\spinlock_top.h"],
 | ||
|     ["soc\\macro\\spi_reg_m.h", "soc\\macro\\spi_reg.h"],
 | ||
|     ["soc\\macro\\uart_reg_m.h", "soc\\macro\\uart_reg.h"],
 | ||
|     ["soc\\macro\\wdg_reg_m.h", "soc\\macro\\wdg_reg.h"],
 | ||
|     # afft_reg_m.h未更改为audio_fft_rf.h,因为仅afft_hw.c中使用该头文件
 | ||
|     ["soc\\macro\\afft_reg_m.h", "soc\\macro\\afft_reg.h"],
 | ||
|     ["soc\\macro\\eq_reg_m.h", "soc\\macro\\eq_reg.h"],
 | ||
|     ["soc\\macro\\gmac_reg_m.h", "soc\\macro\\gmac_reg.h"],
 | ||
|     ["soc\\macro\\bond_reg_m.h", "soc\\macro\\bond_reg.h"],
 | ||
|     ["soc\\macro\\efuse_ctrl_reg_m.h", "soc\\macro\\efuse_dig_reg.h"],
 | ||
|     ["soc\\macro\\pll_cal_reg_m.h", "soc\\macro\\pll_cal_reg.h"],
 | ||
|     ["soc\\macro\\rtc_tmr_reg_m.h", "soc\\macro\\rtc_tmr_reg.h"],
 | ||
| 
 | ||
|     ["soc\\struct\\ada_reg.h", "soc\\struct\\ada_reg_s.h"],
 | ||
|     ["soc\\struct\\ahb_lite_reg.h", "soc\\struct\\ahb_rf_s.h"],
 | ||
|     ["soc\\struct\\ahb_l_reg.h", "soc\\struct\\ahb_l_reg_s.h"],
 | ||
|     ["soc\\struct\\cache_reg.h", "soc\\struct\\apb_cache_reg_s.h"],
 | ||
|     ["soc\\struct\\apb_lite_reg.h", "soc\\struct\\apb_glb_reg_s.h"],
 | ||
|     ["soc\\struct\\dig_pin_reg.h", "soc\\struct\\dig_pin_reg_s.h"],
 | ||
|     ["soc\\struct\\dma_reg.h", "soc\\struct\\dma_reg_s.h"],
 | ||
|     ["soc\\struct\\dtop_ana_inf_reg.h", "soc\\struct\\ana_dig_wrap_rf_s.h"],
 | ||
|     ["soc\\struct\\fdma_mst_reg.h", "soc\\struct\\fdma_mst_reg_s.h"],
 | ||
|     ["soc\\struct\\gpio_mtx_reg.h", "soc\\struct\\gpio_mtx_reg_s.h"],
 | ||
|     ["soc\\struct\\gpio_reg.h", "soc\\struct\\gpio_reg_s.h"],
 | ||
|     ["soc\\struct\\gtmr_reg.h", "soc\\struct\\gtmr_reg_s.h"],
 | ||
|     ["soc\\struct\\i2c_master_reg.h", "soc\\struct\\i2c_reg_s.h"],
 | ||
|     ["soc\\struct\\intc_reg.h", "soc\\struct\\intc_reg_s.h"],
 | ||
|     ["soc\\struct\\ledc_reg.h", "soc\\struct\\ledc_reg_s.h"],
 | ||
|     ["soc\\struct\\mail_box_reg.h", "soc\\struct\\mail_box_rf_s.h"],
 | ||
|     # ["soc\\struct\\pmu_ana_inf_reg.h", "soc\\struct\\ana_pmu_wrap_rf_s.h"],
 | ||
|     # ["soc\\struct\\pmu_reg.h", "soc\\struct\\pmu_rf_s.h"],
 | ||
|     ["soc\\struct\\pwm_reg.h", "soc\\struct\\pwm_reg_s.h"],
 | ||
|     # ["soc\\struct\\sadc0_reg.h", "soc\\struct\\sadc0_reg_s.h"],
 | ||
|     # ["soc\\struct\\sadc1_reg.h", "soc\\struct\\sadc1_reg_s.h"],
 | ||
|     ["soc\\struct\\sar_adc_reg.h", "soc\\struct\\sar_adc_reg_s.h"],
 | ||
|     ["soc\\struct\\sec_sys_reg.h", "soc\\struct\\sec_sys_rf_s.h"],
 | ||
|     ["soc\\struct\\sfc_reg.h", "soc\\struct\\sfc_rf_s.h"],
 | ||
|     ["soc\\struct\\smc_reg.h", "soc\\struct\\smc_rf_s.h"],
 | ||
|     ["soc\\struct\\spinlock_reg.h", "soc\\struct\\spinlock_top_s.h"],
 | ||
|     ["soc\\struct\\spi_reg.h", "soc\\struct\\spi_reg_s.h"],
 | ||
|     ["soc\\struct\\uart_reg.h", "soc\\struct\\uart_reg_s.h"],
 | ||
|     ["soc\\struct\\wdg_reg.h", "soc\\struct\\wdg_reg_s.h"],
 | ||
|     ["soc\\struct\\afft_reg.h", "soc\\struct\\afft_reg_s.h"],
 | ||
|     ["soc\\struct\\eq_reg.h", "soc\\struct\\eq_reg_s.h"],
 | ||
|     ["soc\\struct\\gmac_reg.h", "soc\\struct\\gmac_reg_s.h"],
 | ||
|     ["soc\\struct\\bond_reg.h", "soc\\struct\\bond_reg_s.h"],
 | ||
|     ["soc\\struct\\efuse_ctrl_reg.h", "soc\\struct\\efuse_dig_reg_s.h"],
 | ||
|     ["soc\\struct\\pll_cal_reg.h", "soc\\struct\\pll_cal_reg_s.h"],
 | ||
|     ["soc\\struct\\rtc_tmr_reg.h", "soc\\struct\\rtc_tmr_reg_s.h"],
 | ||
|     # usb头文件不上传,因此需要手动删除usb文件再执行脚本
 | ||
| ]
 | ||
| 
 | ||
| def delete_empty_folder(path):
 | ||
|     if os.path.isdir(path):
 | ||
|         for dir in os.listdir(path):
 | ||
|             path_dir = os.path.join(path, dir)
 | ||
|             if os.path.isdir(path_dir):
 | ||
|                 delete_empty_folder(path_dir)
 | ||
|         if not os.listdir(path):
 | ||
|             print("删除空目录:", path)
 | ||
|             os.rmdir(path)
 | ||
|         # else:
 | ||
|         #     print("目录非空:", path)
 | ||
| 
 | ||
| def main():
 | ||
|     dir_script = os.path.split(os.path.realpath(__file__))[0]
 | ||
|     file_renamed = []
 | ||
|     file_not_find = []
 | ||
|     file_all = []
 | ||
|     file_rename_num = len(g_list_rename)
 | ||
| 
 | ||
|     # 解析文件列表
 | ||
|     for i in range(0, file_rename_num):
 | ||
|         path_src = os.path.join(dir_script, g_list_rename[i][0])
 | ||
|         path_dst = os.path.join(dir_script, g_list_rename[i][1])
 | ||
|         if not os.access(path_src, os.F_OK | os.W_OK):
 | ||
|             if not os.access(path_dst, os.F_OK):
 | ||
|                 file_not_find.append(path_src)
 | ||
|         else:
 | ||
|             file_renamed.append([path_src, path_dst])
 | ||
| 
 | ||
|     # 获取当前所有文件列表
 | ||
|     for dir, dirs, files in os.walk(dir_script):
 | ||
|         # 跳过mac和phy目录,后续直接按目录操作
 | ||
|         dir_relative = str(dir).replace(dir_script, "")
 | ||
|         if dir_relative.count("plc") or dir_relative.count("soc\\phy") or\
 | ||
|             (dir_relative.count("soc\\mac") and (not dir_relative.count("soc\\macro"))):
 | ||
|             continue
 | ||
|         for file_temp in files:
 | ||
|             file_all.append(os.path.join(dir, file_temp))
 | ||
|     file_all.remove(os.path.realpath(__file__))
 | ||
|     for i in range(0, file_rename_num):
 | ||
|         for j in range(0, 2):
 | ||
|             file_temp = os.path.join(dir_script, g_list_rename[i][j])
 | ||
|             if file_all.count(file_temp):
 | ||
|                 file_all.remove(file_temp)
 | ||
| 
 | ||
|     if len(file_not_find):
 | ||
|         print("***************************************************************")
 | ||
|         print("未找到以下文件:")
 | ||
|         for file_temp in file_not_find:
 | ||
|             print(file_temp)
 | ||
|     if len(file_all):
 | ||
|         print("***************************************************************")
 | ||
|         print("存在以下新文件: ")
 | ||
|         for file_temp in file_all:
 | ||
|             print(file_temp)
 | ||
|     while (len(file_not_find) or len(file_all)):
 | ||
|         input_str = input("输入 Y继续,N退出\n")
 | ||
|         if str(input_str) == "y" or str(input_str) == "Y":
 | ||
|             break
 | ||
|         elif str(input_str) == "n" or str(input_str) == "N":
 | ||
|             sys.exit(1)
 | ||
|         else:
 | ||
|             continue
 | ||
| 
 | ||
|     # 重命名文件
 | ||
|     print("开始重命名文件")
 | ||
|     for i in range(0, len(file_renamed)):
 | ||
|         print("%s --> %s" % (file_renamed[i][0], file_renamed[i][1]))
 | ||
|         # 创建不存在的文件夹
 | ||
|         parent_dir = os.path.dirname(file_renamed[i][1])
 | ||
|         if not os.path.exists(parent_dir):
 | ||
|             os.makedirs(parent_dir)
 | ||
|         try:
 | ||
|             os.rename(file_renamed[i][0], file_renamed[i][1])
 | ||
|         except:
 | ||
|             shutil.move(file_renamed[i][0], file_renamed[i][1])
 | ||
|         # struct文件夹中的文件,需要同步更改头文件中的宏定义,目前只更改soc文件
 | ||
|         if str(parent_dir).count("soc\\struct"):
 | ||
|             str_list = str(file_renamed[i][0]).split("\\")
 | ||
|             header_old = str(str_list[len(str_list) - 1]).upper().replace(".", "_")
 | ||
|             str_list = str(file_renamed[i][1]).split("\\")
 | ||
|             header_new = str(str_list[len(str_list) - 1]).upper().replace(".", "_")
 | ||
|             print("macro of file name old:%s, new:%s" % (header_old, header_new))
 | ||
|             with open(file_renamed[i][1], "r+", newline="\n") as fd:
 | ||
|                 data = fd.read()
 | ||
|                 data = data.replace(header_old, header_new)
 | ||
|                 fd.seek(0, 0)
 | ||
|                 fd.write(data)
 | ||
|                 fd.truncate()
 | ||
| 
 | ||
|     # # 部分signal名称变更为kl1、kl2风格
 | ||
|     # list_mtx_sig = [
 | ||
|     #     "GPIO_MTX_SFC_SPI_CLK_OUT_MON", "GPIO_MTX_SFC_SPI_CLK_OUT    ",
 | ||
|     #     "GPIO_MTX_SFC_SPI_CS1_OUT_MON", "GPIO_MTX_SFC_SPI_CS1_OUT    ",
 | ||
|     #     "GPIO_MTX_SFC_SPI_CS0_OUT_MON", "GPIO_MTX_SFC_SPI_CS0_OUT    ",
 | ||
|     #     "GPIO_MTX_SFC_SPI_SI_OUT_MON", "GPIO_MTX_SFC_SPI_D0_OUT    ",
 | ||
|     #     "GPIO_MTX_SFC_SPI_SO_OUT_MON", "GPIO_MTX_SFC_SPI_D1_OUT    ",
 | ||
|     #     "GPIO_MTX_SFC_SPI_WP_OUT_MON", "GPIO_MTX_SFC_SPI_D2_OUT    ",
 | ||
|     #     "GPIO_MTX_SFC_SPI_HOLD_OUT_MON", "GPIO_MTX_SFC_SPI_D3_OUT      ",
 | ||
|     #     "GPIO_MTX_SMC_SPI_CLK_OUT_MON", "GPIO_MTX_SMC_SPI_CLK_OUT    ",
 | ||
|     #     "GPIO_MTX_SMC_SPI_CS_OUT_MON", "GPIO_MTX_SMC_SPI_CS_OUT    ",
 | ||
|     #     "GPIO_MTX_SMC_SPI_SI_OUT_MON", "GPIO_MTX_SMC_SPI_SI_OUT    ",
 | ||
|     #     "GPIO_MTX_SMC_SPI_SO_OUT_MON", "GPIO_MTX_SMC_SPI_SO_OUT    ",
 | ||
|     #     "GPIO_MTX_SMC_SPI_SIO2_OUT_MON", "GPIO_MTX_SMC_SPI_SIO2_OUT    ",
 | ||
|     #     "GPIO_MTX_SMC_SPI_SIO3_OUT_MON", "GPIO_MTX_SMC_SPI_SIO3_OUT    ",
 | ||
|     # ]
 | ||
|     # path_src = os.path.join(dir_script, "gpio_mtx_sig.h")
 | ||
|     # print("Modify the name of the signal, path:%s" % path_src)
 | ||
|     # with open(path_src, "r+", newline="\n") as fd:
 | ||
|     #     data = fd.read()
 | ||
|     #     for i in range(0, int(len(list_mtx_sig) / 2)):
 | ||
|     #         data = data.replace(list_mtx_sig[i * 2], list_mtx_sig[i * 2 + 1])
 | ||
|     #     fd.seek(0, 0)
 | ||
|     #     fd.write(data)
 | ||
|     #     fd.truncate()
 | ||
| 
 | ||
|     # plc phy\mac文件需要新增一个文件夹,且去掉原文件夹
 | ||
|     path_plc = ["mac", "phy"]
 | ||
|     for plc in path_plc:
 | ||
|         path_src = os.path.join(dir_script, "plc", plc, "macro")
 | ||
|         path_dst = os.path.join(dir_script, "plc", plc, "parse_reg")
 | ||
|         path_struct = os.path.join(dir_script, "plc", plc, "struct")
 | ||
|         if not os.path.exists(path_src):
 | ||
|             continue
 | ||
|         if os.path.exists(path_dst):
 | ||
|             shutil.rmtree(path_dst)
 | ||
|         shutil.copytree(path_src, path_dst)
 | ||
|         files = os.listdir(path_dst)
 | ||
|         for i in range(0, len(files)):
 | ||
|             file_temp = os.path.join(path_dst, files[i])
 | ||
|             os.rename(file_temp, file_temp.replace("_m.h", ".h"))
 | ||
|         shutil.rmtree(path_src)
 | ||
|         shutil.rmtree(path_struct)
 | ||
|     # mac需要将操作寄存器的宏定义修改为之前的版本,且基地址宏定义也需要调整
 | ||
|     list_reg_operation = [
 | ||
|         "MAC_SYS_READ_REG", "RGF_MAC_READ_REG",
 | ||
|         "MAC_SYS_WRITE_REG", "RGF_MAC_WRITE_REG",
 | ||
|         "MAC_SYS_BASEADDR", "RGF_MAC_BASEADDR",
 | ||
|         "MAC_RX_READ_REG", "RGF_RX_READ_REG",
 | ||
|         "MAC_RX_WRITE_REG", "RGF_RX_WRITE_REG",
 | ||
|         "MAC_RX_BASEADDR", "RGF_RX_BASEADDR",
 | ||
|         "MAC_TMR_READ_REG", "RGF_TMR_READ_REG",
 | ||
|         "MAC_TMR_WRITE_REG", "RGF_TMR_WRITE_REG",
 | ||
|         "MAC_TMR_BASEADDR", "RGF_TMR_BASEADDR",
 | ||
|         "MAC_RAW_READ_REG", "RGF_RAW_READ_REG",
 | ||
|         "MAC_RAW_WRITE_REG", "RGF_RAW_WRITE_REG",
 | ||
|         "MAC_RAW_BASEADDR", "RGF_RAW_BASEADDR",
 | ||
|         "MAC_HWQ_READ_REG", "RGF_HWQ_READ_REG",
 | ||
|         "MAC_HWQ_WRITE_REG", "RGF_HWQ_WRITE_REG",
 | ||
|         "MAC_HWQ_BASEADDR", "RGF_HWQ_BASEADDR"
 | ||
|     ]
 | ||
|     path_src = os.path.join(dir_script, "plc", "mac", "parse_reg")
 | ||
|     print("Modify the macro of the mac, path:%s" % path_src)
 | ||
|     files = os.listdir(path_src)
 | ||
|     for file in files:
 | ||
|         str_temp = str(file).replace("reg.h", "READ_REG").upper()
 | ||
|         try:
 | ||
|             index = list_reg_operation.index(str_temp)
 | ||
|         except:
 | ||
|             continue
 | ||
|         print("file name:%s, %s -> %s, %s -> %s, %s -> %s" % (file,
 | ||
|             list_reg_operation[index], list_reg_operation[index + 1],
 | ||
|             list_reg_operation[index + 2], list_reg_operation[index + 3],
 | ||
|             list_reg_operation[index + 4], list_reg_operation[index + 5]))
 | ||
|         with open(os.path.join(path_src, file), "r+", newline="\n") as fd:
 | ||
|             data = fd.read()
 | ||
|             data = data.replace(list_reg_operation[index], list_reg_operation[index + 1])
 | ||
|             data = data.replace(list_reg_operation[index + 2], list_reg_operation[index + 3])
 | ||
|             data = data.replace(list_reg_operation[index + 4], list_reg_operation[index + 5])
 | ||
|             fd.seek(0, 0)
 | ||
|             fd.write(data)
 | ||
|             fd.truncate()
 | ||
|     list_reg_base = [
 | ||
|         "MAC_SYS_BASEADDR", "RGF_MAC_BASEADDR",
 | ||
|         "MAC_RX_BASEADDR", "RGF_RX_BASEADDR",
 | ||
|         "MAC_TMR_BASEADDR", "RGF_TMR_BASEADDR",
 | ||
|         "MAC_RAW_BASEADDR", "RGF_RAW_BASEADDR",
 | ||
|         "MAC_HWQ_BASEADDR", "RGF_HWQ_BASEADDR"
 | ||
|     ]
 | ||
|     path_src = os.path.join(dir_script, "chip_reg_base.h")
 | ||
|     print("Modify the macro of the mac, path:%s" % path_src)
 | ||
|     with open(path_src, "r+", newline="\n") as fd:
 | ||
|         data = fd.read()
 | ||
|         for i in range(0, int(len(list_reg_base) / 2)):
 | ||
|             data = data.replace(list_reg_base[i * 2], list_reg_base[i * 2 + 1])
 | ||
|         fd.seek(0, 0)
 | ||
|         fd.write(data)
 | ||
|         fd.truncate()
 | ||
| 
 | ||
|     # rfplc phy\mac文件需要新增一个文件夹,且去掉原文件夹
 | ||
|     # rfplc永远只更新mac,不包含phy的更新
 | ||
|     path_plc = ["mac", "phy"]
 | ||
|     for rfplc in path_plc:
 | ||
|         path_src = os.path.join(dir_script, "rfplc", rfplc, "macro")
 | ||
|         path_dst = os.path.join(dir_script, "plc", "mac", "parse_reg")
 | ||
|         path_struct = os.path.join(dir_script, "rfplc", rfplc, "struct")
 | ||
|         if not os.path.exists(path_src):
 | ||
|             continue
 | ||
|         # shutil.copytree(path_src, path_dst)
 | ||
|         files = os.listdir(path_src)
 | ||
|         for file in files:
 | ||
|             file_src = os.path.join(path_src, file)
 | ||
|             file_dst = os.path.join(path_dst, file).replace("_m.h", ".h")
 | ||
|             os.rename(file_src, file_dst)
 | ||
|         shutil.rmtree(path_src)
 | ||
|         shutil.rmtree(path_struct)
 | ||
| 
 | ||
|     delete_empty_folder(dir_script)
 | ||
| 
 | ||
|     print("文件重命名完成")
 | ||
| 
 | ||
| if __name__ == '__main__':
 | ||
|     main()
 |