generated from readthedocs/tutorial-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
references.py
152 lines (129 loc) · 5.52 KB
/
references.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import csv
import os
from pathlib import Path
def safe_open_w(path):
os.makedirs(os.path.dirname(path), exist_ok=True)
return open(path, 'w', encoding="utf8")
testsmells = {}
with open('./scripts/allreferences.csv', encoding="utf8") as csvfile:
filereader = csv.DictReader(csvfile)
for row in filereader:
if(row["Name"].title() in testsmells.keys()):
testsmells[row["Name"].title()]["references"].append(
{
"link": row["Reference Title"],
"title": row["Title"],
"code_example": row["Code Example"] == "TRUE",
"causes_effects": row["Causes / Effects"] == "TRUE",
"frequency": row["Frequency"] == "TRUE",
"refactor": row["Refactoring"] == "TRUE",
}
)
testsmells[row["Name"].title()]["definitions"].append(row["Definition"])
else:
testsmells[row["Name"].title()] = {
"references": [
{
"link": row["Reference Title"],
"title": row["Title"],
"code_example": row["Code Example"] == "TRUE",
"causes_effects": row["Causes / Effects"] == "TRUE",
"frequency": row["Frequency"] == "TRUE",
"refactor": row["Refactoring"] == "TRUE",
}
],
"definitions": [row["Definition"]]
}
for root, dirs, files in os.walk("docs\source", topdown=False):
for name in files:
path_file = os.path.join(root, name)
if (path_file.count("\\") == 2 or "generated" in path_file or "_static" in path_file or "index.rst" in path_file or ".rst" not in path_file):
continue
text = ""
with open(".\\"+path_file, 'r', encoding="utf-8") as rstfile:
title = rstfile.readline()[:-1].strip().title()
if(title not in testsmells.keys()):
print(title)
continue
text += title + '\n'
linhas = rstfile.readlines()
i = 0
for line in linhas:
i+=1
text += line
if("* :octicon:`graph;1em` - Frequency" in line):
text+=" * :octicon:`sync;1em` - Refactoring\n\n"
break
i+=1
rstfile.seek(0)
testsmells[title]["references"].sort(key=lambda x: x["title"])
for reference in testsmells[title]["references"]:
text += "* `"+reference["title"]+" <"+reference["link"]+">`_"
if(reference["code_example"]):
text += " :octicon:`file-code;1em`"
if(reference["causes_effects"]):
text += " :octicon:`comment-discussion;1em`"
if(reference["frequency"]):
text += " :octicon:`graph;1em`"
if(reference["refactor"]):
text += " :octicon:`sync;1em`"
text += "\n"
with open(".\\"+path_file, 'w', encoding="utf-8") as rstfile:
rstfile.write(text)
# i = 0
# with open('mycsv.csv', 'r', encoding="utf8") as csvfile:
# file = csv.reader(csvfile)
# for row in file:
# i+=1
# name = row[7].title()
# #print(row[10] == "TRUE", row[11] == "TRUE", row[12] == "TRUE")
# if(name not in testsmells):
# testsmells[name] = {}
# testsmells[name]["references"] = [{
# "Reference Title": row[2],
# "title": row[3],
# "example": row[10] == "TRUE",
# "ce": row[11] == "TRUE",
# "freq": row[12] == "TRUE"
# }]
# else:
# testsmells[name]["references"].append({
# "Reference Title": row[2],
# "title": row[3],
# "example": row[10] == "TRUE",
# "ce": row[11] == "TRUE",
# "freq": row[12] == "TRUE"
# })
# for root, dirs, files in os.walk("docs\source", topdown=False):
# for name in files:
# path_file = os.path.join(root, name)
# if (path_file.count("\\") == 2 or "generated" in path_file or "_static" in path_file or "index.rst" in path_file or ".rst" not in path_file):
# continue
# text = ""
# with open(".\\"+path_file, 'r+', encoding="utf-8") as rstfile:
# title = rstfile.readline()[:-1].strip().title()
# text += title + '\n'
# linhas = rstfile.readlines()
# i = 0
# for line in linhas:
# i+=1
# text += line
# if("**References:**:" in line):
# text+="\n"
# break
# i+=1
# rstfile.seek(0)
# for lineReference in linhas[i:]:
# for reference in testsmells[title]["references"]:
# if(reference["Reference Title"] in lineReference):
# text += lineReference[:-1]
# if(reference["example"]):
# text += " :octicon:`file-code;1em`"
# if(reference["ce"]):
# text += " :octicon:`comment-discussion;1em`"
# if(reference["freq"]):
# text += " :octicon:`graph;1em`"
# text += "\n"
# text+='\n'
# rstfile.seek(0, 0)
# rstfile.write(text)