上传文件至 ''
update version 1.1
This commit is contained in:
		| @@ -19,8 +19,6 @@ | |||||||
| pip install pyyaml | pip install pyyaml | ||||||
| python modify.py | python modify.py | ||||||
| ``` | ``` | ||||||
| 请手动替换脚本中header和工作目录为你自己的 |  | ||||||
| header获取方法:立创EDA导出gerber→随意打开一个gerber文件 |  | ||||||
|  |  | ||||||
| # 文件结构 | # 文件结构 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,14 +1,15 @@ | |||||||
| # 此处存放文件头 文件名等配置信息 | # 此处存放文件头 文件名等配置信息 | ||||||
|  |  | ||||||
| # 工作目录 | # 工作目录 | ||||||
| WorkDir: C:\Users\Public\Desktop | WorkDir: ../ | ||||||
|  |  | ||||||
| # 输出目录,可留空 | # 输出目录,可留空 | ||||||
| DestDir:  | DestDir: ../out | ||||||
|  |  | ||||||
| Header: |- | Header: |- | ||||||
|   G04 EasyEDA Pro v1.9.28, 2023-01-14 19:19:00* |   G04 EasyEDA v6.5.23, 2023-02-21 20:00:12* | ||||||
|   G04 Gerber Generator version 0.3* |   G04 79a7123266304c56a38f2e75c23f1545,85767ff9b60442ae9acdb7a1f8f5a820,10* | ||||||
|  |   G04 Gerber Generator version 0.2* | ||||||
|    |    | ||||||
| TextFileName: PCB下单必读.txt | TextFileName: PCB下单必读.txt | ||||||
| TextFileContent: |- | TextFileContent: |- | ||||||
|   | |||||||
							
								
								
									
										38
									
								
								modify.py
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								modify.py
									
									
									
									
									
								
							| @@ -1,3 +1,4 @@ | |||||||
|  | ''' | ||||||
| Warn = """\033[0;31;40m | Warn = """\033[0;31;40m | ||||||
| =======警告======= | =======警告======= | ||||||
| 此脚本仅包含有限的“自动重命名”功能,它: | 此脚本仅包含有限的“自动重命名”功能,它: | ||||||
| @@ -11,28 +12,53 @@ Warn = """\033[0;31;40m | |||||||
| \033[0m""" | \033[0m""" | ||||||
| print(Warn) | print(Warn) | ||||||
| raise Exception("READ THE WARNING") | raise Exception("READ THE WARNING") | ||||||
|  | ''' | ||||||
| import yaml, os, re | import yaml | ||||||
|  | import os | ||||||
|  | import re | ||||||
|  |  | ||||||
| fconfig = open("config.yaml", "r", encoding="utf-8") | fconfig = open("config.yaml", "r", encoding="utf-8") | ||||||
| frule = open("rule.yaml", "r", encoding="utf-8") | frule = open("rule.yaml", "r", encoding="utf-8") | ||||||
| Config = yaml.load(fconfig, Loader=yaml.FullLoader) | Config = yaml.load(fconfig, Loader=yaml.FullLoader) | ||||||
| Rule = yaml.load(frule, Loader=yaml.FullLoader) | Rule = yaml.load(frule, Loader=yaml.FullLoader) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def rand_str(size): | ||||||
|  |     chars = b"0123456789abcdef" | ||||||
|  |     data = bytearray(size) | ||||||
|  |     for i in range(size): | ||||||
|  |         ri = int.from_bytes(os.urandom(4), "big") % len(chars) | ||||||
|  |         ch = chars[ri] | ||||||
|  |         data[i] = ch | ||||||
|  |     return data.decode("utf-8") | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def rand_head_line_2(): | ||||||
|  |     r1 = rand_str(32) | ||||||
|  |     r2 = rand_str(32) | ||||||
|  |     return f"G04 {r1},{r2},10*" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # random generate header line 2 | ||||||
|  | headers = Config["Header"].split("\n") | ||||||
|  | if len(headers) >= 2: | ||||||
|  |     headers[1] = rand_head_line_2() | ||||||
|  | Config["Header"] = "\n".join(headers) | ||||||
|  |  | ||||||
| WorkDir = Config["WorkDir"] | WorkDir = Config["WorkDir"] | ||||||
| DestDir = Config["DestDir"] | DestDir = Config["DestDir"] | ||||||
| WorkDirFiles = os.listdir(WorkDir) | WorkDirFiles = os.listdir(WorkDir) | ||||||
|  |  | ||||||
| if not DestDir: | if not DestDir: | ||||||
|     DestDir=os.path.join(WorkDir,'output') |     DestDir = os.path.join(WorkDir, "output") | ||||||
| if not os.path.exists(DestDir): | if not os.path.exists(DestDir): | ||||||
|     os.mkdir(DestDir) |     os.mkdir(DestDir) | ||||||
|  |  | ||||||
| #创建PCB下单必读文档 | # 创建PCB下单必读文档 | ||||||
| with open(os.path.join(DestDir, Config["TextFileName"]), "w") as textFile: | with open(os.path.join(DestDir, Config["TextFileName"]), "w") as textFile: | ||||||
|     textFile.write(Config["TextFileContent"]) |     textFile.write(Config["TextFileContent"]) | ||||||
|  |  | ||||||
| #检验文件是否齐全/重复匹配 | # 检验文件是否齐全/重复匹配 | ||||||
| for key, value in Rule.items(): | for key, value in Rule.items(): | ||||||
|     matchFile = [] |     matchFile = [] | ||||||
|     rePattern = re.compile(pattern=value) |     rePattern = re.compile(pattern=value) | ||||||
| @@ -48,7 +74,7 @@ for key, value in Rule.items(): | |||||||
|     else: |     else: | ||||||
|         print(key + " -> " + matchFile[0]) |         print(key + " -> " + matchFile[0]) | ||||||
|  |  | ||||||
| #改名和加头操作 | # 改名和加头操作 | ||||||
| for key, value in Rule.items(): | for key, value in Rule.items(): | ||||||
|     matchFile = "" |     matchFile = "" | ||||||
|     rePattern = re.compile(pattern=value) |     rePattern = re.compile(pattern=value) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user