提交 8824df76 编写于 作者: M Mars Liu

fixed odd orders

上级 6da9d1eb
...@@ -4,6 +4,8 @@ import os ...@@ -4,6 +4,8 @@ import os
import re import re
import sys import sys
import uuid import uuid
import re
import git
id_set = set() id_set = set()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -12,7 +14,10 @@ handler = logging.StreamHandler(sys.stdout) ...@@ -12,7 +14,10 @@ handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter) handler.setFormatter(formatter)
logger.addHandler(handler) logger.addHandler(handler)
repo = git.Repo(".")
def user_name():
return repo.config_reader().get_value("user", "name")
def load_json(p): def load_json(p):
with open(p, 'r') as f: with open(p, 'r') as f:
...@@ -301,6 +306,14 @@ class TreeWalker: ...@@ -301,6 +306,14 @@ class TreeWalker:
def ensure_exercises(self, section_path): def ensure_exercises(self, section_path):
config = self.ensure_section_config(section_path) config = self.ensure_section_config(section_path)
for e in os.listdir(section_path):
base, ext = os.path.splitext(e)
_, source = os.path.split(e)
if ext != ".md":
continue
meta_path = os.path.join(section_path, base + ".json")
self.ensure_exercises_meta(meta_path, source)
for e in config.get("export", []): for e in config.get("export", []):
full_name = os.path.join(section_path, e) full_name = os.path.join(section_path, e)
exercise = load_json(full_name) exercise = load_json(full_name)
...@@ -311,6 +324,36 @@ class TreeWalker: ...@@ -311,6 +324,36 @@ class TreeWalker:
else: else:
id_set.add(exercise["exercise_id"]) id_set.add(exercise["exercise_id"])
def ensure_exercises_meta(self, meta_path, source):
_, mfile = os.path.split(meta_path)
if os.path.exists(meta_path):
meta = load_json(meta_path)
if "exercise_id" not in meta:
meta["exercise_id"] = uuid.uuid4().hex
if "notebook_enable" not in meta:
meta["notebook_enable"] = self.default_notebook()
if "source" not in meta:
meta["source"] = source
if "author" not in meta:
meta["author"] = user_name()
if "type" not in meta:
meta["type"] = "code_options"
else:
meta = {
"type": "code_options",
"author": user_name(),
"source": source,
"notebook_enable": self.default_notebook(),
"exercise_id": uuid.uuid4().hex
}
dump_json(meta_path, meta, True, True)
def default_notebook(self):
if self.name in ["python", "java", "c", "algorithm"]:
return True
else:
return False
def check_section_keywords(self, full_path): def check_section_keywords(self, full_path):
config = self.ensure_section_config(full_path) config = self.ensure_section_config(full_path)
if not config.get("keywords", []): if not config.get("keywords", []):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册