forked from Ascotbe/Kernelhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentGeneration.py
91 lines (82 loc) · 4.95 KB
/
DocumentGeneration.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
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
Path="/Users/ascotbe/code/Kernelhub"
SuccessList=[]
FailureList=[]
def Config():
CNBegin="""let config = {\n title: 'Kernelhub',\n home: 'Info.md',\n repo: 'Ascotbe/Kernelhub',\n nav: [\n {\n title: '简介', path: '/'\n },\n {\n title: '目录导航',type: 'dropdown', items: [\n {\n title: "有利用脚本(测试成功)",path: '/TestSuccess'\n },"""
End="""\n ]\n },\n ],\n tocVisibleDepth: 10,\n plugins: []\n};"""
RejectList=['.DS_Store', '.git','.idea', '.gitignore','LICENSE', 'Patch', 'README.CN.md', 'README.md', 'TestFailure', 'docs', 'DocumentGeneration.py']
ENBegin="""let config = {\n title: 'Kernelhub',\n home: 'Info.md',\n repo: 'Ascotbe/Kernelhub',\n nav: [\n {\n title: 'Introduction', path: '/'\n },\n {\n title: 'DirectoryNavigation',type: 'dropdown', items: [\n {\n title: "exploit script (successful test)",path: '/TestSuccess'\n },"""
#处理成功的编号
for i in os.listdir(Path):
if i not in RejectList:
SuccessList.append(i)
for x in sorted(SuccessList):
CNBegin+="""\n {\n path: '/CN/"""+x+"""', source: 'https://raw.githubusercontent.com/Ascotbe/Kernelhub/master/"""+x+"""/README.md'\n },"""
ENBegin+="""\n {\n path: '/EN/"""+x+"""', source: 'https://raw.githubusercontent.com/Ascotbe/Kernelhub/master/"""+x+"""/README_EN.md'\n },"""
#处理失败的编号
CNBegin+="""\n {\n title: '有利用脚本(测试未成功)', path: '/TestFailure'\n },"""
ENBegin+="""\n {\n title: 'exploit script (test failure)', path: '/TestFailure'\n },"""
for i in os.listdir(Path+"/TestFailure"):
if i not in RejectList:
FailureList.append(i)
for xx in sorted(FailureList):
CNBegin+="""\n {\n path: '/CN/"""+xx+"""', source: 'https://raw.githubusercontent.com/Ascotbe/Kernelhub/master/TestFailure/"""+xx+"""/README.md'\n },"""
ENBegin+="""\n {\n path: '/EN/"""+xx+"""', source: 'https://raw.githubusercontent.com/Ascotbe/Kernelhub/master/TestFailure/"""+xx+"""/README_EN.md'\n },"""
CNBegin+=End
ENBegin+=End
cn_file=open(Path+"/docs/Docs/config.js","w+")
cn_file.write(CNBegin)
cn_file.close()
en_file=open(Path+"/docs/EnglishDocs/config.js","w+")
en_file.write(ENBegin)
en_file.close()
def Markdown():
CVEList=[]
CNMarkdownSuccessList=[]
CNMarkdownFailureList=[]
ENMarkdownSuccessList=[]
ENMarkdownFailureList=[]
file=open(Path+"/README.md","r").read()
date = re.findall(r'(?<=> Numbered list)([\w\W]+)(?=### Required environment)', file)[0].split("\n")
for i in date:
if i != "":
CVEList.append(i)
for x in CVEList[2:]:
date = re.findall(r'(?<=\[)([\w\W]+)(?=\])', x)[0]
if date in SuccessList:
CNMarkdownSuccessList.append(re.sub(r'(?<=\()([\w\W]+)(?=\))', "http://kernelhub.ascotbe.com/Docs/#/CN/"+date, x))
ENMarkdownSuccessList.append(re.sub(r'(?<=\()([\w\W]+)(?=\))', "http://kernelhub.ascotbe.com/EnglishDocs/#/EN/"+date, x))
if date in FailureList:
CNMarkdownFailureList.append(re.sub(r'(?<=\()([\w\W]+)(?=\))', "http://kernelhub.ascotbe.com/Docs/#/CN/"+date, x))
ENMarkdownFailureList.append(re.sub(r'(?<=\()([\w\W]+)(?=\))', "http://kernelhub.ascotbe.com/EnglishDocs/#/EN/"+date, x))
CNMarkdownSuccessDate=CVEList[0]+"\n"+CVEList[1]+"\n"
CNMarkdownFailureDate=CVEList[0]+"\n"+CVEList[1]+"\n"
ENMarkdownSuccessDate=CVEList[0]+"\n"+CVEList[1]+"\n"
ENMarkdownFailureDate=CVEList[0]+"\n"+CVEList[1]+"\n"
for x1 in CNMarkdownSuccessList:
CNMarkdownSuccessDate+=x1+"\n"
for x2 in CNMarkdownFailureList:
CNMarkdownFailureDate+=x2+"\n"
for x3 in ENMarkdownSuccessList:
ENMarkdownSuccessDate+=x3+"\n"
for x4 in ENMarkdownFailureList:
ENMarkdownFailureDate+=x4+"\n"
CNTestSuccess=open(Path+"/docs/Docs/TestSuccess.md","w+")
CNTestSuccess.write(CNMarkdownSuccessDate)
CNTestSuccess.close()
CNTestFailure=open(Path+"/docs/Docs/TestFailure.md","w+")
CNTestFailure.write(CNMarkdownFailureDate)
CNTestFailure.close()
ENTestSuccess=open(Path+"/docs/EnglishDocs/TestSuccess.md","w+")
ENTestSuccess.write(ENMarkdownSuccessDate)
ENTestSuccess.close()
ENTestFailure=open(Path+"/docs/EnglishDocs/TestFailure.md","w+")
ENTestFailure.write(ENMarkdownFailureDate)
ENTestFailure.close()
if __name__ == '__main__':
Config()
Markdown()