1 Star 0 Fork 6

pilu01/leetcode

forked from mirrors_doocs/leetcode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
run_format.py 2.56 KB
一键复制 编辑 原始数据 按行查看 历史
ylb 提交于 2022-08-18 16:37 +08:00 . feat: update lc problems
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pilu01/leetcode.git
git@gitee.com:pilu01/leetcode.git
pilu01
leetcode
leetcode
main

搜索帮助