代码拉取完成,页面将自动刷新
同步操作将从 mirrors_doocs/leetcode 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import os.path
import re
path = os.getcwd()
def format():
for suffix in ['md', 'js', 'ts']:
command = f'prettier --write "**/*.{suffix}"'
os.system(command)
def format_cpp():
for root, _, files in os.walk(path):
for name in files:
if name.endswith('.cpp') or name.endswith('.c'):
local_path = root + '/' + name
command = f'clang-format -i --style=file "{local_path}"'
print(command)
os.system(command)
for root, _, files in os.walk(path):
for name in files:
if name.endswith('.md'):
p1 = root + '/' + name
with open(p1, 'r', encoding='utf-8') as f:
content = f.read()
x = content
res = re.search('```cpp(.*?)```', content, re.S)
if not res:
continue
print(p1)
res = res.group(1)
p2 = root + "/tmp.cpp"
with open(p2, 'w', encoding='utf-8') as f:
f.write(res)
command = f'clang-format -i --style=file "{p2}"'
os.system(command)
with open(p2, 'r', encoding='utf-8') as f:
content = f.read()
content = x.replace(res, content)
with open(p1, 'w', encoding='utf-8') as f:
f.write(content)
os.remove(p2)
def format_py():
command = 'black -S .'
os.system(command)
for root, _, files in os.walk(path):
for name in files:
if name.endswith('.md'):
p1 = root + '/' + name
with open(p1, 'r', encoding='utf-8') as f:
content = f.read()
x = content
res = re.search('```python(.*?)```', content, re.S)
if not res:
continue
print(p1)
res = res.group(1)
p2 = root + "/tmp.py"
with open(p2, 'w', encoding='utf-8') as f:
f.write(res)
os.system(f'black -S "{p2}"')
with open(p2, 'r', encoding='utf-8') as f:
content = f.read()
content = x.replace(res, '\n' + content)
with open(p1, 'w', encoding='utf-8') as f:
f.write(content)
os.remove(p2)
def git_add():
command = 'git add .'
os.system(command)
if __name__ == '__main__':
format_cpp()
format()
format_py()
git_add()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。