tmp_c2a4a_patch.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """C-2a-4a 补丁:
  4. 1. gate-lock.vue L126 .reward-text on-dark 文字 rgba(143,197,232,0.5) -> rgba(251,146,60,0.5)
  5. 2. 执行首跑中断后未完成的两个文件(FamilyRelationGraph / DimensionArticles)
  6. """
  7. import io
  8. import sys
  9. ORANGE = '$brand-primary'
  10. ORANGE_LIGHT = '$brand-primary-light'
  11. RESIDUAL_RE = __import__('re').compile(
  12. r'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|3A7CC2|4A9BD7|63B3ED|8FC5E8)(?![0-9A-Fa-f])', __import__('re').I)
  13. RESIDUAL_RGBA = __import__('re').compile(r'rgba\((?:91, ?155, ?213|74, ?155, ?215|143, ?197, ?232)')
  14. # (page, [(old, new, expect)], [(old, new, expect) script], need_lang)
  15. JOBS = [
  16. ('components/gate-lock.vue',
  17. [('color: rgba(143,197,232,0.5);', 'color: rgba(251,146,60,0.5);', 1)],
  18. [], False),
  19. ('components/FamilyRelationGraph.vue',
  20. [],
  21. [("home: '#5B9BD5',", "home: '#F97316',", 1)],
  22. False),
  23. ('components/DimensionArticles.vue',
  24. [],
  25. [("linear-gradient(135deg, #5B9BD5, #8FC5E8)",
  26. "'linear-gradient(135deg, %s, %s)'" % (ORANGE, ORANGE_LIGHT), 1)],
  27. False),
  28. ]
  29. def main():
  30. for page, globals_, script, _lang in JOBS:
  31. src = io.open(page, encoding='utf-8').read()
  32. print('== %s ==' % page)
  33. for old, new, expect in globals_:
  34. n = src.count(old)
  35. if n != expect:
  36. raise RuntimeError('%s: hit=%d(要求 %d):: %s' % (page, n, expect, old))
  37. src = src.replace(old, new)
  38. print(' %-52s -> %s x%d' % (old, new, n))
  39. for old, new, expect in script:
  40. n = src.count(old)
  41. if n != expect:
  42. raise RuntimeError('%s: 脚本区 %s hit=%d(要求 %d)' % (page, old, n, expect))
  43. src = src.replace(old, new)
  44. print(' [script] %-44s -> %s x%d' % (old, new, n))
  45. io.open(page, 'w', encoding='utf-8', newline='').write(src)
  46. residual = RESIDUAL_RE.findall(src) + RESIDUAL_RGBA.findall(src)
  47. if residual:
  48. raise RuntimeError('%s: 终检残留 %s' % (page, residual))
  49. print('C-2a-4a 补丁完毕')
  50. if __name__ == '__main__':
  51. sys.exit(main())