配置文件的自动化更新(v3.1)
1 import openpyxl 2 import sys 3 import re 4 5 wb_temp = openpyxl.load_workbook("E:\Projects\work_11_25\\Utility機種対応知能化\\Utility機種対応仕様.xlsx") 6 wb_info = openpyxl.load_workbook("E:\Projects\work_11_25\\Utility機種対応知能化\\Utility機種対応Input情報.xlsx") 7 wb_result = openpyxl.load_workbook("E:\Projects\work_11_25\\Utility機種対応知能化\\Utility詳細設計書_テンプレート_結果記入.xlsx") 8 9 10 ws_base = wb_temp["Color Correct Utility"] 11 ws_code = wb_temp["LANGCode"] 12 ws_info = wb_info["Color Correct Utility"] 13 14 # 多国语情报: 15 language_code = [ws_base['B22'].value, ws_base['B25'].value, ws_base['B28'].value, ws_base['B31'].value, 16 ws_base['B34'].value, ws_base['B37'].value, ws_base['B40'].value, ws_base['B43'].value, 17 ws_base['B46'].value, ws_base['B49'].value, ] 18 19 # ['ENU', 'JPN', 'CHS', 'CHT', 'DEU', 'ESP', 'FRA', 'ITA', 'KOR', 'PTB'] 20 21 # 多国语编码 22 language_encoding = {} 23 for l in range(3, 26): 24 language_encoding.update({ws_code['B' + str(l)].value: ws_code['C' + str(l)].value}) 25 # print(language_encoding) 26 27 # OS情报: 28 OS_info = [ws_base['B56'].value, ws_base['B57'].value] 29 # ['x86', 'x64'] 30 31 path = ws_base['C4'].value 32 path_readme = ws_base['C12'].value 33 # setupdir\OS情報\Resource\多国語情報\ColorUtility\Oclutl.ini 34 35 path_list_dic = {} 36 path_list = [] 37 path_list_readme = {} 38 readme_map = {'ENU': 'readme', 'JPN': 'readme', 'CHS': 'readme', 'CHT': 'readme', 'DEU': 'Liesmich', 'ESP': 'leame', 39 'FRA': 'LisezMoi', 'ITA': 'Leggimi', 'KOR': 'readme', 'PTB': 'readme', } 40 41 for lan in language_code: 42 for os in OS_info: 43 path_list_dic[lan + '_' + os] = path.replace('多国語情報', lan).replace('OS情報', os) 44 path_list_readme[lan] = path_readme.replace('多国語情報', lan).replace('ReadmeFile', readme_map[lan]) 45 # print(path_list_readme) 46 # {'ENU': 'setupdir\\license\\ENU\\readme.txt', 47 # 'JPN': 'setupdir\\license\\JPN\\readme.txt', 48 # 'CHS': 'setupdir\\license\\CHS\\readme.txt', 49 # 'CHT': 'setupdir\\license\\CHT\\readme.txt', 50 # 'DEU': 'setupdir\\license\\DEU\\Liesmich.txt', 51 # 'ESP': 'setupdir\\license\\ESP\\license.txt', 52 # 'FRA': 'setupdir\\license\\FRA\\LisezMoi.txt', 53 # 'ITA': 'setupdir\\license\\ITA\\license.txt', 54 # 'KOR': 'setupdir\\license\\KOR\\readme.txt', 55 # 'PTB': 'setupdir\\license\\PTB\\readme.txt'} 56 57 # print(path_list_dic) 58 # {'ENU_x86': 'setupdir\\x86\\Resource\\ENU\\ColorUtility\\Oclutl.ini', 59 # 'JPN_x86': 'setupdir\\x86\\Resource\\JPN\\ColorUtility\\Oclutl.ini', 60 # 'CHS_x86': 'setupdir\\x86\\Resource\\CHS\\ColorUtility\\Oclutl.ini', 61 # 'CHT_x86': 'setupdir\\x86\\Resource\\CHT\\ColorUtility\\Oclutl.ini', 62 # 'DEU_x86': 'setupdir\\x86\\Resource\\DEU\\ColorUtility\\Oclutl.ini', 63 # 'ESP_x86': 'setupdir\\x86\\Resource\\ESP\\ColorUtility\\Oclutl.ini', 64 # 'FRA_x86': 'setupdir\\x86\\Resource\\FRA\\ColorUtility\\Oclutl.ini', 65 # 'ITA_x86': 'setupdir\\x86\\Resource\\ITA\\ColorUtility\\Oclutl.ini', 66 # 'KOR_x86': 'setupdir\\x86\\Resource\\KOR\\ColorUtility\\Oclutl.ini', 67 # 'PTB_x86': 'setupdir\\x86\\Resource\\PTB\\ColorUtility\\Oclutl.ini', 68 # 'ENU_x64': 'setupdir\\x64\\Resource\\ENU\\ColorUtility\\Oclutl.ini', 69 # 'JPN_x64': 'setupdir\\x64\\Resource\\JPN\\ColorUtility\\Oclutl.ini', 70 # 'CHS_x64': 'setupdir\\x64\\Resource\\CHS\\ColorUtility\\Oclutl.ini', 71 # 'CHT_x64': 'setupdir\\x64\\Resource\\CHT\\ColorUtility\\Oclutl.ini', 72 # 'DEU_x64': 'setupdir\\x64\\Resource\\DEU\\ColorUtility\\Oclutl.ini', 73 # 'ESP_x64': 'setupdir\\x64\\Resource\\ESP\\ColorUtility\\Oclutl.ini', 74 # 'FRA_x64': 'setupdir\\x64\\Resource\\FRA\\ColorUtility\\Oclutl.ini', 75 # 'ITA_x64': 'setupdir\\x64\\Resource\\ITA\\ColorUtility\\Oclutl.ini', 76 # 'KOR_x64': 'setupdir\\x64\\Resource\\KOR\\ColorUtility\\Oclutl.ini', 77 # 'PTB_x64': 'setupdir\\x64\\Resource\\PTB\\ColorUtility\\Oclutl.ini'} 78 # if p[3:] == "_x64": 79 dic_x86 = {} 80 dic_x64 = {} 81 for k in language_code: 82 dic_x86[k + '_x86'] = path_list_dic[k + '_x86'] 83 dic_x64[k + '_x64'] = path_list_dic[k + '_x64'] 84 # print(dic_x64) 85 # print(dic_x86) 86 # {'ENU_x86': 'setupdir\\x86\\Resource\\ENU\\ColorUtility\\Oclutl.ini', 'JPN_x86': 'setupdir\\x86\\Resource\\JPN\\ColorUtility\\Oclutl.ini', 'CHS_x86': 'setupdir\\x86\\Resource\\CHS\\ColorUtility\\Oclutl.ini', 'CHT_x86': 'setupdir\\x86\\Resource\\CHT\\ColorUtility\\Oclutl.ini', 'DEU_x86': 'setupdir\\x86\\Resource\\DEU\\ColorUtility\\Oclutl.ini', 'ESP_x86': 'setupdir\\x86\\Resource\\ESP\\ColorUtility\\Oclutl.ini', 'FRA_x86': 'setupdir\\x86\\Resource\\FRA\\ColorUtility\\Oclutl.ini', 'ITA_x86': 'setupdir\\x86\\Resource\\ITA\\ColorUtility\\Oclutl.ini', 'KOR_x86': 'setupdir\\x86\\Resource\\KOR\\ColorUtility\\Oclutl.ini', 'PTB_x86': 'setupdir\\x86\\Resource\\PTB\\ColorUtility\\Oclutl.ini'} 87 # {'ENU_x64': 'setupdir\\x64\\Resource\\ENU\\ColorUtility\\Oclutl.ini', 'JPN_x64': 'setupdir\\x64\\Resource\\JPN\\ColorUtility\\Oclutl.ini', 'CHS_x64': 'setupdir\\x64\\Resource\\CHS\\ColorUtility\\Oclutl.ini', 'CHT_x64': 'setupdir\\x64\\Resource\\CHT\\ColorUtility\\Oclutl.ini', 'DEU_x64': 'setupdir\\x64\\Resource\\DEU\\ColorUtility\\Oclutl.ini', 'ESP_x64': 'setupdir\\x64\\Resource\\ESP\\ColorUtility\\Oclutl.ini', 'FRA_x64': 'setupdir\\x64\\Resource\\FRA\\ColorUtility\\Oclutl.ini', 'ITA_x64': 'setupdir\\x64\\Resource\\ITA\\ColorUtility\\Oclutl.ini', 'KOR_x64': 'setupdir\\x64\\Resource\\KOR\\ColorUtility\\Oclutl.ini', 'PTB_x64': 'setupdir\\x64\\Resource\\PTB\\ColorUtility\\Oclutl.ini'} 88 89 90 def add_x86(): 91 m = 0 92 for p in dic_x86: 93 with open(dic_x86[p], 'r', encoding=language_encoding[p[:-4]]) as f1: 94 new_section_name = '[CCMVer' + str(ws_info['C3'].value) + ']' # 获取H列单元格内容"section" 95 # [CCMVer42.3] 96 97 lst = f1.readlines() # 读取每行信息 98 if new_section_name+'\n' in lst: 99 print("该section在x86文件中已添加过,无需添加。") 100 # sys.exit(0) 101 break 102 # # 103 n = lst.index('[StringSet1]\n') # 获取"[StringSet1]"的索引 104 lst.insert(n, new_section_name + '\n') # 将新section按照索引值插入列表中 105 if ws_info['C8'].value == 'Default': 106 for i in range(5, 12): 107 n = n + 1 108 item = ws_base['E' + str(i)].value # 获取item值 109 value = str(ws_info['C' + str(i-1)].value) # 获取value值 110 if i == 8: 111 value = value + "\n" 112 if i == 9: 113 value = str(ws_base['D' + str(22 + m)].value) 114 if i == 10: 115 value = str(ws_base['D' + str(23 + m)].value) 116 if i == 11: 117 value = str(ws_base['D' + str(24 + m)].value) + "\n" 118 m += 3 119 120 lst.insert(n, item + "=" + value + '\n') # 将item值与value值按照索引插入列表中 121 122 elif ws_info['C8'].value == 'A6': 123 for i in range(5, 12): 124 n = n + 1 125 item = ws_base['E' + str(i)].value # 获取item值 126 value = str(ws_info['C' + str(i - 1)].value) # 获取value值 127 if i == 8: 128 value = value + "\n" 129 if i == 9: 130 value = str(ws_base['E' + str(22 + m)].value) 131 if i == 10: 132 value = str(ws_base['E' + str(23 + m)].value) 133 if i == 11: 134 value = str(ws_base['E' + str(24 + m)].value) + "\n" 135 136 m += 3 137 lst.insert(n, item + "=" + value + '\n') # 将item值与value值按照索引插入列表中 138 print(lst) 139 with open(dic_x86[p], 'w', encoding=language_encoding[p[:-4]]) as f2: 140 f2.writelines(lst) 141 142 143 def add_x64(): 144 m = 0 145 for p in dic_x64: 146 with open(dic_x64[p], 'r', encoding=language_encoding[p[:-4]]) as f1: 147 new_section_name = '[CCMVer' + str(ws_info['C3'].value) + ']' # 获取H列单元格内容"section" 148 # [CCMVer42.3] 149 150 lst = f1.readlines() # 读取每行信息 151 if new_section_name+'\n' in lst: 152 print("该section在x64文件中已添加过,无需添加。") 153 # sys.exit(0) 154 break 155 # # 156 n = lst.index('[StringSet1]\n') # 获取"[StringSet1]"的索引 157 lst.insert(n, new_section_name + '\n') # 将新section按照索引值插入列表中 158 if ws_info['C8'].value == 'Default': 159 for i in range(5, 12): 160 n = n + 1 161 item = ws_base['E' + str(i)].value # 获取item值 162 value = str(ws_info['C' + str(i - 1)].value) # 获取value值 163 if i == 8: 164 value = value + "\n" 165 if i == 9: 166 value = str(ws_base['D' + str(22 + m)].value) 167 if i == 10: 168 value = str(ws_base['D' + str(23 + m)].value) 169 if i == 11: 170 value = str(ws_base['D' + str(24 + m)].value) + "\n" 171 m += 3 172 173 lst.insert(n, item + "=" + value + '\n') # 将item值与value值按照索引插入列表中 174 175 elif ws_info['C8'].value == 'A6': 176 for i in range(5, 12): 177 n = n + 1 178 item = ws_base['E' + str(i)].value # 获取item值 179 value = str(ws_info['C' + str(i - 1)].value) # 获取value值 180 if i == 8: 181 value = value + "\n" 182 if i == 9: 183 value = str(ws_base['E' + str(22 + m)].value) 184 if i == 10: 185 value = str(ws_base['E' + str(23 + m)].value) 186 if i == 11: 187 value = str(ws_base['E' + str(24 + m)].value) + "\n" 188 m += 3 189 lst.insert(n, item + "=" + value + '\n') # 将item值与value值按照索引插入列表中 190 # print(lst) 191 with open(dic_x64[p], 'w', encoding=language_encoding[p[:-4]]) as f2: 192 f2.writelines(lst) 193 194 195 change_type_value = ws_base['B4'].value 196 if change_type_value == 'CCMVerion追加': 197 add_x86() 198 add_x64() 199 200 201 def readme(): 202 for r in path_list_readme: 203 with open(path_list_readme[r], 'r+', encoding=language_encoding[r]) as f3: 204 line = f3.readlines() 205 index_list = [] 206 # [' Windows 10 operating system\n', ' Windows 8.1 operating system\n', ' Windows 8 operating system\n', 207 # ' Windows 7 operating system\n', ' Windows Server 2019 operating system\n', 208 # ' Windows Server 2016 operating system\n', ' Windows Server 2012 R2 operating system\n', 209 # ' Windows Server 2012 operating system\n', ' Windows Server 2008 R2 operating system\n', 210 # ' Windows Server 2008 operating system\n'] 211 for i in line: 212 if 'Version' in i: 213 ver = line.index(i) 214 line[ver] = " Version " + ws_info['C9'].value + '\n' 215 if 'Copyright' in i: 216 cr = line.index(i) 217 line[cr] = " " + ws_info['C12'].value + '\n' 218 if 'Windows' in i and 'operating system' in i: 219 index_list.append(line.index(i)) 220 line = [line[c] for c in range(len(line)) if (c not in index_list)] 221 line.insert(index_list[0], ws_info['C11'].value+'\n') 222 # print(r, '完成') 223 # for a in line: 224 # print(a) 225 226 with open(path_list_readme[r], 'w', encoding=language_encoding[r]) as f4: 227 f4.writelines(line) 228 print('all done') 229 230 231 readme() 232 233 234 def version_modify(): 235 with open('version.txt', 'r', encoding='utf-8') as f5: 236 line = f5.readlines() 237 line[2] = 'MainVersion=' + ws_info['C9'].value + '\n' 238 line[3] = 'SubVersion=' + str(ws_info['C10'].value) + '\n' 239 line[4] = 'Copyright=' + ws_info['C12'].value 240 241 with open('version.txt', 'w', encoding='utf-8') as f6: 242 f6.writelines(line) 243 244 245 version_modify()