tmp_c2a4a_patch2.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """C-2a-4a 补丁 2:gates.vue 首跑漏写 3 处 #5B9BD5(L195/L243/L256,全部主行动/当前态 -> 橙)
  4. + fix_lang。reward-energy 已由补丁 1 处理。
  5. """
  6. import io
  7. import re
  8. import sys
  9. ORANGE = '$brand-primary'
  10. PAGE = 'pages/profile-extra/gates.vue'
  11. SUBS = [
  12. (' border: 2rpx solid #5B9BD5;\n', ' border: 2rpx solid %s;\n' % ORANGE, 1),
  13. (' background: #5B9BD5;\n', ' background: %s;\n' % ORANGE, 1),
  14. (' color: #5B9BD5;\n', ' color: %s;\n' % ORANGE, 1),
  15. ]
  16. STYLE_RE = re.compile(r'^[ \t]*<style[^>]*>[\s\S]*?</style>', re.M)
  17. def main():
  18. src = io.open(PAGE, encoding='utf-8').read()
  19. for old, new, expect in SUBS:
  20. n = src.count(old)
  21. if n != expect:
  22. raise RuntimeError('%s: hit=%d(要求 %d):: %r' % (PAGE, n, expect, old))
  23. src = src.replace(old, new)
  24. print(' %-46s -> %s x%d' % (old.strip(), new.strip(), n))
  25. m = STYLE_RE.search(src)
  26. block = m.group(0)
  27. first, rest = block.split('\n', 1)
  28. if '<style scoped>' in first and 'lang=' not in first:
  29. first = first.replace('<style scoped>', '<style scoped lang="scss">', 1)
  30. print(' [lang] 补 lang="scss"')
  31. src = src[:m.start()] + first + '\n' + rest + src[m.end():]
  32. io.open(PAGE, 'w', encoding='utf-8', newline='').write(src)
  33. # 终检
  34. residual = re.findall(r'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|3A7CC2|4A9BD7|63B3ED|8FC5E8)(?![0-9A-Fa-f])', src, re.I)
  35. residual += re.findall(r'rgba\((?:91, ?155, ?213|74, ?155, ?215|143, ?197, ?232)', src)
  36. if residual:
  37. raise RuntimeError('%s: 终检残留 %s' % (PAGE, residual))
  38. print('C-2a-4a 补丁 2 完毕')
  39. if __name__ == '__main__':
  40. sys.exit(main())