fix several Py3 issues
This commit is contained in:
@@ -16,7 +16,7 @@ def deserializeVersionHeader(path):
|
||||
for l in dat:
|
||||
tokens = l.split()
|
||||
if len(tokens) > 1 and tokens[0].lower() == '#define':
|
||||
version[tokens[1]] = tokens[2].replace('"',"")
|
||||
version[tokens[1]] = tokens[2].replace('"',"")
|
||||
|
||||
return version
|
||||
|
||||
|
||||
@@ -135,11 +135,11 @@ def set_type_constants(nameSpace):
|
||||
DEBUG = 1
|
||||
def dbgprint(level, msg):
|
||||
if DEBUG and level > 0:
|
||||
print msg
|
||||
print (msg)
|
||||
|
||||
def pplist(lst):
|
||||
for count, item in enumerate(lst):
|
||||
print '%d. %s' % (count, item)
|
||||
print ('%d. %s' % (count, item))
|
||||
|
||||
|
||||
|
||||
@@ -433,7 +433,7 @@ class XschemaElement:
|
||||
attr = attrGroup.get(name)
|
||||
self.attributeDefs[name] = attr
|
||||
else:
|
||||
print '*** Error. attributeGroup %s not defined.' % groupName
|
||||
print ('*** Error. attributeGroup %s not defined.' % groupName)
|
||||
|
||||
def __str__(self):
|
||||
s1 = '<"%s" XschemaElement instance at 0x%x>' % \
|
||||
@@ -560,7 +560,7 @@ class XschemaHandler(handler.ContentHandler):
|
||||
return self.root
|
||||
|
||||
def showError(self, msg):
|
||||
print msg
|
||||
print (msg)
|
||||
sys.exit(-1)
|
||||
|
||||
def startElement(self, name, attrs):
|
||||
@@ -710,7 +710,7 @@ class XschemaHandler(handler.ContentHandler):
|
||||
elif name == SchemaType:
|
||||
self.inSchema = 0
|
||||
if len(self.stack) != 1:
|
||||
print '*** error stack. len(self.stack): %d' % len(self.stack)
|
||||
print ('*** error stack. len(self.stack): %d' % len(self.stack))
|
||||
sys.exit(-1)
|
||||
self.root = self.stack[0]
|
||||
elif name == ComplexContentType:
|
||||
@@ -1957,8 +1957,8 @@ def generateClasses(outfile, prefix, element, delayed):
|
||||
return
|
||||
AlreadyGenerated.append(element.getName())
|
||||
if element.getMixedExtensionError():
|
||||
print '*** Element %s extension chain contains mixed and non-mixed content. Not generated.' % \
|
||||
(element.getName(),)
|
||||
print ('*** Element %s extension chain contains mixed and non-mixed content. Not generated.' % \
|
||||
(element.getName(),))
|
||||
return
|
||||
ElementsForSubclasses.append(element)
|
||||
name = element.getCleanName()
|
||||
@@ -2735,7 +2735,7 @@ def get_impl_body(classBehavior, baseImplUrl, implUrl):
|
||||
impl = implFile.read()
|
||||
implFile.close()
|
||||
except urllib2.HTTPError:
|
||||
print '*** Implementation at %s not found.' % implUrl
|
||||
print ('*** Implementation at %s not found.' % implUrl)
|
||||
return impl
|
||||
|
||||
###
|
||||
@@ -2762,7 +2762,7 @@ def get_impl_body(classBehavior, baseImplUrl, implUrl):
|
||||
## impl = implFile.read()
|
||||
## implFile.close()
|
||||
## except:
|
||||
## print '*** Implementation at %s not found.' % implUrl
|
||||
## print ('*** Implementation at %s not found.' % implUrl)
|
||||
## return impl
|
||||
|
||||
|
||||
@@ -3030,9 +3030,9 @@ def generateSubclasses(root, subclassFilename, behaviorFilename,
|
||||
sys.path.insert(0, '.')
|
||||
import xmlbehavior_sub as xmlbehavior
|
||||
except ImportError:
|
||||
print '*** You have requested generation of extended methods.'
|
||||
print '*** But, no xmlbehavior module is available.'
|
||||
print '*** Generation of extended behavior methods is omitted.'
|
||||
print ('*** You have requested generation of extended methods.')
|
||||
print ('*** But, no xmlbehavior module is available.')
|
||||
print ('*** Generation of extended behavior methods is omitted.')
|
||||
if xmlbehavior:
|
||||
behaviors = xmlbehavior.parse(behaviorFilename)
|
||||
behaviors.make_class_dictionary(cleanupName)
|
||||
@@ -3227,7 +3227,7 @@ python generateDS.py -o generateModel_Module.py generateMetaModel_Module.xsd
|
||||
"""
|
||||
|
||||
def usage():
|
||||
print USAGE_TEXT
|
||||
print (USAGE_TEXT)
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
@@ -3266,7 +3266,7 @@ def main():
|
||||
superModule = option[1]
|
||||
set_type_constants(nameSpace)
|
||||
if behaviorFilename and not subclassFilename:
|
||||
print '\n*** Error. -b requires -s'
|
||||
print ('\n*** Error. -b requires -s')
|
||||
usage()
|
||||
if len(args) != 1:
|
||||
usage()
|
||||
|
||||
@@ -9,7 +9,7 @@ import generateBase.generateTools
|
||||
class TemplateCPPFile (template.ModelTemplate):
|
||||
def Generate(self):
|
||||
generateBase.generateTools.ensureDir(self.path)
|
||||
print "Generate() App Dir"
|
||||
print ("Generate() App Dir")
|
||||
|
||||
Template = """
|
||||
/***************************************************************************
|
||||
@@ -36,4 +36,4 @@ Template = """
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
"""
|
||||
"""
|
||||
|
||||
@@ -52,10 +52,10 @@ def crawl():
|
||||
# tests ###############################################
|
||||
|
||||
if os.system(QHELPCOMPILER +' -v'):
|
||||
print "Error: QAssistant not fully installed, exiting."
|
||||
print ("Error: QAssistant not fully installed, exiting.")
|
||||
return 1
|
||||
if os.system(QCOLLECTIOMGENERATOR +' -v'):
|
||||
print "Error: QAssistant not fully installed, exiting."
|
||||
print ("Error: QAssistant not fully installed, exiting.")
|
||||
return 1
|
||||
|
||||
# run ########################################################
|
||||
@@ -64,22 +64,22 @@ def crawl():
|
||||
qhcp = createCollProjectFile()
|
||||
shutil.copy("../../Gui/Icons/freecad-icon-64.png","localwiki/freecad-icon-64.png")
|
||||
if generate(qhcp) or compile(qhp):
|
||||
print "Error at compiling"
|
||||
print ("Error at compiling")
|
||||
return 1
|
||||
if VERBOSE: print "All done!"
|
||||
if VERBOSE: print ("All done!")
|
||||
i=raw_input("Copy the files to their correct location in the source tree? y/n (default=no) ")
|
||||
if i.upper() in ["Y","YES"]:
|
||||
shutil.copy("localwiki/freecad.qch","../../Doc/freecad.qch")
|
||||
shutil.copy("localwiki/freecad.qhc","../../Doc/freecad.qhc")
|
||||
else:
|
||||
print 'Files are in localwiki. Test with "assistant -collectionFile localwiki/freecad.qhc"'
|
||||
print ('Files are in localwiki. Test with "assistant -collectionFile localwiki/freecad.qhc"')
|
||||
return 0
|
||||
|
||||
def compile(qhpfile):
|
||||
"compiles the whole html doc with qassistant"
|
||||
qchfile = FOLDER + os.sep + "freecad.qch"
|
||||
if not os.system(QHELPCOMPILER + ' '+qhpfile+' -o '+qchfile):
|
||||
if VERBOSE: print "Successfully created",qchfile
|
||||
if VERBOSE: print ("Successfully created",qchfile)
|
||||
return 0
|
||||
|
||||
def generate(qhcpfile):
|
||||
@@ -93,7 +93,7 @@ def generate(qhcpfile):
|
||||
about.close()
|
||||
qhcfile = FOLDER + os.sep + "freecad.qhc"
|
||||
if not os.system(QCOLLECTIOMGENERATOR+' '+qhcpfile+' -o '+qhcfile):
|
||||
if VERBOSE: print "Successfully created ",qhcfile
|
||||
if VERBOSE: print ("Successfully created ",qhcfile)
|
||||
return 0
|
||||
|
||||
def createCollProjectFile():
|
||||
@@ -131,12 +131,12 @@ def createCollProjectFile():
|
||||
</docFiles>
|
||||
</QHelpCollectionProject>
|
||||
'''
|
||||
if VERBOSE: print "Building project file..."
|
||||
if VERBOSE: print ("Building project file...")
|
||||
qfilename = FOLDER + os.sep + "freecad.qhcp"
|
||||
f = open(qfilename,'w')
|
||||
f.write(qprojectfile)
|
||||
f.close()
|
||||
if VERBOSE: print "Done writing qhcp file",qfilename
|
||||
if VERBOSE: print ("Done writing qhcp file",qfilename)
|
||||
return qfilename
|
||||
|
||||
def buildtoc():
|
||||
@@ -182,7 +182,7 @@ def buildtoc():
|
||||
if not link: link = 'default.html'
|
||||
return title,link
|
||||
|
||||
if VERBOSE: print "Building table of contents..."
|
||||
if VERBOSE: print ("Building table of contents...")
|
||||
f = open(FOLDER+os.sep+INDEX+'.html')
|
||||
html = ''
|
||||
for line in f: html += line
|
||||
@@ -229,9 +229,9 @@ def buildtoc():
|
||||
f = open(qfilename,'wb')
|
||||
f.write(qhelpfile)
|
||||
f.close()
|
||||
if VERBOSE: print "Done writing qhp file",qfilename
|
||||
if VERBOSE: print ("Done writing qhp file",qfilename)
|
||||
return qfilename
|
||||
|
||||
if __name__ == "__main__":
|
||||
crawl()
|
||||
|
||||
crawl()
|
||||
|
||||
|
||||
@@ -60,15 +60,15 @@ def crawl(pagename=[]):
|
||||
else:
|
||||
if os.path.exists("wikifiles.txt"):
|
||||
f = open("wikifiles.txt","r")
|
||||
if VERBOSE: print "Reading existing list..."
|
||||
if VERBOSE: print ("Reading existing list...")
|
||||
for l in f.readlines():
|
||||
if l.strip() != "":
|
||||
if VERBOSE: print "Adding ",l
|
||||
if VERBOSE: print ("Adding ",l)
|
||||
processed.append(l.strip())
|
||||
f.close()
|
||||
if os.path.exists("todolist.txt"):
|
||||
f = open("todolist.txt","r")
|
||||
if VERBOSE: print "Reading existing todo list..."
|
||||
if VERBOSE: print ("Reading existing todo list...")
|
||||
for l in f.readlines():
|
||||
if l.strip() != "":
|
||||
todolist.append(l.strip())
|
||||
@@ -79,19 +79,19 @@ def crawl(pagename=[]):
|
||||
while todolist:
|
||||
targetpage = todolist.pop()
|
||||
if (not targetpage in NORETRIEVE):
|
||||
if VERBOSE: print count, ": Scanning ", targetpage
|
||||
if VERBOSE: print (count, ": Scanning ", targetpage)
|
||||
pages,images = get(targetpage)
|
||||
count += 1
|
||||
processed.append(targetpage)
|
||||
processed.extend(images)
|
||||
if VERBOSE: print "got",len(pages),"links"
|
||||
if VERBOSE: print ("got",len(pages),"links")
|
||||
for p in pages:
|
||||
if (not (p in todolist)) and (not (p in processed)):
|
||||
todolist.append(p)
|
||||
if WRITETHROUGH:
|
||||
writeList(processed)
|
||||
writeList(todolist,"todolist.txt")
|
||||
if VERBOSE: print "Fetched ", count, " pages"
|
||||
if VERBOSE: print ("Fetched ", count, " pages")
|
||||
if not WRITETHROUGH:
|
||||
writeList(processed)
|
||||
if pagename:
|
||||
@@ -156,7 +156,7 @@ def getlinks(html):
|
||||
NORETRIEVE.append(rg)
|
||||
if not rg in NORETRIEVE:
|
||||
pages.append(rg)
|
||||
print "got link: ",rg
|
||||
print ("got link: ",rg)
|
||||
return pages
|
||||
|
||||
def getimagelinks(html):
|
||||
@@ -167,7 +167,7 @@ def getimagelinks(html):
|
||||
|
||||
def fetchpage(page):
|
||||
"retrieves given page from the wiki"
|
||||
print "fetching: ",page
|
||||
print ("fetching: ",page)
|
||||
failcount = 0
|
||||
while failcount < MAXFAIL:
|
||||
try:
|
||||
@@ -175,7 +175,7 @@ def fetchpage(page):
|
||||
return html
|
||||
except HTTPError:
|
||||
failcount += 1
|
||||
print 'Error: unable to fetch page ' + page
|
||||
print ('Error: unable to fetch page ' + page)
|
||||
sys.exit()
|
||||
|
||||
def cleanList(pagelist):
|
||||
@@ -193,7 +193,7 @@ def writeList(pages,filename="wikifiles.txt"):
|
||||
for p in pages:
|
||||
f.write(p+"\n")
|
||||
f.close()
|
||||
if VERBOSE: print "written ",filename
|
||||
if VERBOSE: print ("written ",filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
crawl(sys.argv[1:])
|
||||
|
||||
@@ -137,7 +137,7 @@ def crawl():
|
||||
"downloads an entire wiki site"
|
||||
global processed
|
||||
processed = []
|
||||
if VERBOSE: print "crawling ", URL, ", saving in ", FOLDER
|
||||
if VERBOSE: print ("crawling ", URL, ", saving in ", FOLDER)
|
||||
if not os.path.isdir(FOLDER): os.mkdir(FOLDER)
|
||||
file = open(FOLDER + os.sep + "wiki.css",'wb')
|
||||
file.write(css)
|
||||
@@ -151,16 +151,16 @@ def crawl():
|
||||
for l in lfile: locallist.append(l.replace("\n",""))
|
||||
lfile.close()
|
||||
todolist = locallist[:]
|
||||
print "getting",len(todolist),"files..."
|
||||
print ("getting",len(todolist),"files...")
|
||||
count = 1
|
||||
indexpages = get(INDEX)
|
||||
while todolist:
|
||||
targetpage = todolist.pop()
|
||||
if VERBOSE: print count, ": Fetching ", targetpage
|
||||
if VERBOSE: print (count, ": Fetching ", targetpage)
|
||||
get(targetpage)
|
||||
count += 1
|
||||
if VERBOSE: print "Fetched ", count, " pages"
|
||||
if VERBOSE: print "All done!"
|
||||
if VERBOSE: print ("Fetched ", count, " pages")
|
||||
if VERBOSE: print ("All done!")
|
||||
return 0
|
||||
|
||||
def get(page):
|
||||
@@ -180,7 +180,7 @@ def get(page):
|
||||
html = cleanimagelinks(html)
|
||||
output(html,page)
|
||||
else:
|
||||
if VERBOSE: print " skipping",page
|
||||
if VERBOSE: print (" skipping",page)
|
||||
|
||||
def getlinks(html):
|
||||
"returns a list of wikipage links in html file"
|
||||
@@ -268,7 +268,7 @@ def cleanimagelinks(html,links=None):
|
||||
|
||||
def fetchpage(page):
|
||||
"retrieves given page from the wiki"
|
||||
print " fetching: ",page
|
||||
print (" fetching: ",page)
|
||||
failcount = 0
|
||||
while failcount < MAXFAIL:
|
||||
try:
|
||||
@@ -276,19 +276,19 @@ def fetchpage(page):
|
||||
return html
|
||||
except HTTPError:
|
||||
failcount += 1
|
||||
print 'Error: unable to fetch page ' + page
|
||||
print ('Error: unable to fetch page ' + page)
|
||||
|
||||
def fetchimage(imagelink):
|
||||
"retrieves given image from the wiki and saves it"
|
||||
if imagelink[0:5] == "File:":
|
||||
print "Skipping file page link"
|
||||
print ("Skipping file page link")
|
||||
return
|
||||
filename = re.findall('.*/(.*)',imagelink)[0]
|
||||
if not exists(filename,image=True):
|
||||
failcount = 0
|
||||
while failcount < MAXFAIL:
|
||||
try:
|
||||
if VERBOSE: print " fetching " + filename
|
||||
if VERBOSE: print (" fetching " + filename)
|
||||
data = (urlopen(URL + imagelink).read())
|
||||
path = local(filename,image=True)
|
||||
file = open(path,'wb')
|
||||
@@ -298,11 +298,11 @@ def fetchimage(imagelink):
|
||||
failcount += 1
|
||||
else:
|
||||
processed.append(filename)
|
||||
if VERBOSE: print " saving",local(filename,image=True)
|
||||
if VERBOSE: print (" saving",local(filename,image=True))
|
||||
return
|
||||
print 'Error: unable to fetch file ' + filename
|
||||
print ('Error: unable to fetch file ' + filename)
|
||||
else:
|
||||
if VERBOSE: print " skipping",filename
|
||||
if VERBOSE: print (" skipping",filename)
|
||||
|
||||
def local(page,image=False):
|
||||
"returns a local path for a given page/image"
|
||||
@@ -337,11 +337,11 @@ def output(html,page):
|
||||
filename = filename.replace("&pagefrom=","+")
|
||||
filename = filename.replace("#mw-pages","")
|
||||
filename = filename.replace(".html.html",".html")
|
||||
print " saving",filename
|
||||
print (" saving",filename)
|
||||
file = open(filename,'wb')
|
||||
file.write(html)
|
||||
file.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
crawl()
|
||||
|
||||
crawl()
|
||||
|
||||
|
||||
@@ -618,5 +618,5 @@ def main(arg):
|
||||
|
||||
if __name__ == "__main__":
|
||||
# main(sys.argv[1:])
|
||||
print "Warning! This script is obsolete. Use the scripts in the offlinedocs folder..."
|
||||
print ("Warning! This script is obsolete. Use the scripts in the offlinedocs folder...")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user