From 3e12a59d41dc2af205e2e3891cc07a034eca0755 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 3 Jan 2019 18:11:37 +0100 Subject: [PATCH] fix several Py3 issues --- src/Mod/Arch/importGBXML.py | 2 +- src/Mod/Assembly/DevAssembly.py | 2 +- src/Mod/Path/PathScripts/post/fablin_post.py | 36 +++++++++---------- src/Mod/Path/libarea/kurve/test.py | 2 +- src/Mod/TechDraw/moveViews.py | 12 +++---- src/Tools/ArchiveNameFromVersionHeader.py | 2 +- src/Tools/generateBase/generateDS.py | 28 +++++++-------- .../generateTemplates/templateCPPFile.py | 4 +-- src/Tools/offlinedoc/buildqhelp.py | 26 +++++++------- src/Tools/offlinedoc/buildwikiindex.py | 20 +++++------ src/Tools/offlinedoc/downloadwiki.py | 32 ++++++++--------- src/Tools/wiki2qhelp.py | 2 +- 12 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/Mod/Arch/importGBXML.py b/src/Mod/Arch/importGBXML.py index ef5e5a52f8..573921077e 100644 --- a/src/Mod/Arch/importGBXML.py +++ b/src/Mod/Arch/importGBXML.py @@ -89,7 +89,7 @@ def export(objectslist,filename): # spaces for space in Draft.getObjectsOfType(Draft.getGroupContents(building.Group,addgroups=True),"Space"): if not space.Zone: - FreeCAD.Console.PrintError(translate("Arch","Error: Space '%s' has no Zone. Aborting.")+ "\n" + % space.Label) + FreeCAD.Console.PrintError(translate("Arch","Error: Space '%s' has no Zone. Aborting.") % space.Label + "\n") return filestream.write( ' \n' % (space.Name, space.SpaceType, space.Zone.Name, space.Conditioning) ) #filestream.write( ' %s\n' % space.Name ) # not sure what this is used for? diff --git a/src/Mod/Assembly/DevAssembly.py b/src/Mod/Assembly/DevAssembly.py index e6365961d5..1136573738 100644 --- a/src/Mod/Assembly/DevAssembly.py +++ b/src/Mod/Assembly/DevAssembly.py @@ -1,5 +1,5 @@ import FreeCAD,Assembly,time -print "Script to test the assembly development" +print ("Script to test the assembly development") time.sleep(3) diff --git a/src/Mod/Path/PathScripts/post/fablin_post.py b/src/Mod/Path/PathScripts/post/fablin_post.py index aecd74f55b..c2ee8ca9ed 100644 --- a/src/Mod/Path/PathScripts/post/fablin_post.py +++ b/src/Mod/Path/PathScripts/post/fablin_post.py @@ -1,7 +1,7 @@ #*************************************************************************** -#* (c) imarin 2017 * +#* (c) imarin 2017 * #* * -#* heavily based on gbrl post-procesor by: * +#* heavily based on gbrl post-procesor by: * #* (c) sliptonic (shopinthewoods@gmail.com) 2014 * #* * #* This file is part of the FreeCAD CAx development system. * @@ -116,22 +116,22 @@ def processArguments(argstring): elif arg == '--show-editor': SHOW_EDITOR = True elif arg == '--no-show-editor': - SHOW_EDITOR = False + SHOW_EDITOR = False - params = arg.split('=') + params = arg.split('=') if params[0] == '--rapids-feedrate': - RAPID_FEEDRATE = params[1] + RAPID_FEEDRATE = params[1] def export(objectslist,filename,argstring): processArguments(argstring) global UNITS for obj in objectslist: if not hasattr(obj,"Path"): - print "the object " + obj.Name + " is not a path. Please select only path and Compounds." + print ("the object " + obj.Name + " is not a path. Please select only path and Compounds.") return - print "postprocessing..." + print ("postprocessing...") gcode = "" #Find the machine. @@ -144,7 +144,7 @@ def export(objectslist,filename,argstring): if p.Name == "Machine": myMachine = p if myMachine is None: - print "No machine found in this project" + print ("No machine found in this project") else: if myMachine.MachineUnits == "Metric": UNITS = "G21" @@ -195,7 +195,7 @@ def export(objectslist,filename,argstring): else: final = gcode - print "done postprocessing." + print ("done postprocessing.") gfile = pythonopen(filename,"wb") gfile.write(gcode) @@ -232,13 +232,13 @@ def parse(pathobj): outstring = [] command = c.Name - # fablin does not support parenthesis syntax, so removing that (pocket) in the agnostic gcode - if command[0] == '(': - if not OUTPUT_COMMENTS: pass - else: - outstring.append(command) + # fablin does not support parenthesis syntax, so removing that (pocket) in the agnostic gcode + if command[0] == '(': + if not OUTPUT_COMMENTS: pass + else: + outstring.append(command) - # if modal: only print the command if it is not the same as the last one + # if modal: only print the command if it is not the same as the last one if MODAL == True: if command == lastcommand: outstring.pop(0) @@ -255,8 +255,8 @@ def parse(pathobj): else: outstring.append(param + format(c.Parameters[param], '.4f')) - if command in RAPID_MOVES and command != lastcommand: - outstring.append('F' + format(RAPID_FEEDRATE)) + if command in RAPID_MOVES and command != lastcommand: + outstring.append('F' + format(RAPID_FEEDRATE)) # store the latest command lastcommand = command @@ -292,5 +292,5 @@ def parse(pathobj): return out -print __name__ + " gcode postprocessor loaded." +print (__name__ + " gcode postprocessor loaded.") diff --git a/src/Mod/Path/libarea/kurve/test.py b/src/Mod/Path/libarea/kurve/test.py index a179cd710f..0af6495030 100644 --- a/src/Mod/Path/libarea/kurve/test.py +++ b/src/Mod/Path/libarea/kurve/test.py @@ -6,4 +6,4 @@ m = area.Matrix([1,0,0,12, 0,1,0,0, 0,0,1,0, 0,0,0,1]) p.Transform(m) -print p.x, p.y \ No newline at end of file +print (p.x, p.y) diff --git a/src/Mod/TechDraw/moveViews.py b/src/Mod/TechDraw/moveViews.py index 4c8d680af1..2fab352f77 100644 --- a/src/Mod/TechDraw/moveViews.py +++ b/src/Mod/TechDraw/moveViews.py @@ -18,11 +18,11 @@ def moveViews(): s = FreeCADGui.Selection.getSelection() if len(s) != 2: - print "Please select 1 Drawing Page and 1 TechDraw Page" + print ("Please select 1 Drawing Page and 1 TechDraw Page") return - print "First object in selection is a: ", s[0].TypeId - print "Second object in selection is a: ", s[1].TypeId + print ("First object in selection is a: ", s[0].TypeId) + print ("Second object in selection is a: ", s[1].TypeId) if s[0].isDerivedFrom("Drawing::FeaturePage") and \ s[1].isDerivedFrom("TechDraw::DrawPage"): dPage = s[0] @@ -32,20 +32,20 @@ def moveViews(): tPage = s[0] dPage = s[1] else: - print "Please select 1 Drawing Page and 1 TechDraw Page" + print ("Please select 1 Drawing Page and 1 TechDraw Page") return i = 1 for o in dPage.OutList: newName = "DraftView" + str(i).zfill(3) - print "moving " + o.Name + " to " + newName + print ("moving " + o.Name + " to " + newName) svg = svgHead + o.ViewResult + svgTail no = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol',newName) no.Symbol = svg tPage.addView(no) i += 1 - print "moveViews moved " + str(i-1) + " views" + print ("moveViews moved " + str(i-1) + " views") if __name__ == '__main__': moveViews() diff --git a/src/Tools/ArchiveNameFromVersionHeader.py b/src/Tools/ArchiveNameFromVersionHeader.py index a2e2d993b3..142094a980 100644 --- a/src/Tools/ArchiveNameFromVersionHeader.py +++ b/src/Tools/ArchiveNameFromVersionHeader.py @@ -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 diff --git a/src/Tools/generateBase/generateDS.py b/src/Tools/generateBase/generateDS.py index 1890209547..e6e10d5ad5 100644 --- a/src/Tools/generateBase/generateDS.py +++ b/src/Tools/generateBase/generateDS.py @@ -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() diff --git a/src/Tools/generateTemplates/templateCPPFile.py b/src/Tools/generateTemplates/templateCPPFile.py index 33b0c89905..227618d825 100644 --- a/src/Tools/generateTemplates/templateCPPFile.py +++ b/src/Tools/generateTemplates/templateCPPFile.py @@ -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" -""" \ No newline at end of file +""" diff --git a/src/Tools/offlinedoc/buildqhelp.py b/src/Tools/offlinedoc/buildqhelp.py index 0310a54821..e09a7190d2 100755 --- a/src/Tools/offlinedoc/buildqhelp.py +++ b/src/Tools/offlinedoc/buildqhelp.py @@ -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(): ''' - 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() + diff --git a/src/Tools/offlinedoc/buildwikiindex.py b/src/Tools/offlinedoc/buildwikiindex.py index 933b63d701..a3ea893055 100755 --- a/src/Tools/offlinedoc/buildwikiindex.py +++ b/src/Tools/offlinedoc/buildwikiindex.py @@ -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:]) diff --git a/src/Tools/offlinedoc/downloadwiki.py b/src/Tools/offlinedoc/downloadwiki.py index f48c319d56..95fc813f19 100755 --- a/src/Tools/offlinedoc/downloadwiki.py +++ b/src/Tools/offlinedoc/downloadwiki.py @@ -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() + diff --git a/src/Tools/wiki2qhelp.py b/src/Tools/wiki2qhelp.py index 00b6de91d1..1ee865dac9 100755 --- a/src/Tools/wiki2qhelp.py +++ b/src/Tools/wiki2qhelp.py @@ -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...")