Updated doc build scripts for Python 3

These changes allow the scripts to work with either Python 2 or 3.
This commit is contained in:
David G Yu 2022-09-11 15:33:46 -07:00
parent 40eee124f4
commit 26cda644a3
2 changed files with 30 additions and 28 deletions

View File

@ -22,16 +22,17 @@
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
from __future__ import print_function
import os
import sys
import string
import re
import HTMLParser
from html.parser import HTMLParser
class HtmlToTextParser(HTMLParser.HTMLParser):
class HtmlToTextParser(HTMLParser):
def __init__(self):
HTMLParser.HTMLParser.__init__(self)
HTMLParser.__init__(self)
self.m_text = []
self.m_inTitle = False
self.m_inScript = False
@ -89,10 +90,10 @@ def ReadNavigationTemplate( filePath ):
try:
navFile = open( filePath, "r")
except IOError:
print "Could not open file \'"+filePath+"\'"
print("Could not open file \'"+filePath+"\'")
with navFile:
print "Navigation template: \'"+filePath+"\'"
print("Navigation template: \'"+filePath+"\'")
navHtml = navFile.read()
navHtml = StripHTMLComments(navHtml)
navFile.close()
@ -105,11 +106,11 @@ def WriteIndexFile( outputFile, content ):
outputPath = os.path.dirname( outputFile )
try:
os.makedirs( outputPath );
os.makedirs( outputPath )
except:
pass
print "Creating Search-Index File : \""+outputFile+"\""
print("Creating Search-Index File : \""+outputFile+"\"")
f = open(outputFile, "w")
f.write(content)
@ -117,8 +118,8 @@ def WriteIndexFile( outputFile, content ):
#-------------------------------------------------------------------------------
def Usage():
print str(sys.argv[0])+" <input directory> <output directory> <html template>"
exit(1);
print(str(sys.argv[0])+" <input directory> <output directory> <html template>")
exit(1)
#-------------------------------------------------------------------------------
@ -132,7 +133,7 @@ navTemplate = str(sys.argv[2])
navHtml = ReadNavigationTemplate( navTemplate )
print "Scanning : \'"+rootDir+"\'"
print("Scanning : \'"+rootDir+"\'")
searchIndex = 'var tipuesearch = { "pages": [ '
@ -157,7 +158,7 @@ for root, dirs, files in os.walk(rootDir):
parser.feed(html)
title = parser.GetTitle()
text = parser.GetText()
except HTMLParser.HTMLParseError:
except HTMLParser.error:
continue
msg = " \""+inputFile+"\" - "
@ -172,22 +173,22 @@ for root, dirs, files in os.walk(rootDir):
# if necessary, insert navigation html
if (not parser.HasNavigationSection()):
loc = string.find(html,"<body>")
loc = html.find("<body>")
html = html[:loc+6] + navHtml + html[loc+6:]
msg += "added navigation"
# replace the article title placeholder with the real title
if title:
html = string.replace(html,"OSD_ARTICLE_TITLE", title)
html = html.replace("OSD_ARTICLE_TITLE", title)
else:
html = string.replace(html,"OSD_ARTICLE_TITLE", "")
html = html.replace("OSD_ARTICLE_TITLE", "")
f.seek(0)
f.write(html)
f.close()
print msg
print(msg)
searchIndex = searchIndex + "]};"

View File

@ -22,6 +22,7 @@
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
from __future__ import print_function
import os
import sys
@ -33,7 +34,7 @@ def ReadFile(inputfile):
try:
f = open( inputfile, "r")
except IOError:
print "Could not read file \'"+inputfile+"\'"
print("Could not read file \'"+inputfile+"\'")
content = f.read()
f.close()
return content
@ -42,13 +43,13 @@ def ReadFile(inputfile):
def WriteToFile(outputfile, content):
outputPath = os.path.dirname(outputfile)
try:
os.makedirs(outputPath);
os.makedirs(outputPath)
except:
pass
try:
f = open(outputfile, "w")
except IOError:
print "Could not write file \'"+outputfile+"\'"
print("Could not write file \'"+outputfile+"\'")
f.write(content)
f.close()
@ -86,8 +87,8 @@ def Process(srcfile, title):
#-------------------------------------------------------------------------------
def Usage():
print str(sys.argv[0])+" <input file> <output file> <title>"
exit(1);
print(str(sys.argv[0])+" <input file> <output file> <title>")
exit(1)
#-------------------------------------------------------------------------------