tmp_c2a4a_rest.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """C-2a-4a 续跑:gates 补修(#3A7CC2 漏网)+ 剩余 10 文件
  4. 前 8 文件(teacher 7 + gates 主体)已在首跑完成,本脚本不重复。
  5. gate-lock 新增:锁面板 on-dark accent 文字随品牌族迁移(#8FC5E8 → $brand-primary-light,
  6. rgba(143,197,232,0.7) → rgba(251,146,60,0.7));reward-energy material 蓝徽章非旧蓝族保留。
  7. """
  8. import io
  9. import re
  10. import sys
  11. ORANGE = '$brand-primary'
  12. ORANGE_DARK = '$brand-primary-dark'
  13. ORANGE_LIGHT = '$brand-primary-light'
  14. INFO = '$uni-info'
  15. PALE = '$uni-primary-pale'
  16. GRAD_DARK = 'linear-gradient(135deg, #5B9BD5, #3A7CC4)'
  17. GRAD_DARK2 = 'linear-gradient(135deg, #5B9BD5, #3A7CC2)'
  18. GRAD_LIGHT = 'linear-gradient(135deg, #5B9BD5, #8FC5E8)'
  19. # ---- 前置补修:gates.vue reward-energy 徽章(首跑漏网 #3A7CC2 + rgba(66,165,245,0.15))----
  20. PRE_FIX = [
  21. ('pages/profile-extra/gates.vue', [
  22. ('color: #3A7CC2; background: rgba(66,165,245,0.15);',
  23. 'color: %s; background: rgba(14,165,233,0.15);' % INFO, 1),
  24. ]),
  25. ]
  26. PAGES = {
  27. 'pages/profile/report-detail.vue': {
  28. 'blocks': [],
  29. 'global': [('#5B9BD5', ORANGE)],
  30. 'script': [],
  31. },
  32. 'pages/profile/components/ProfileMenu.vue': {
  33. 'blocks': [],
  34. 'global': [('#5B9BD5', INFO)],
  35. 'script': [('color="#5B9BD5"', 'color="#F97316"', 1)],
  36. },
  37. 'pages/profile-extra/coupons.vue': {
  38. 'blocks': [],
  39. 'global': [
  40. ('color: #5B9BD5', 'color: ' + INFO),
  41. ('background: #5B9BD5', 'background: ' + ORANGE),
  42. ],
  43. 'script': [],
  44. },
  45. 'pages/profile/report-management.vue': {
  46. 'blocks': [],
  47. 'global': [('#5B9BD5', ORANGE)],
  48. 'script': [],
  49. },
  50. 'pages/profile/index.vue': {
  51. 'blocks': [],
  52. 'global': [(GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK))],
  53. 'script': [],
  54. },
  55. 'pages/home-pages/member-home-detail.vue': {
  56. 'blocks': [],
  57. 'global': [
  58. (GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)),
  59. ('#5B9BD5', ORANGE),
  60. ],
  61. 'script': [],
  62. },
  63. 'pages/article-center/article-edit.vue': {
  64. 'blocks': [],
  65. 'global': [
  66. ('#E8F4FD', PALE),
  67. ('#5B9BD5', ORANGE),
  68. ],
  69. 'script': [],
  70. },
  71. 'components/gate-lock.vue': {
  72. 'blocks': [],
  73. 'global': [
  74. (GRAD_DARK2, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)),
  75. ('color: #8FC5E8;', 'color: %s;' % ORANGE_LIGHT),
  76. ('color: rgba(143,197,232,0.7);', 'color: rgba(251,146,60,0.7);'),
  77. ],
  78. 'script': [],
  79. },
  80. 'components/FamilyRelationGraph.vue': {
  81. 'blocks': [],
  82. 'global': [],
  83. 'script': [("home: '#5B9BD5',", "home: '#F97316',", 1)],
  84. },
  85. 'components/DimensionArticles.vue': {
  86. 'blocks': [],
  87. 'global': [],
  88. 'script': [(GRAD_LIGHT, "'linear-gradient(135deg, %s, %s)'" % (ORANGE, ORANGE_LIGHT), 1)],
  89. },
  90. }
  91. RESIDUAL_RE = re.compile(r'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|3A7CC2|4A9BD7|63B3ED|8FC5E8)(?![0-9A-Fa-f])', re.I)
  92. RESIDUAL_RGBA = re.compile(r'rgba\((?:91, ?155, ?213|74, ?155, ?215|143, ?197, ?232)')
  93. STYLE_RE = re.compile(r'^[ \t]*<style[^>]*>[\s\S]*?</style>', re.M)
  94. def apply_global(block, pairs, page):
  95. for old, new in pairs:
  96. n = block.count(old)
  97. if n == 0:
  98. raise RuntimeError('%s: 全局替换 hit=0 :: %s' % (page, old))
  99. block = block.replace(old, new)
  100. print(' %-52s -> %-30s x%d' % (old, new, n))
  101. return block
  102. def fix_lang(block, page):
  103. first, rest = block.split('\n', 1)
  104. if 'lang="scss"' not in first:
  105. if '<style scoped>' in first:
  106. first = first.replace('<style scoped>', '<style scoped lang="scss">', 1)
  107. elif '<style>' in first:
  108. first = first.replace('<style>', '<style lang="scss">', 1)
  109. else:
  110. raise RuntimeError('%s: 无法识别的 style 标签: %s' % (page, first.strip()))
  111. print(' [lang] 补 lang="scss"')
  112. return first + '\n' + rest
  113. def main():
  114. # 前置补修(整文件 targeted)
  115. for page, subs in PRE_FIX:
  116. src = io.open(page, encoding='utf-8').read()
  117. print('== [补修] %s ==' % page)
  118. for old, new, expect in subs:
  119. n = src.count(old)
  120. if n != expect:
  121. raise RuntimeError('%s: 补修 hit=%d(要求 %d):: %s' % (page, n, expect, old))
  122. src = src.replace(old, new)
  123. print(' %-52s -> %s x%d' % (old, new, n))
  124. io.open(page, 'w', encoding='utf-8', newline='').write(src)
  125. for page, cfg in PAGES.items():
  126. src = io.open(page, encoding='utf-8').read()
  127. m = STYLE_RE.search(src)
  128. if not m:
  129. raise RuntimeError('%s: 未找到 style 块' % page)
  130. block = m.group(0)
  131. print('== %s ==' % page)
  132. if cfg['global']:
  133. block = apply_global(block, cfg['global'], page)
  134. block = fix_lang(block, page)
  135. src = src[:m.start()] + block + src[m.end():]
  136. for old, new, expect in cfg['script']:
  137. n = src.count(old)
  138. if n != expect:
  139. raise RuntimeError('%s: 脚本区 %s hit=%d(要求 %d)' % (page, old, n, expect))
  140. src = src.replace(old, new)
  141. print(' [script] %-44s -> %s x%d' % (old, new, n))
  142. io.open(page, 'w', encoding='utf-8', newline='').write(src)
  143. residual = RESIDUAL_RE.findall(src) + RESIDUAL_RGBA.findall(src)
  144. if residual:
  145. raise RuntimeError('%s: 终检残留 %s' % (page, residual))
  146. print('C-2a-4a 续跑完毕')
  147. if __name__ == '__main__':
  148. sys.exit(main())