From 2b3af1cca3f4c0993a9c5419813ff33dcb16c97c Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Wed, 29 Dec 2021 12:36:29 +0800 Subject: [PATCH] sync tree.py script --- src/tree.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/tree.py b/src/tree.py index 99a6936..0c58d32 100644 --- a/src/tree.py +++ b/src/tree.py @@ -7,7 +7,6 @@ import sys import uuid import re - id_set = set() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -17,6 +16,14 @@ handler.setFormatter(formatter) logger.addHandler(handler) +def search_author(author_dict, username): + for key in author_dict: + names = author_dict[key] + if username in names: + return key + return username + + def user_name(md_file, author_dict): ret = subprocess.Popen([ "git", "log", md_file @@ -27,11 +34,11 @@ def user_name(md_file, author_dict): if line.startswith('Author'): author_lines.append(line.split(' ')[1]) author_nick_name = author_lines[-1] - return author_dict.get(author_nick_name, "") + return search_author(author_dict, author_nick_name) def load_json(p): - with open(p, 'r') as f: + with open(p, 'r', encoding="utf-8") as f: return json.loads(f.read()) @@ -87,13 +94,13 @@ def check_export(base, cfg): class TreeWalker: def __init__( - self, root, - tree_name, - title=None, - log=None, - authors=None, - enable_notebook=None, - ignore_keywords=False + self, root, + tree_name, + title=None, + log=None, + authors=None, + enable_notebook=None, + ignore_keywords=False ): self.ignore_keywords = ignore_keywords self.authors = authors if authors else {} -- GitLab