Model.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import glob
  2. import os
  3. import shutil
  4. rootFile = 'D:/Project/P2207-platform/inspur-ui/'
  5. modelFile = rootFile + 'bin/model/'
  6. jsFile = rootFile + 'src/views/party_screen/details/designer/tools/configure/'
  7. vueFile = rootFile + 'src/views/party_screen/details/designer/widget/'
  8. mainFile = rootFile + 'src/views/party_screen/details/designer/tools/main.js'
  9. # 复制文件到对应位置
  10. def copyfile(srcfile, dstpath, ckey): # 复制函数
  11. if not os.path.isfile(srcfile):
  12. print("%s not exist!" % (srcfile))
  13. else:
  14. fpath, fname = os.path.split(srcfile) # 分离文件名和路径
  15. if not os.path.exists(dstpath):
  16. print('复制路径出现错误')
  17. os.makedirs(dstpath) # 创建路径
  18. if fname == 'widget-Mobile.js':
  19. fname = 'widget-' + ckey + '.js'
  20. fpath = jsFile
  21. elif fname == 'widgetMobile.vue':
  22. fname = 'widget' + ckey + '.vue'
  23. fpath = vueFile
  24. shutil.copy(srcfile, fpath + fname) # 复制文件
  25. print("copy %s -> %s" % (srcfile, dstpath + fname))
  26. # 修改main.js
  27. def myCopyFileStrring(replaceMessage, removeStrring):
  28. firstpath = mainFile
  29. contentValue = replaceMessage.replace(removeStrring, '')
  30. newcontentValue = contentValue.replace('-', '')
  31. newString = '// 111\nimport { ' + newcontentValue + ' } from \"./configure/' + contentValue + '\";'
  32. newString2 = '// 222\n ' + newcontentValue + ','
  33. if os.path.isfile(firstpath):
  34. f1 = open(firstpath, 'r+', encoding='utf-8')
  35. infos = f1.readlines()
  36. f1.seek(0, 0)
  37. for line in infos:
  38. line_new = line.replace('// 111', newString)
  39. f1.write(line_new)
  40. f1.close()
  41. if os.path.isfile(firstpath):
  42. f1 = open(firstpath, 'r+', encoding='utf-8')
  43. infos = f1.readlines()
  44. f1.seek(0, 0)
  45. for line in infos:
  46. line_new = line.replace('// 222', newString2)
  47. f1.write(line_new)
  48. f1.close()
  49. def tempFileStrring(replaceMessage, removeStrring):
  50. firstpath = vueFile + '/temp.vue'
  51. contentValue = replaceMessage.replace(removeStrring, '')
  52. newcontentValue = contentValue.replace('-', '')
  53. newString = '// 111\n import ' + newcontentValue + ' from \"./' + replaceMessage + '\"'
  54. newString2 = '// 222\n ' + newcontentValue + ','
  55. if os.path.isfile(firstpath):
  56. f1 = open(firstpath, 'r+', encoding='utf-8')
  57. infos = f1.readlines()
  58. f1.seek(0, 0)
  59. for line in infos:
  60. line_new = line.replace('// 111', newString)
  61. f1.write(line_new)
  62. f1.close()
  63. if os.path.isfile(firstpath):
  64. f1 = open(firstpath, 'r+', encoding='utf-8')
  65. infos = f1.readlines()
  66. f1.seek(0, 0)
  67. for line in infos:
  68. line_new = line.replace('// 222', newString2)
  69. f1.write(line_new)
  70. f1.close()
  71. def widgetFileStrring(replaceMessage, removeStrring):
  72. firstpath = vueFile + '/widget.vue'
  73. contentValue = replaceMessage.replace(removeStrring, '')
  74. newcontentValue = contentValue.replace('-', '')
  75. newString = '// 111\n import ' + newcontentValue + ' from \"./' + contentValue + '\";'
  76. newString2 = '// 222\n ' + newcontentValue + ','
  77. if os.path.isfile(firstpath):
  78. f1 = open(firstpath, 'r+', encoding='utf-8')
  79. infos = f1.readlines()
  80. f1.seek(0, 0)
  81. for line in infos:
  82. line_new = line.replace('// 111', newString)
  83. f1.write(line_new)
  84. f1.close()
  85. if os.path.isfile(firstpath):
  86. f1 = open(firstpath, 'r+', encoding='utf-8')
  87. infos = f1.readlines()
  88. f1.seek(0, 0)
  89. for line in infos:
  90. line_new = line.replace('// 222', newString2)
  91. f1.write(line_new)
  92. f1.close()
  93. def lastWay(firstFile, secondFile, keyValue):
  94. # D:\Project\report-ui-inspur\src\views\mobileDesigner\designer\tools\configure
  95. src_file_list = glob.glob(firstFile + '*')
  96. for srcfile in src_file_list:
  97. # print(srcfile)
  98. copyfile(srcfile, secondFile, keyValue) # 复制文件
  99. def replaceMessage(filePath, originValue , replaceValue):
  100. rep = ''
  101. with open(filePath, 'r', encoding='utf-8') as fp:
  102. contents = fp.read()
  103. rep = contents.replace(originValue, replaceValue)
  104. with open(filePath, 'w', encoding='utf-8') as fp2:
  105. fp2.write(rep)
  106. print('正式结束。。。')
  107. if __name__ == '__main__':
  108. # file:///D:/Project/P2207-platform/inspur-ui/src/views/party_screen/details/designer/widget/widgetMobileGrid.vue
  109. endString = 'MobileTabList'
  110. firstFileName = 'widget-' + endString + '.js'
  111. secondFileName = 'widget' + endString + '.vue'
  112. # 第一步复制文件到相关地址
  113. # 替换main.js中文件地址
  114. # 替换temp文件和widge文件中地址
  115. lastWay(modelFile, modelFile, endString)
  116. # lastWay()
  117. myCopyFileStrring(firstFileName, '.js')
  118. tempFileStrring(secondFileName, '.vue')
  119. widgetFileStrring(secondFileName, '.vue')
  120. replaceMessage(jsFile + firstFileName, 'widget', secondFileName.replace('.vue', ''))
  121. replaceMessage(jsFile + firstFileName, 'widget-', firstFileName.replace('.js', ''))
  122. replaceMessage(vueFile + secondFileName, 'widget', firstFileName.replace('.js', ''))