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