diff --git a/pygitlog/gitoperation.py b/pygitlog/gitoperation.py index 883fce2..cb9958c 100644 --- a/pygitlog/gitoperation.py +++ b/pygitlog/gitoperation.py @@ -16,7 +16,7 @@ def get_commits_commit_count(commit1,commit2): #获取两个commit之间的hash列表 def get_commit_hash(commit1,commit2): - cmd = "git log" + " '" + commit1 + "'.." + commit2 + " --oneline --pretty=format:'%h'" + cmd = "git log" + " " + commit1 + ".." + commit2 + " --oneline --pretty=format:'%h'" hash = [] multiline_str = os.popen(cmd) for line in multiline_str.readlines(): @@ -56,8 +56,12 @@ def get_commit_body(hash): return preprocessed #获取某个commit的修改文件 -def get_commit_diff_files(hash_list,hash_commit): - num = list.index(hash_list) +def get_commit_diff_files(hash_commit): + cmd = "git log" + " " + hash_commit + " -2 --oneline --pretty=format:'%h'" + hash = [] + multiline_str = os.popen(cmd) + for line in multiline_str.readlines(): + hash.append(line.replace('\n','')) cmd = "git diff" + " --name-only " + hash[1] + " " + hash[0] process = os.popen(cmd) preprocessed = process.read() diff --git a/pygitlog/mdoperation.py b/pygitlog/mdoperation.py index 4f9a163..794fbfb 100644 --- a/pygitlog/mdoperation.py +++ b/pygitlog/mdoperation.py @@ -1,14 +1,32 @@ from pygitlog.gitoperation import * +import sys + +def mkdir(path): + # 去除首位空格 + path=path.strip() + # 去除尾部 \ 符号 + path=path.rstrip("\\") + # 判断路径是否存在 + isExists=os.path.exists(path) + # 判断结果 + if not isExists: + os.makedirs(path) + print (path + " 创建成功") + else: + # 如果目录存在则不创建,并提示目录已存在 + print (path + " 目录已存在") def initmd(version1,version2,source): - filename = source + version1 + "_" + version2 + ".md" + dir = os.getcwd() + "/output/" + mkdir(dir) + filename = dir + source + version1 + "_" + version2 + ".md" with open(filename,mode="w") as file: file.write("# kernel log summary\n") file.write("## " + source + " from " + version1 + " to " + version2 + "\n") file.write("| hash | time | editor | email | body | type | keywords | diff-files | \n") file.write("| :---- | :---- | :---- | :---- | :--- | :---- | :------- | :--------- | \n") os.chmod(filename,448) - return os.getcwd() + "/" + filename + return filename def format(str):