diff --git a/pygitlog/fsoperation.py b/pygitlog/fsoperation.py new file mode 100644 index 0000000..077a492 --- /dev/null +++ b/pygitlog/fsoperation.py @@ -0,0 +1,42 @@ +import os + +def mkdir(path): + # 去除首位空格 + path=path.strip() + # 去除尾部 \ 符号 + path=path.rstrip("\\") + # 判断路径是否存在 + isExists=os.path.exists(path) + # 判断结果 + if not isExists: + os.makedirs(path) + +#文档内容删除,head代表从第几行开始要,tail表示倒数第几行开始不要 +def delete_lines(file_name, head,tail): + fin = open(file_name, 'r') + a = fin.readlines() + fout = open(file_name, 'w') + b = ''.join(a[head:-tail]) + fout.write(b) + +##实现body的展开功能(attr为summary) +def format(str1,str2): + list = "
" + str1 + " " + list = list + str2.replace('\n','
')+"
" + return list + +##实现文件差别的展开功能(首行summary) +def format_diff(str): + a = 0 + if str.count('\n') > 1: + for line in str.split('\n'): + if a == 0: + #防止首行为空,其实没必要 + if line != '': + list = "
" + line + " " + a = 1 + else: + list = list + line + '
' + return list + "
" + else: + return str.replace('\n','') \ No newline at end of file