-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.py
83 lines (67 loc) · 2.16 KB
/
doc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# ~*~
import os
import sys
PREFIX = u'//'
sys.stdout = open("README.md", "w", encoding="utf-8")
def get_extension(file_name):
return os.path.splitext(file_name)[1]
def lang(file_name):
extension = get_extension(file_name)
if extension in ['.cpp', '.c', '.h', '.hpp']:
return 'cpp'
if extension == '.java':
return 'java'
return "TODO: doc.py Сделать обработчик **" + extension + "**";
def parse(file_name):
"""
:param file_name: имя файла
:return:
"""
code = False
with open(file_name, "r", encoding="utf-8-sig") as f:
for line in f:
if '//-->' in line:
print('``` ' + lang(file_name))
code = True
continue
if '//<--' in line:
print('```')
code = False
continue
if code:
print(line.rstrip())
continue
s = line.strip()
if s.startswith(PREFIX):
print(s[len(PREFIX):].strip())
from os import listdir
from os.path import isfile, join
mypath = "."
extensions = [".cpp", ".c", ".h", ".hpp", ".java", ".md"]
special_files = ["pom.xml"]
all_files = []
for root, dirs, files in os.walk("."):
for name in files:
if (get_extension(name) in extensions) or (name in special_files):
# Пропускаем готовые README.md
# if name.upper() == "README.md".upper():
# continue
file_name = os.path.join(root, name)
#print(file_name)
#if name == "README.md":
# continue
if file_name == '.\\README.md':
continue
all_files.append(file_name)
for file_name in sorted(all_files):
# Markdown файлы просто передаём на выход не меняя
print(file_name)
print()
if get_extension(file_name).lower() == ".md":
print()
for line in open(file_name, 'r', encoding="utf-8"):
print(line.rstrip())
print()
continue
parse(file_name)
# [f for f in listdir(mypath) if isfile(join(mypath, f))]