mirror of https://gitee.com/bigwinds/arangodb
Fixed error in script
This commit is contained in:
parent
900aa7f33b
commit
270cb1eb6e
|
@ -2,35 +2,7 @@ import sys
|
|||
import re
|
||||
import os
|
||||
|
||||
def replaceText(text,pathOfFile):
|
||||
f=open(pathOfFile,"rU")
|
||||
if f:
|
||||
s=f.read()
|
||||
f.close()
|
||||
f=open(pathOfFile,'w')
|
||||
|
||||
replaced=re.sub('@startDocuBlock\s+\w+',text,s)
|
||||
|
||||
f.write(replaced)
|
||||
f.close()
|
||||
|
||||
def getTextFromSourceFile(searchText):
|
||||
f=open("allComments.txt", 'rU')
|
||||
s=f.read()
|
||||
match = re.search(r'@startDocuBlock\s+'+re.escape(searchText)+'(.+?)@endDocuBlock', s,re.DOTALL)
|
||||
if match:
|
||||
global textExtracted
|
||||
textExtracted = match.group(1)
|
||||
return textExtracted
|
||||
def findStartCode(textFile,full_path):
|
||||
match = re.findall(r'@startDocuBlock\s*(\w+)', textFile)
|
||||
if match:
|
||||
for find in match:
|
||||
textToReplace=getTextFromSourceFile(find)
|
||||
replaceText(textToReplace,full_path)
|
||||
return
|
||||
|
||||
def walk_on_files(dirpatp):
|
||||
def walk_on_files(dirpath):
|
||||
for root, dirs, files in os.walk(dirpath):
|
||||
for file in files:
|
||||
if file.endswith(".md"):
|
||||
|
@ -42,11 +14,34 @@ def walk_on_files(dirpatp):
|
|||
findStartCode(textFile,full_path)
|
||||
return
|
||||
|
||||
def main():
|
||||
walk_on_files()
|
||||
def findStartCode(textFile,full_path):
|
||||
match = re.findall(r'@startDocuBlock\s*(\w+)', textFile)
|
||||
if match:
|
||||
for find in match:
|
||||
textToReplace=getTextFromSourceFile(find, full_path)
|
||||
|
||||
def getTextFromSourceFile(searchText, full_path):
|
||||
f=open("allComments.txt", 'rU')
|
||||
s=f.read()
|
||||
match = re.search(r'@startDocuBlock\s+'+re.escape(searchText)+'(.+?)@endDocuBlock', s,re.DOTALL)
|
||||
if match:
|
||||
textExtracted = match.group(1)
|
||||
replaceText(textExtracted, full_path, searchText)
|
||||
|
||||
def replaceText(text, pathOfFile, searchText):
|
||||
f=open(pathOfFile,"rU")
|
||||
if f:
|
||||
s=f.read()
|
||||
f.close()
|
||||
f=open(pathOfFile,'w')
|
||||
|
||||
replaced=re.sub('@startDocuBlock\s+'+ searchText + "(?:\s+|$)",text,s)
|
||||
|
||||
f.write(replaced)
|
||||
f.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
path = ["Documentation/Books/Users/"]
|
||||
path = ["Documentation/Books/Users"]
|
||||
for i in path:
|
||||
dirpath = os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.pardir,"ArangoDB/../../"+i))
|
||||
walk_on_files(dirpath)
|
Loading…
Reference in New Issue