• 配置文件的自动化更新(v2.1)


      1 import openpyxl
      2 import sys
      3 
      4 wb_temp = openpyxl.load_workbook("E:Projectswork_11_25\Utility機種対応知能化\Utility機種対応仕様.xlsx")
      5 wb_info = openpyxl.load_workbook("E:Projectswork_11_25\Utility機種対応知能化\Utility機種対応Input情報.xlsx")
      6 wb_result = openpyxl.load_workbook("E:Projectswork_11_25\Utility機種対応知能化\Utility詳細設計書_テンプレート_結果記入.xlsx")
      7 
      8 
      9 ws_base = wb_temp["Color Correct Utility"]
     10 ws_code = wb_temp["LANGCode"]
     11 ws_info = wb_info["Color Correct Utility"]
     12 
     13 # 多国语情报:
     14 language_code = [ws_base['B22'].value, ws_base['B25'].value, ws_base['B28'].value, ws_base['B31'].value,
     15                  ws_base['B34'].value, ws_base['B37'].value, ws_base['B40'].value, ws_base['B43'].value,
     16                  ws_base['B46'].value, ws_base['B49'].value, ]
     17 # ['ENU', 'JPN', 'CHS', 'CHT', 'DEU', 'ESP', 'FRA', 'ITA', 'KOR', 'PTB']
     18 
     19 # 多国语编码
     20 language_encoding = {}
     21 for l in range(3, 26):
     22     language_encoding.update({ws_code['B' + str(l)].value: ws_code['C' + str(l)].value})
     23 # print(language_encoding)
     24 
     25 # OS情报:
     26 OS_info = [ws_base['B56'].value, ws_base['B57'].value]
     27 # ['x86', 'x64']
     28 
     29 path = ws_base['B4'].value
     30 # setupdirOS情報Resource多国語情報ColorUtilityOclutl.ini
     31 
     32 path_list_dic = {}
     33 path_list = []
     34 
     35 for os in OS_info:
     36     for lan in language_code:
     37         path_list_dic[lan + '_' + os] = path.replace('多国語情報', lan).replace('OS情報', os)
     38 # print(path_list_dic)
     39 # {'ENU_x86': 'setupdir\x86\Resource\ENU\ColorUtility\Oclutl.ini',
     40 # 'JPN_x86': 'setupdir\x86\Resource\JPN\ColorUtility\Oclutl.ini',
     41 # 'CHS_x86': 'setupdir\x86\Resource\CHS\ColorUtility\Oclutl.ini',
     42 # 'CHT_x86': 'setupdir\x86\Resource\CHT\ColorUtility\Oclutl.ini',
     43 # 'DEU_x86': 'setupdir\x86\Resource\DEU\ColorUtility\Oclutl.ini',
     44 # 'ESP_x86': 'setupdir\x86\Resource\ESP\ColorUtility\Oclutl.ini',
     45 # 'FRA_x86': 'setupdir\x86\Resource\FRA\ColorUtility\Oclutl.ini',
     46 # 'ITA_x86': 'setupdir\x86\Resource\ITA\ColorUtility\Oclutl.ini',
     47 # 'KOR_x86': 'setupdir\x86\Resource\KOR\ColorUtility\Oclutl.ini',
     48 # 'PTB_x86': 'setupdir\x86\Resource\PTB\ColorUtility\Oclutl.ini',
     49 # 'ENU_x64': 'setupdir\x64\Resource\ENU\ColorUtility\Oclutl.ini',
     50 # 'JPN_x64': 'setupdir\x64\Resource\JPN\ColorUtility\Oclutl.ini',
     51 # 'CHS_x64': 'setupdir\x64\Resource\CHS\ColorUtility\Oclutl.ini',
     52 # 'CHT_x64': 'setupdir\x64\Resource\CHT\ColorUtility\Oclutl.ini',
     53 # 'DEU_x64': 'setupdir\x64\Resource\DEU\ColorUtility\Oclutl.ini',
     54 # 'ESP_x64': 'setupdir\x64\Resource\ESP\ColorUtility\Oclutl.ini',
     55 # 'FRA_x64': 'setupdir\x64\Resource\FRA\ColorUtility\Oclutl.ini',
     56 # 'ITA_x64': 'setupdir\x64\Resource\ITA\ColorUtility\Oclutl.ini',
     57 # 'KOR_x64': 'setupdir\x64\Resource\KOR\ColorUtility\Oclutl.ini',
     58 # 'PTB_x64': 'setupdir\x64\Resource\PTB\ColorUtility\Oclutl.ini'}
     59 # if p[3:] == "_x64":
     60 dic_x86 = {}
     61 dic_x64 = {}
     62 for k in language_code:
     63     dic_x86[k + '_x86'] = path_list_dic[k + '_x86']
     64     dic_x64[k + '_x64'] = path_list_dic[k + '_x64']
     65 # {'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'}
     66 # {'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'}
     67 
     68 
     69 def add_x86():
     70     m = 0
     71     for p in dic_x86:
     72         with open(dic_x86[p], 'r', encoding=language_encoding[p[:-4]]) as f1:
     73             new_section_name = '[CCMVer' + str(ws_info['C3'].value) + ']'  # 获取H列单元格内容"section"
     74             # [CCMVer42.3]
     75 
     76             lst = f1.readlines()  # 读取每行信息
     77             if new_section_name+'
    ' in lst:
     78                 print("该section已添加过,无需添加。")
     79                 sys.exit(0)
     80             # #
     81             n = lst.index('[StringSet1]
    ')  # 获取"[StringSet1]"的索引
     82             lst.insert(n, new_section_name + '
    ')  # 将新section按照索引值插入列表中
     83             if ws_info['C8'].value == 'Default':
     84                 for i in range(5, 12):
     85                     n = n + 1
     86                     item = ws_base['D' + str(i)].value               # 获取item值
     87                     value = str(ws_info['C' + str(i-1)].value)         # 获取value值
     88                     if i == 8:
     89                         value = value + "
    "
     90                     if i == 9:
     91                         value = str(ws_base['D' + str(22 + m)].value)
     92                     if i == 10:
     93                         value = str(ws_base['D' + str(23 + m)].value)
     94                     if i == 11:
     95                         value = str(ws_base['D' + str(24 + m)].value) + "
    "
     96                         m += 3
     97 
     98                     lst.insert(n, item + " = " + value + '
    ')  # 将item值与value值按照索引插入列表中
     99 
    100             elif ws_info['C8'].value == 'A6':
    101                 for i in range(5, 12):
    102                     n = n + 1
    103                     item = ws_base['D' + str(i)].value  # 获取item值
    104                     value = str(ws_info['C' + str(i - 1)].value)  # 获取value值
    105                     if i == 8:
    106                         value = value + "
    "
    107                     if i == 9:
    108                         value = str(ws_base['E' + str(22 + m)].value)
    109                     if i == 10:
    110                         value = str(ws_base['E' + str(23 + m)].value)
    111                     if i == 11:
    112                         value = str(ws_base['E' + str(24 + m)].value) + "
    "
    113 
    114                         m += 3
    115                     lst.insert(n, item + " = " + value + '
    ')         # 将item值与value值按照索引插入列表中
    116             print(lst)
    117         with open(dic_x86[p], 'w', encoding=language_encoding[p[:-4]]) as f2:
    118             f2.writelines(lst)
    119 
    120 
    121 def add_x64():
    122     m = 0
    123     for p in dic_x64:
    124         with open(dic_x64[p], 'r', encoding=language_encoding[p[:-4]]) as f1:
    125             new_section_name = '[CCMVer' + str(ws_info['C3'].value) + ']'  # 获取H列单元格内容"section"
    126             # [CCMVer42.3]
    127 
    128             lst = f1.readlines()  # 读取每行信息
    129             if new_section_name+'
    ' in lst:
    130                 print("该section已添加过,无需添加。")
    131                 sys.exit(0)
    132             # #
    133             n = lst.index('[StringSet1]
    ')  # 获取"[StringSet1]"的索引
    134             lst.insert(n, new_section_name + '
    ')  # 将新section按照索引值插入列表中
    135             if ws_info['C8'].value == 'Default':
    136                 for i in range(5, 12):
    137                     n = n + 1
    138                     item = ws_base['D' + str(i)].value  # 获取item值
    139                     value = str(ws_info['C' + str(i - 1)].value)  # 获取value值
    140                     if i == 8:
    141                         value = value + "
    "
    142                     if i == 9:
    143                         value = str(ws_base['D' + str(22 + m)].value)
    144                     if i == 10:
    145                         value = str(ws_base['D' + str(23 + m)].value)
    146                     if i == 11:
    147                         value = str(ws_base['D' + str(24 + m)].value) + "
    "
    148                         m += 3
    149 
    150                     lst.insert(n, item + " = " + value + '
    ')  # 将item值与value值按照索引插入列表中
    151 
    152             elif ws_info['C8'].value == 'A6':
    153                 for i in range(5, 12):
    154                     n = n + 1
    155                     item = ws_base['D' + str(i)].value  # 获取item值
    156                     value = str(ws_info['C' + str(i - 1)].value)  # 获取value值
    157                     if i == 8:
    158                         value = value + "
    "
    159                     if i == 9:
    160                         value = str(ws_base['E' + str(22 + m)].value)
    161                     if i == 10:
    162                         value = str(ws_base['E' + str(23 + m)].value)
    163                     if i == 11:
    164                         value = str(ws_base['E' + str(24 + m)].value) + "
    "
    165                         m += 3
    166                     lst.insert(n, item + " = " + value + '
    ')  # 将item值与value值按照索引插入列表中
    167             print(lst)
    168         with open(dic_x64[p], 'w', encoding=language_encoding[p[:-4]]) as f2:
    169             f2.writelines(lst)
    170 
    171 
    172 add_x86()
    173 add_x64()
  • 相关阅读:
    tkinter中text文本与scroll滚动条控件(五)
    tkinter中entry输入控件(四)
    tkinter中button按钮控件(三)
    tkinter中lable标签控件(二)
    tkinter简介(一)
    Pycharm激活方法使用的是(license server)
    教你如何解决WIN 10系统睡眠无法唤醒
    命令查询windows&Linux系统版本信息
    文本溢出显示省略号,CSS未加载时a标签仍可用处理方法
    Vue.js 中的动态路由
  • 原文地址:https://www.cnblogs.com/wangzhilong/p/11928992.html
Copyright © 2020-2023  润新知