-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse_docs.py
More file actions
executable file
·91 lines (81 loc) · 3.81 KB
/
parse_docs.py
File metadata and controls
executable file
·91 lines (81 loc) · 3.81 KB
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
#!/usr/bin/env python3
import os
import glob
import re
class Errata:
def parse_docs(self):
function_name_start = "docs/function."
function_name_end = ".html"
keywords = ["security", "deprecat", "unsafe", "warning", "code exec", "danger"] # changes here need updating below
security_matches = []
deprecat_matches = []
unsafe_matches = []
warning_matches = []
pop_the_champagne_matches = []
danger_matches = []
security_fd = open("security.txt", "a")
deprecat_fd = open("deprecated.txt", "a")
unsafe_fd = open("unsafe.txt", "a")
warning_fd = open("warning.txt", "a")
code_exec_fd = open("code-exec.txt", "a")
danger_fd = open("danger.txt", "a")
for filename in glob.iglob("docs/**/function.*.html", recursive=True):
fd = open(filename, "r")
current_file = fd.read()
for item in keywords:
temp = re.search(item, current_file, re.IGNORECASE)
if temp:
if item == "security":
function_name = re.search('%s(.*)%s' % (function_name_start, function_name_end), filename).group(1)
function_name = function_name.replace("-","_")
security_matches.append(function_name)
if item == "deprecat":
function_name = re.search('%s(.*)%s' % (function_name_start, function_name_end), filename).group(1)
function_name = function_name.replace("-","_")
deprecat_matches.append(function_name)
if item == "unsafe":
function_name = re.search('%s(.*)%s' % (function_name_start, function_name_end), filename).group(1)
function_name = function_name.replace("-","_")
unsafe_matches.append(function_name)
if item == "warning":
function_name = re.search('%s(.*)%s' % (function_name_start, function_name_end), filename).group(1)
function_name = function_name.replace("-","_")
warning_matches.append(function_name)
if item == "code exec":
function_name = re.search('%s(.*)%s' % (function_name_start, function_name_end), filename).group(1)
function_name = function_name.replace("-","_")
pop_the_champagne_matches.append(function_name)
if item == "danger":
function_name = re.search('%s(.*)%s' % (function_name_start, function_name_end), filename).group(1)
function_name = function_name.replace("-","_")
danger_matches.append(function_name)
fd.close()
if len(security_matches) != 0:
for x in security_matches:
security_fd.write("%s\n" % x)
if len(deprecat_matches) != 0:
for x in deprecat_matches:
deprecat_fd.write("%s\n" % x)
if len(unsafe_matches) != 0:
for x in unsafe_matches:
unsafe_fd.write("%s\n" % x)
if len(warning_matches) != 0:
for x in warning_matches:
warning_fd.write("%s\n" % x)
if len(pop_the_champagne_matches) != 0:
for x in pop_the_champagne_matches:
code_exec_fd.write("%s\n" % x)
if len(danger_matches) != 0:
for x in danger_matches:
danger_fd.write("%s\n" %x)
security_fd.close()
deprecat_fd.close()
unsafe_fd.close()
warning_fd.close()
code_exec_fd.close()
danger_fd.close()
def main():
x = Errata()
x.parse_docs()
if __name__ == "__main__":
main()