提交 e19310cf 编写于 作者: ccat's avatar ccat

Merge branch 'dev/refactor' into 'master'

dev(hansbug): refactor the code && fix the bug on encoding

See merge request !1
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
.DS_Store .DS_Store
__pycache__ __pycache__
*.pyc *.pyc
*.zip *.zip
\ No newline at end of file .python-version
\ No newline at end of file
...@@ -4,7 +4,7 @@ import os ...@@ -4,7 +4,7 @@ import os
import re import re
import sys import sys
import uuid import uuid
import re
import git import git
id_set = set() id_set = set()
...@@ -16,12 +16,21 @@ handler.setFormatter(formatter) ...@@ -16,12 +16,21 @@ handler.setFormatter(formatter)
logger.addHandler(handler) logger.addHandler(handler)
repo = git.Repo(".") repo = git.Repo(".")
def user_name(): def user_name():
return repo.config_reader().get_value("user", "name") return repo.config_reader().get_value("user", "name")
_DEFAULT_ENCODING = 'utf-8'
def read_text(filepath):
with open(filepath, 'r', encoding='utf-8') as f:
return f.read()
def load_json(p): def load_json(p):
with open(p, 'r') as f: return json.loads(read_text(p))
return json.loads(f.read())
def dump_json(p, j, exist_ok=False, override=False): def dump_json(p, j, exist_ok=False, override=False):
...@@ -177,7 +186,7 @@ class TreeWalker: ...@@ -177,7 +186,7 @@ class TreeWalker:
posted = os.path.join(base, f"{index + 1}.{title}") posted = os.path.join(base, f"{index + 1}.{title}")
if origin != posted: if origin != posted:
self.logger.info(f"rename [{origin}] to [{posted}]") self.logger.info(f"rename [{origin}] to [{posted}]")
os.rename(origin, posted) os.rename(origin, posted)
return children return children
def ensure_chapters(self): def ensure_chapters(self):
...@@ -338,8 +347,7 @@ class TreeWalker: ...@@ -338,8 +347,7 @@ class TreeWalker:
_, mfile = os.path.split(meta_path) _, mfile = os.path.split(meta_path)
meta = None meta = None
if os.path.exists(meta_path): if os.path.exists(meta_path):
with open(meta_path) as f: content = read_text(meta_path)
content = f.read()
if content: if content:
meta = json.loads(content) meta = json.loads(content)
if "exercise_id" not in meta: if "exercise_id" not in meta:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册