diff --git a/src/Tools/ArchiveNameFromVersionHeader.py b/src/Tools/ArchiveNameFromVersionHeader.py index 51455228ff..a2e2d993b3 100644 --- a/src/Tools/ArchiveNameFromVersionHeader.py +++ b/src/Tools/ArchiveNameFromVersionHeader.py @@ -10,7 +10,7 @@ def deserializeVersionHeader(path): try: dat = open(path, 'r').readlines() except IOError: - print 'Unable to open ', path + print('Unable to open ', path) raise for l in dat: @@ -40,13 +40,13 @@ def main(): if SHA: version['FCRepositoryHash'] = SHA - print 'FreeCAD_{Major}.{Minor}-{RevCount}.{GitShortSHA}-{OS}-{Arch}'.format( + print('FreeCAD_{Major}.{Minor}-{RevCount}.{GitShortSHA}-{OS}-{Arch}'.format( Major=version['FCVersionMajor'], Minor=version['FCVersionMinor'], RevCount=version['FCRevision'], GitShortSHA=version['FCRepositoryHash'][0:7], OS=OSAbbrev.get(platform.system(), 'LIN'), - Arch=platform.machine()) + Arch=platform.machine())) if __name__ == "__main__": main() diff --git a/src/Tools/DistTools.py b/src/Tools/DistTools.py index 695c745d90..14468a7bc3 100644 --- a/src/Tools/DistTools.py +++ b/src/Tools/DistTools.py @@ -35,26 +35,26 @@ def cpall(dirFrom, dirTo): """ global dcount, fcount for file in os.listdir(dirFrom): # for files/dirs here - print file + print(file) pathFrom = os.path.join(dirFrom, file) pathTo = os.path.join(dirTo, file) # extend both paths if not os.path.isdir(pathFrom): # copy simple files try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo + if verbose > 1: print('copying', pathFrom, 'to', pathTo) cpfile(pathFrom, pathTo) fcount = fcount+1 except: - print 'Error copying', pathFrom, to, pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error copying', pathFrom, to, pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) else: - if verbose: print 'copying dir', pathFrom, 'to', pathTo + if verbose: print ('copying dir', pathFrom, 'to', pathTo) try: os.mkdir(pathTo) # make new subdir cpall(pathFrom, pathTo) # recur into subdirs dcount = dcount+1 except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error creating', pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) def SetUpFilter(MatchList): RegList = [] @@ -73,27 +73,27 @@ def cpallWithFilter(dirFrom, dirTo,MatchList): for matchpat in MatchList: if(re.match(matchpat,file)): hitt = 1 - print 'Refuse: '+file + print('Refuse: '+file) if hitt == 0: pathFrom = os.path.join(dirFrom, file) pathTo = os.path.join(dirTo, file) # extend both paths if not os.path.isdir(pathFrom): # copy simple files try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo + if verbose > 1: print('copying', pathFrom, 'to', pathTo) cpfile(pathFrom, pathTo) fcount = fcount+1 except: - print 'Error copying', pathFrom, to, pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error copying', pathFrom, to, pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) else: - if verbose: print 'copying dir', pathFrom, 'to', pathTo + if verbose: print('copying dir', pathFrom, 'to', pathTo) try: os.mkdir(pathTo) # make new subdir cpallWithFilter(pathFrom, pathTo,MatchList) # recur into subdirs dcount = dcount+1 except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error creating', pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) ################################################################ # Use: "python rmall.py directoryPath directoryPath..." diff --git a/src/Tools/FCFileTools.py b/src/Tools/FCFileTools.py index 498ec9f3c4..961efdc084 100644 --- a/src/Tools/FCFileTools.py +++ b/src/Tools/FCFileTools.py @@ -1,120 +1,120 @@ - - -# shell and operating system -import os, sys, re -verbose = 0 -dcount = fcount = 0 -maxfileload = 100000 -blksize = 1024 * 8 - -def cpfile(pathFrom, pathTo, maxfileload=maxfileload): - """ - copy file pathFrom to pathTo, byte for byte - """ - if os.path.getsize(pathFrom) <= maxfileload: - bytesFrom = open(pathFrom, 'rb').read() # read small file all at once - bytesTo = open(pathTo, 'wb') - bytesTo.write(bytesFrom) # need b mode on Windows - #bytesTo.close() - #bytesFrom.close() - else: - fileFrom = open(pathFrom, 'rb') # read big files in chunks - fileTo = open(pathTo, 'wb') # need b mode here too - while 1: - bytesFrom = fileFrom.read(blksize) # get one block, less at end - if not bytesFrom: break # empty after last chunk - fileTo.write(bytesFrom) - #fileFrom.close() - #fileTo.close() - - - -def cpall(dirFrom, dirTo): - """ - copy contents of dirFrom and below to dirTo - """ - global dcount, fcount - for file in os.listdir(dirFrom): # for files/dirs here - print file - pathFrom = os.path.join(dirFrom, file) - pathTo = os.path.join(dirTo, file) # extend both paths - if not os.path.isdir(pathFrom): # copy simple files - try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo - cpfile(pathFrom, pathTo) - fcount = fcount+1 - except: - print 'Error copying', pathFrom, to, pathTo, '--skipped' - print sys.exc_type, sys.exc_value - else: - if verbose: print 'copying dir', pathFrom, 'to', pathTo - try: - os.mkdir(pathTo) # make new subdir - cpall(pathFrom, pathTo) # recur into subdirs - dcount = dcount+1 - except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value - -def SetUpFilter(MatchList): - RegList = [] - for regexp in MatchList: - a = re.compile(regexp) - RegList.append(a) - return RegList - -def cpallWithFilter(dirFrom, dirTo,MatchList): - """ - copy contents of dirFrom and below to dirTo without match - """ - global dcount, fcount - for file in os.listdir(dirFrom): # for files/dirs here - hitt = 0 - for matchpat in MatchList: - if(re.match(matchpat,file)): - hitt = 1 - print 'Refuse: '+file - if hitt == 0: - pathFrom = os.path.join(dirFrom, file) - pathTo = os.path.join(dirTo, file) # extend both paths - if not os.path.isdir(pathFrom): # copy simple files - try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo - cpfile(pathFrom, pathTo) - fcount = fcount+1 - except: - print 'Error copying', pathFrom, to, pathTo, '--skipped' - print sys.exc_type, sys.exc_value - else: - if verbose: print 'copying dir', pathFrom, 'to', pathTo - try: - os.mkdir(pathTo) # make new subdir - cpallWithFilter(pathFrom, pathTo,MatchList) # recur into subdirs - dcount = dcount+1 - except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value - -################################################################ -# Use: "python rmall.py directoryPath directoryPath..." -# recursive directory tree deletion: removes all files and -# directories at and below directoryPaths; recurs into subdirs -# and removes parent dir last, because os.rmdir requires that -# directory is empty; like a Unix "rm -rf directoryPath" -################################################################ - -fcount = dcount = 0 - -def rmall(dirPath): # delete dirPath and below - global fcount, dcount - namesHere = os.listdir(dirPath) - for name in namesHere: # remove all contents first - path = os.path.join(dirPath, name) - if not os.path.isdir(path): # remove simple files - os.remove(path) - fcount = fcount + 1 - else: # recur to remove subdirs - rmall(path) - os.rmdir(dirPath) # remove now-empty dirPath - dcount = dcount + 1 - + + +# shell and operating system +import os, sys, re +verbose = 0 +dcount = fcount = 0 +maxfileload = 100000 +blksize = 1024 * 8 + +def cpfile(pathFrom, pathTo, maxfileload=maxfileload): + """ + copy file pathFrom to pathTo, byte for byte + """ + if os.path.getsize(pathFrom) <= maxfileload: + bytesFrom = open(pathFrom, 'rb').read() # read small file all at once + bytesTo = open(pathTo, 'wb') + bytesTo.write(bytesFrom) # need b mode on Windows + #bytesTo.close() + #bytesFrom.close() + else: + fileFrom = open(pathFrom, 'rb') # read big files in chunks + fileTo = open(pathTo, 'wb') # need b mode here too + while 1: + bytesFrom = fileFrom.read(blksize) # get one block, less at end + if not bytesFrom: break # empty after last chunk + fileTo.write(bytesFrom) + #fileFrom.close() + #fileTo.close() + + + +def cpall(dirFrom, dirTo): + """ + copy contents of dirFrom and below to dirTo + """ + global dcount, fcount + for file in os.listdir(dirFrom): # for files/dirs here + print(file) + pathFrom = os.path.join(dirFrom, file) + pathTo = os.path.join(dirTo, file) # extend both paths + if not os.path.isdir(pathFrom): # copy simple files + try: + if verbose > 1: print('copying', pathFrom, 'to', pathTo) + cpfile(pathFrom, pathTo) + fcount = fcount+1 + except: + print('Error copying', pathFrom, to, pathTo, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + else: + if verbose: print('copying dir', pathFrom, 'to', pathTo) + try: + os.mkdir(pathTo) # make new subdir + cpall(pathFrom, pathTo) # recur into subdirs + dcount = dcount+1 + except: + print('Error creating', pathTo, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + +def SetUpFilter(MatchList): + RegList = [] + for regexp in MatchList: + a = re.compile(regexp) + RegList.append(a) + return RegList + +def cpallWithFilter(dirFrom, dirTo,MatchList): + """ + copy contents of dirFrom and below to dirTo without match + """ + global dcount, fcount + for file in os.listdir(dirFrom): # for files/dirs here + hitt = 0 + for matchpat in MatchList: + if(re.match(matchpat,file)): + hitt = 1 + print('Refuse: '+file) + if hitt == 0: + pathFrom = os.path.join(dirFrom, file) + pathTo = os.path.join(dirTo, file) # extend both paths + if not os.path.isdir(pathFrom): # copy simple files + try: + if verbose > 1: print('copying', pathFrom, 'to', pathTo) + cpfile(pathFrom, pathTo) + fcount = fcount+1 + except: + print('Error copying', pathFrom, to, pathTo, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + else: + if verbose: print('copying dir', pathFrom, 'to', pathTo) + try: + os.mkdir(pathTo) # make new subdir + cpallWithFilter(pathFrom, pathTo,MatchList) # recur into subdirs + dcount = dcount+1 + except: + print('Error creating', pathTo, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + +################################################################ +# Use: "python rmall.py directoryPath directoryPath..." +# recursive directory tree deletion: removes all files and +# directories at and below directoryPaths; recurs into subdirs +# and removes parent dir last, because os.rmdir requires that +# directory is empty; like a Unix "rm -rf directoryPath" +################################################################ + +fcount = dcount = 0 + +def rmall(dirPath): # delete dirPath and below + global fcount, dcount + namesHere = os.listdir(dirPath) + for name in namesHere: # remove all contents first + path = os.path.join(dirPath, name) + if not os.path.isdir(path): # remove simple files + os.remove(path) + fcount = fcount + 1 + else: # recur to remove subdirs + rmall(path) + os.rmdir(dirPath) # remove now-empty dirPath + dcount = dcount + 1 + diff --git a/src/Tools/MakeAppTools.py b/src/Tools/MakeAppTools.py index 5c51b159ae..31b8ee2d03 100644 --- a/src/Tools/MakeAppTools.py +++ b/src/Tools/MakeAppTools.py @@ -1,77 +1,77 @@ -import os, sys, re,string,FCFileTools -verbose = 0 -dcount = fcount = 0 - -def replaceTemplate(dirName, oldName, newName): - """ - modify contents from dirName and below, replace oldName by newName - """ - for file in os.listdir(dirName): - pathName = os.path.join(dirName, file) - if not os.path.isdir(pathName): - try: - print pathName - origFile = open(pathName) # open file - lines = origFile.readlines() # read the file... - origFile.close() # ... and close it - output = open(pathName,"w") # open the file again - for line in lines: - if (string.find(line, oldName) != -1): # search for 'oldName' and replace it - line = string.replace(line, oldName, newName) - output.write(line) # write the modified line back - output.close # close the file - except: - print 'Error modifying', pathName, '--skipped' - print sys.exc_type, sys.exc_value - else: - try: - replaceTemplate(pathName, oldName, newName) - except: - print 'Error changing to directory', pathName, '--skipped' - print sys.exc_type, sys.exc_value - - -def copyTemplate(dirFrom, dirTo, oldName, newName, MatchFile, MatchDir): - """ - copy contents of dirFrom and below to dirTo - """ - global dcount, fcount - for file in os.listdir(dirFrom): # for files/dirs here - print file - pathFrom = os.path.join(dirFrom, file) - pathTo = os.path.join(dirTo, file) # extend both paths - if (string.find(pathTo, oldName) != -1): - pathTo = string.replace(pathTo, oldName, newName) # rename file if 'oldName' is found - if not os.path.isdir(pathFrom): # copy simple files - hit = 0 - for matchpat in MatchFile: - if(re.match(matchpat,file)): - hit = 1 - break - if hit: - print 'Ignore file '+file - continue - try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo - FCFileTools.cpfile(pathFrom, pathTo) - fcount = fcount+1 - except: - print 'Error copying', pathFrom, 'to', pathTo, '--skipped' - print sys.exc_type, sys.exc_value - else: - hit = 0 - for matchpat in MatchDir: - if(re.match(matchpat,file)): - hit = 1 - break - if hit: - print 'Ignore directory '+file - continue - if verbose: print 'copying dir', pathFrom, 'to', pathTo - try: - os.mkdir(pathTo) # make new subdir - copyTemplate(pathFrom, pathTo, oldName, newName, MatchFile, MatchDir) # recur into subdirs - dcount = dcount+1 - except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value +import os, sys, re,string,FCFileTools +verbose = 0 +dcount = fcount = 0 + +def replaceTemplate(dirName, oldName, newName): + """ + modify contents from dirName and below, replace oldName by newName + """ + for file in os.listdir(dirName): + pathName = os.path.join(dirName, file) + if not os.path.isdir(pathName): + try: + print(pathName) + origFile = open(pathName) # open file + lines = origFile.readlines() # read the file... + origFile.close() # ... and close it + output = open(pathName,"w") # open the file again + for line in lines: + if (string.find(line, oldName) != -1): # search for 'oldName' and replace it + line = string.replace(line, oldName, newName) + output.write(line) # write the modified line back + output.close # close the file + except: + print('Error modifying', pathName, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + else: + try: + replaceTemplate(pathName, oldName, newName) + except: + print('Error changing to directory', pathName, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + + +def copyTemplate(dirFrom, dirTo, oldName, newName, MatchFile, MatchDir): + """ + copy contents of dirFrom and below to dirTo + """ + global dcount, fcount + for file in os.listdir(dirFrom): # for files/dirs here + print(file) + pathFrom = os.path.join(dirFrom, file) + pathTo = os.path.join(dirTo, file) # extend both paths + if (string.find(pathTo, oldName) != -1): + pathTo = string.replace(pathTo, oldName, newName) # rename file if 'oldName' is found + if not os.path.isdir(pathFrom): # copy simple files + hit = 0 + for matchpat in MatchFile: + if(re.match(matchpat,file)): + hit = 1 + break + if hit: + print('Ignore file '+file) + continue + try: + if verbose > 1: print('copying', pathFrom, 'to', pathTo) + FCFileTools.cpfile(pathFrom, pathTo) + fcount = fcount+1 + except: + print('Error copying', pathFrom, 'to', pathTo, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + else: + hit = 0 + for matchpat in MatchDir: + if(re.match(matchpat,file)): + hit = 1 + break + if hit: + print('Ignore directory '+file) + continue + if verbose: print('copying dir', pathFrom, 'to', pathTo) + try: + os.mkdir(pathTo) # make new subdir + copyTemplate(pathFrom, pathTo, oldName, newName, MatchFile, MatchDir) # recur into subdirs + dcount = dcount+1 + except: + print('Error creating', pathTo, '--skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) diff --git a/src/Tools/MakeMacBundleRelocatable.py b/src/Tools/MakeMacBundleRelocatable.py index e6c7b52e00..26e43b9d2f 100755 --- a/src/Tools/MakeMacBundleRelocatable.py +++ b/src/Tools/MakeMacBundleRelocatable.py @@ -353,7 +353,7 @@ def print_node(graph, node, path): def main(): if len(sys.argv) < 2: - print "Usage " + sys.argv[0] + " path [additional search paths]" + print("Usage " + sys.argv[0] + " path [additional search paths]") quit() path = sys.argv[1] diff --git a/src/Tools/MakeNewBuildNbr.py b/src/Tools/MakeNewBuildNbr.py index fa38a583bb..9dc1fb90e6 100644 --- a/src/Tools/MakeNewBuildNbr.py +++ b/src/Tools/MakeNewBuildNbr.py @@ -36,8 +36,8 @@ import time BuildNumber = int(FCVersionBuild[23:-1]) +1 # writing new Version.h File -open("../Version.h",'w').writelines([FCVersionMajor,FCVersionMinor,FCVersionBuild[:23]+`BuildNumber`+'\n',FCVersionDisDa[:23]+ '"'+time.asctime()+'"']) +open("../Version.h",'w').writelines([FCVersionMajor,FCVersionMinor,FCVersionBuild[:23]+str(BuildNumber)+'\n',FCVersionDisDa[:23]+ '"'+time.asctime()+'"']) # writing the ChangeLog.txt -open("../ChangeLog.txt",'a').write("\nVersion: V"+FCVersionMajor[23:-1]+"."+FCVersionMinor[23:-1]+"B"+`BuildNumber`+" Date: "+time.asctime()+' +++++++++++++++++++++++++++++++\n') +open("../ChangeLog.txt",'a').write("\nVersion: V"+FCVersionMajor[23:-1]+"."+FCVersionMinor[23:-1]+"B"+str(BuildNumber)+" Date: "+time.asctime()+' +++++++++++++++++++++++++++++++\n') diff --git a/src/Tools/WinVersion.py b/src/Tools/WinVersion.py index 48884686a9..c75e6cc6bd 100644 --- a/src/Tools/WinVersion.py +++ b/src/Tools/WinVersion.py @@ -1,49 +1,49 @@ -#! python -# -*- coding: utf-8 -*- -# (c) 2012 Juergen Riegel LGPL -# -# Script to create files used in Windows build -# uses SubWCRev.py for version detection# - -import SubWCRev,getopt,sys,string - -def main(): - - input="" - output="." - dir="." - - try: - opts, args = getopt.getopt(sys.argv[1:], "dso:", ["dir=","src=","out="]) - except getopt.GetoptError: - pass - - for o, a in opts: - if o in ("-d", "--dir"): - dir = a - if o in ("-s", "--src"): - input = a - if o in ("-o", "--out"): - output = a - git = SubWCRev.GitControl() - - if(git.extractInfo(input)): - print git.hash - print git.branch - print git.rev[0:4] - print git.date - print git.url - print input - print output - - f = open(input,'r') - o = open(output,'w') - for line in f.readlines(): - line = string.replace(line,'$WCREV$',git.rev[0:4]) - line = string.replace(line,'$WCDATE$',git.date) - line = string.replace(line,'$WCURL$',git.url) - o.write(line) - - -if __name__ == "__main__": - main() +#! python +# -*- coding: utf-8 -*- +# (c) 2012 Juergen Riegel LGPL +# +# Script to create files used in Windows build +# uses SubWCRev.py for version detection# + +import SubWCRev,getopt,sys,string + +def main(): + + input="" + output="." + dir="." + + try: + opts, args = getopt.getopt(sys.argv[1:], "dso:", ["dir=","src=","out="]) + except getopt.GetoptError: + pass + + for o, a in opts: + if o in ("-d", "--dir"): + dir = a + if o in ("-s", "--src"): + input = a + if o in ("-o", "--out"): + output = a + git = SubWCRev.GitControl() + + if(git.extractInfo(input)): + print(git.hash) + print(git.branch) + print(git.rev[0:4]) + print(git.date) + print(git.url) + print(input) + print(output) + + f = open(input,'r') + o = open(output,'w') + for line in f.readlines(): + line = string.replace(line,'$WCREV$',git.rev[0:4]) + line = string.replace(line,'$WCDATE$',git.date) + line = string.replace(line,'$WCURL$',git.url) + o.write(line) + + +if __name__ == "__main__": + main() diff --git a/src/Tools/dir2qrc.py b/src/Tools/dir2qrc.py index ed7eb2d546..1f7680f526 100644 --- a/src/Tools/dir2qrc.py +++ b/src/Tools/dir2qrc.py @@ -47,24 +47,24 @@ hhcFooter=""" """ EndingList = ['.xpm','.svg','.qm','.png','.ui'] - -locations = [["../Gui/Language","translation.qrc"," prefix=\"/translations\""], - ["../Gui/Icons","resource.qrc"," prefix=\"/icons\""], - ["../Mod/Assembly/Gui/Resources","Assembly.qrc"], - ["../Mod/Complete/Gui/Resources","Complete.qrc"], - ["../Mod/Draft/Resources","Draft.qrc"], - ["../Mod/Drawing/Gui/Resources","Drawing.qrc"], - ["../Mod/Fem/Gui/Resources","Fem.qrc"], - ["../Mod/Image/Gui/Resources","Image.qrc"], - ["../Mod/Mesh/Gui/Resources","Mesh.qrc"], - ["../Mod/MeshPart/Gui/Resources","MeshPart.qrc"], - ["../Mod/Part/Gui/Resources","Part.qrc"], - ["../Mod/PartDesign/Gui/Resources","PartDesign.qrc"], - ["../Mod/Points/Gui/Resources","Points.qrc"], - ["../Mod/Raytracing/Gui/Resources","Raytracing.qrc"], - ["../Mod/ReverseEngineering/Gui/Resources","ReverseEngineering.qrc"], - ["../Mod/Robot/Gui/Resources","Robot.qrc"], - ["../Mod/Sketcher/Gui/Resources","Sketcher.qrc"]] + +locations = [["../Gui/Language","translation.qrc"," prefix=\"/translations\""], + ["../Gui/Icons","resource.qrc"," prefix=\"/icons\""], + ["../Mod/Assembly/Gui/Resources","Assembly.qrc"], + ["../Mod/Complete/Gui/Resources","Complete.qrc"], + ["../Mod/Draft/Resources","Draft.qrc"], + ["../Mod/Drawing/Gui/Resources","Drawing.qrc"], + ["../Mod/Fem/Gui/Resources","Fem.qrc"], + ["../Mod/Image/Gui/Resources","Image.qrc"], + ["../Mod/Mesh/Gui/Resources","Mesh.qrc"], + ["../Mod/MeshPart/Gui/Resources","MeshPart.qrc"], + ["../Mod/Part/Gui/Resources","Part.qrc"], + ["../Mod/PartDesign/Gui/Resources","PartDesign.qrc"], + ["../Mod/Points/Gui/Resources","Points.qrc"], + ["../Mod/Raytracing/Gui/Resources","Raytracing.qrc"], + ["../Mod/ReverseEngineering/Gui/Resources","ReverseEngineering.qrc"], + ["../Mod/Robot/Gui/Resources","Robot.qrc"], + ["../Mod/Sketcher/Gui/Resources","Sketcher.qrc"]] def main(): global Verbose,Automatic,ExtraDist,Dir,Output @@ -90,7 +90,7 @@ def main(): if o in ("-o", "--out-file"): Output = a if o in ("-d", "--directory"): - print "Using path: " + a +"\n" + print("Using path: " + a +"\n") Dir = a if Automatic: @@ -123,7 +123,7 @@ def updateResourceFile(Dir, Output,prefix=""): FilePath = FilePathOrg.replace(DirPath,'') FilePath = FilePath.replace('.\\','') FilePath = FilePath.replace('\\','/') - if Verbose: print FilePathOrg + ' -> ' + FilePath + if Verbose: print(FilePathOrg + ' -> ' + FilePath) filelist.append(FilePath) @@ -139,7 +139,7 @@ def makeTargetExtraDist(Dir): extensions.append(".qrc") extensions.append(".bat") extensions.append(".ts") - print ("EXTRA_DIST = \\") + print("EXTRA_DIST = \\") DirPath = Dir + os.path.sep for root, dirs, files in os.walk(Dir): for name in files: @@ -148,8 +148,8 @@ def makeTargetExtraDist(Dir): FilePath = FilePathOrg.replace(DirPath,'') FilePath = FilePath.replace('.\\','') FilePath = FilePath.replace('\\','/') - print ("\t\t%s \\" % (FilePath)) - print + print("\t\t%s \\" % (FilePath)) + print() if __name__ == "__main__": main() diff --git a/src/Tools/fcbt.py b/src/Tools/fcbt.py index 8c0a5bf575..e4652189a2 100644 --- a/src/Tools/fcbt.py +++ b/src/Tools/fcbt.py @@ -55,7 +55,7 @@ elif Cmd == "createpymodule" or Cmd == "cp": elif Cmd == "?" or Cmd == "help" or Cmd == "/h" or Cmd == "/?" or Cmd == "-h" or Cmd == "-help": sys.stdout.write(help1) else: - print CmdRaw + " is an unknown command!\n" + print(CmdRaw + " is an unknown command!\n") sys.exit(1) diff --git a/src/Tools/fcbt/BuildDoc.py b/src/Tools/fcbt/BuildDoc.py index 3a6f1927e3..71e2a9c519 100644 --- a/src/Tools/fcbt/BuildDoc.py +++ b/src/Tools/fcbt/BuildDoc.py @@ -29,7 +29,7 @@ sys.stdout.write ('Running source documentation ...') # running doxygen with the parameters from the config file param = "doxygen fcbt"+ds+"BuildDocDoxy.cfg" LogFile.write(param) -print param +print(param) text = os.popen(param).read() LogFile.write(text) if not os.path.isdir("../../doc/SourceDocumentation"): diff --git a/src/Tools/fcbt/FileTools.py b/src/Tools/fcbt/FileTools.py index 40288dae3d..21607e22c7 100644 --- a/src/Tools/fcbt/FileTools.py +++ b/src/Tools/fcbt/FileTools.py @@ -40,21 +40,21 @@ def cpall(dirFrom, dirTo): pathTo = os.path.join(dirTo, file) # extend both paths if not os.path.isdir(pathFrom): # copy simple files try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo + if verbose > 1: print('copying', pathFrom, 'to', pathTo) cpfile(pathFrom, pathTo) fcount = fcount+1 except: - print 'Error copying', pathFrom, to, pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error copying', pathFrom, to, pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) else: - if verbose: print 'copying dir', pathFrom, 'to', pathTo + if verbose: print('copying dir', pathFrom, 'to', pathTo) try: os.mkdir(pathTo) # make new subdir cpall(pathFrom, pathTo) # recur into subdirs dcount = dcount+1 except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error creating', pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) def SetUpFilter(MatchList): RegList = [] @@ -79,21 +79,21 @@ def cpallWithFilter(dirFrom, dirTo,MatchList): pathTo = os.path.join(dirTo, file) # extend both paths if not os.path.isdir(pathFrom): # copy simple files try: - if verbose > 1: print 'copying', pathFrom, 'to', pathTo + if verbose > 1: print('copying', pathFrom, 'to', pathTo) cpfile(pathFrom, pathTo) fcount = fcount+1 except: - print 'Error copying', pathFrom, to, pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error copying', pathFrom, to, pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) else: - if verbose: print 'copying dir', pathFrom, 'to', pathTo + if verbose: print('copying dir', pathFrom, 'to', pathTo) try: os.mkdir(pathTo) # make new subdir cpallWithFilter(pathFrom, pathTo,MatchList) # recur into subdirs dcount = dcount+1 except: - print 'Error creating', pathTo, '--skipped' - print sys.exc_type, sys.exc_value + print('Error creating', pathTo, '--skipped') + print(sys.exc_type, sys.exc_value) ################################################################ # Use: "python rmall.py directoryPath directoryPath..." diff --git a/src/Tools/fcbt/NextBuildNumber.py b/src/Tools/fcbt/NextBuildNumber.py index a4c0bf2a8b..34b0832784 100644 --- a/src/Tools/fcbt/NextBuildNumber.py +++ b/src/Tools/fcbt/NextBuildNumber.py @@ -35,23 +35,24 @@ import time # increasing build number BuildNumber = int(FCVersionBuild[23:-1]) +1 -print "New Buildnumber is:" -print BuildNumber -print "\n" +print("New Buildnumber is:") +print(BuildNumber) +print("\n") # writing new Version.h File open("../Version.h",'w').writelines([FCVersionMajor, FCVersionMinor, - FCVersionBuild[:23]+`BuildNumber`+'\n', + FCVersionBuild[:23]+str(BuildNumber)+'\n', FCVersionDisDa[:23]+ '"'+time.asctime()+'" \n\n']) # writing the ChangeLog.txt -open("../ChangeLog.txt",'a').write("\nVersion: V"+FCVersionMajor[23:-1]+"."+FCVersionMinor[23:-1]+"B"+`BuildNumber`+" Date: "+time.asctime()+' +++++++++++++++++++++++++++++++\n') +open("../ChangeLog.txt",'a').write("\nVersion: V"+FCVersionMajor[23:-1]+"."+FCVersionMinor[23:-1]+"B"+ + str(BuildNumber)+" Date: "+time.asctime()+' +++++++++++++++++++++++++++++++\n') # writing new Version.wxi File open("../Version.wxi",'w').writelines(["\n", " \n", " \n", - " \n", + " \n", " \n"]) diff --git a/src/Tools/githubstats.py b/src/Tools/githubstats.py index 694d8c9b0e..64a1f8dc8f 100755 --- a/src/Tools/githubstats.py +++ b/src/Tools/githubstats.py @@ -1,6 +1,6 @@ #!/usr/bin/python -print "Fetching download statistics from github..." +print("Fetching download statistics from github...") import requests r=requests.get('https://api.github.com/repos/FreeCAD/FreeCAD/releases') @@ -8,4 +8,4 @@ myobj = r.json() for p in myobj: if "assets" in p: for asset in p['assets']: - print (asset['name'] + ": " + str(asset['download_count']) + " downloads") + print((asset['name'] + ": " + str(asset['download_count']) + " downloads")) diff --git a/src/Tools/makedist.py b/src/Tools/makedist.py index 3a9b79e19f..8e02d13d24 100644 --- a/src/Tools/makedist.py +++ b/src/Tools/makedist.py @@ -5,7 +5,7 @@ # Python script to make source tarballs. # -import sys, os, getopt, tarfile, gzip, time, StringIO, platform, shutil +import sys, os, getopt, tarfile, gzip, time, io, platform, shutil def main(): srcdir="." @@ -43,7 +43,7 @@ def main(): revision='%04d' % (info.count('\n')) verfile = open("%s/src/Build/Version.h" % (bindir), 'r') - verstream = StringIO.StringIO(verfile.read()) + verstream = io.StringIO(verfile.read()) verfile.close() version_minor = verstream.getvalue().split('FCVersionMinor "')[1][:2] @@ -58,11 +58,11 @@ def main(): TGZNAME = DIRNAME + '-dfsg.tar.gz' verinfo = tarfile.TarInfo(DIRNAME + "/src/Build/Version.h") - verinfo.mode = 0660 + verinfo.mode = 0o660 verinfo.size = len(verstream.getvalue()) verinfo.mtime = time.time() - print "git archive %s --prefix=%s/ HEAD" % (wta, DIRNAME) + print(("git archive %s --prefix=%s/ HEAD" % (wta, DIRNAME))) if platform.system() == 'Windows': os.popen("git archive %s --prefix=%s/ --output=%s HEAD" % (wta, DIRNAME, TARNAME)).read() @@ -80,7 +80,7 @@ def main(): else: tardata = os.popen("git archive %s --prefix=%s/ HEAD" % (wta, DIRNAME)).read() - tarstream = StringIO.StringIO(tardata) + tarstream = io.StringIO(tardata) tar = tarfile.TarFile(mode="a", fileobj=tarstream) tar.addfile(verinfo, verstream) @@ -92,7 +92,7 @@ def main(): if dfsg: os.remove("src/.gitattributes") - print "Created " + TGZNAME + print(("Created " + TGZNAME)) # Unpack and build if check: archive=tarfile.open(mode='r:gz',name=TGZNAME) diff --git a/src/Tools/offlinedoc/buildpdf.py b/src/Tools/offlinedoc/buildpdf.py index 18e83f926e..825337d520 100755 --- a/src/Tools/offlinedoc/buildpdf.py +++ b/src/Tools/offlinedoc/buildpdf.py @@ -331,7 +331,8 @@ Embedding_FreeCADGui Code_snippets""" import sys, os, re, tempfile, getopt, shutil, time -from urllib2 import urlopen, HTTPError +from urllib.request import urlopen +from urllib.error import HTTPError # CONFIGURATION ################################################# @@ -363,19 +364,19 @@ def crawl(): return 1 elif PDFCONVERTOR == 'htmldoc': if os.system('htmldoc --version'): - print "Error: Htmldoc not found, exiting." + print("Error: Htmldoc not found, exiting.") return 1 try: from PyPDF2 import PdfFileReader,PdfFileWriter except: - print "Error: Python-pypdf2 not installed, exiting." + print("Error: Python-pypdf2 not installed, exiting.") # run ######################################################## buildpdffiles() joinpdf() - if VERBOSE: print "All done!" + if VERBOSE: print("All done!") return 0 @@ -389,10 +390,10 @@ def buildpdffiles(): for i in templist: if i[-5:] == '.html': fileslist.append(i) - print "converting ",len(fileslist)," pages" + print("converting ",len(fileslist)," pages") i = 1 for f in fileslist: - print i," : ",f + print(i," : ",f) if PDFCONVERTOR == 'pisa': createpdf_pisa(f[:-5]) elif PDFCONVERTOR == 'wkhtmltopdf': @@ -421,7 +422,7 @@ def createpdf_pisa(pagename): if (not exists(pagename+".pdf",image=True)) or OVERWRTIE: infile = open(FOLDER + os.sep + pagename+'.html','ro') outfile = open(FOLDER + os.sep + pagename+'.pdf','wb') - if VERBOSE: print "Converting " + pagename + " to pdf..." + if VERBOSE: print("Converting " + pagename + " to pdf...") pdf = pisa.CreatePDF(infile,outfile,FOLDER,link_callback=fetch_resources) outfile.close() if pdf.err: @@ -441,7 +442,7 @@ def createpdf_firefox(pagename): if os.path.exists(FIREFOXPDFFOLDER + os.sep + pagename + ".pdf"): shutil.move(FIREFOXPDFFOLDER+os.sep+pagename+".pdf",outfile) else: - print "-----------------------------------------> Couldn't find print output!" + print("-----------------------------------------> Couldn't find print output!") def createpdf_htmldoc(pagename): @@ -458,16 +459,16 @@ def createpdf_wkhtmltopdf(pagename): infile = FOLDER + os.sep + pagename+'.html' outfile = FOLDER + os.sep + pagename+'.pdf' cmd = 'wkhtmltopdf -L 5mm --user-style-sheet '+FOLDER+os.sep+'wkhtmltopdf.css '+infile+' '+outfile - print cmd + print(cmd) #return os.system(cmd) else: - print "skipping" + print("skipping") def joinpdf(): "creates one pdf file from several others, following order from the cover" from PyPDF2 import PdfFileReader,PdfFileWriter - if VERBOSE: print "Building table of contents..." + if VERBOSE: print("Building table of contents...") result = PdfFileWriter() createCover() @@ -488,7 +489,7 @@ def joinpdf(): if page == "end": parent = False continue - if VERBOSE: print 'Appending',page, "at position",count + if VERBOSE: print('Appending',page, "at position",count) title = page.replace("_"," ") pdffile = page + ".pdf" if exists(pdffile,True): @@ -504,16 +505,16 @@ def joinpdf(): result.addBookmark(title,count,parent) count += numpages else: - print "page",pdffile,"not found, aborting." + print("page",pdffile,"not found, aborting.") sys.exit() - if VERBOSE: print "Writing..." + if VERBOSE: print("Writing...") outputfile = open(FOLDER+os.sep+"freecad.pdf",'wb') result.write(outputfile) outputfile.close() if VERBOSE: - print ' ' - print 'Successfully created '+FOLDER+os.sep+'freecad.pdf' + print(' ') + print('Successfully created '+FOLDER+os.sep+'freecad.pdf') def local(page,image=False): @@ -544,7 +545,7 @@ def makeStyleSheet(): def createCover(): "downloads and creates a cover page" - if VERBOSE: print "fetching " + COVER + if VERBOSE: print("fetching " + COVER) data = (urlopen(COVER).read()) path = FOLDER + os.sep + "Cover.svg" fil = open(path,'wb') diff --git a/src/Tools/offlinedoc/update.py b/src/Tools/offlinedoc/update.py index 9f35ed52a3..fd3b8ac729 100755 --- a/src/Tools/offlinedoc/update.py +++ b/src/Tools/offlinedoc/update.py @@ -41,7 +41,8 @@ This script needs to be run after the wiki has been fully downloaded. It has thr """ import sys, os, re, tempfile, getopt -from urllib2 import urlopen, HTTPError +from urllib.request import urlopen +from urllib.error import HTTPError # CONFIGURATION ################################################# @@ -58,70 +59,70 @@ def update(pagename=None): if not os.path.exists("revisions.txt"): # case 1) if not os.path.exists("wikifiles.txt"): - print "No wikifiles.txt found. Aborting" + print("No wikifiles.txt found. Aborting") sys.exit() pages = [] 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 not "/wiki/" in l: - if VERBOSE: print "Adding ",l.strip() + if VERBOSE: print("Adding ",l.strip()) pages.append(l.strip()) f.close() - if VERBOSE: print "Added ",str(len(pages))," entries" + if VERBOSE: print("Added ",str(len(pages))," entries") i = 1 revs = [] for page in pages: rev = getRevision(page) - if VERBOSE: print str(i)," revision: ",rev + if VERBOSE: print(str(i)," revision: ",rev) revs.append(page+":"+rev) i += 1 writeList(revs,"revisions.txt") - print "All done. Successfully written revisions.txt with ",len(revs)," entries." + print("All done. Successfully written revisions.txt with ",len(revs)," entries.") elif os.path.exists("revisions.txt") and (not os.path.exists("updates.txt")): # case 2) f = open("revisions.txt","r") - if VERBOSE: print "Reading revisions list..." + if VERBOSE: print("Reading revisions list...") revisions = {} for l in f.readlines(): if l.strip() != "": r = l.strip().split(":") p = ":".join(r[:-1]) - if VERBOSE: print "Adding ",p + if VERBOSE: print("Adding ",p) revisions[p] = r[1] f.close() - if VERBOSE: print "Added ",str(len(revisions.keys()))," entries" + if VERBOSE: print("Added ",str(len(list(revisions.keys())))," entries") updates = [] i = 1 - for page in revisions.keys(): + for page in list(revisions.keys()): rev = getRevision(page) if rev != revisions[page]: - if VERBOSE: print str(i),page," has a new revision: ",rev + if VERBOSE: print(str(i),page," has a new revision: ",rev) updates.append(page) else: - if VERBOSE: print str(i),page," is up to date " + if VERBOSE: print(str(i),page," is up to date ") i += 1 if updates: writeList(updates,"updates.txt") - print "All done. Successfully written updates.txt with ",len(updates)," entries." + print("All done. Successfully written updates.txt with ",len(updates)," entries.") else: - print "Everything up to date. Nothing to be done." + print("Everything up to date. Nothing to be done.") elif os.path.exists("revisions.txt") and os.path.exists("updates.txt"): # case 3) if not os.path.exists("wikifiles.txt"): - print "No wikifiles.txt found. Aborting" + print("No wikifiles.txt found. Aborting") sys.exit() wikifiles = [] f = open("wikifiles.txt","r") - if VERBOSE: print "Reading wikifiles list..." + if VERBOSE: print("Reading wikifiles list...") for l in f.readlines(): if l.strip() != "": wikifiles.append(l.strip()) f.close() - if VERBOSE: print "Read ",str(len(wikifiles))," entries" + if VERBOSE: print("Read ",str(len(wikifiles))," entries") f = open("revisions.txt","r") - if VERBOSE: print "Reading revisions list..." + if VERBOSE: print("Reading revisions list...") revisions = {} for l in f.readlines(): if l.strip() != "": @@ -131,25 +132,25 @@ def update(pagename=None): f.close() todo = [] f = open("updates.txt","r") - if VERBOSE: print "Reading updates list..." + if VERBOSE: print("Reading updates list...") for l in f.readlines(): if l.strip() != "": todo.append(l.strip()) f.close() - if VERBOSE: print str(len(todo))," pages to scan..." + if VERBOSE: print(str(len(todo))," pages to scan...") import buildwikiindex buildwikiindex.WRITETHROUGH = False buildwikiindex.VERBOSE = VERBOSE updates = [] for t in todo: - if VERBOSE: print "Scanning ",t + if VERBOSE: print("Scanning ",t) updates.extend(buildwikiindex.crawl(t)) updates = [u for u in updates if not u in wikifiles] - if VERBOSE: print str(len(updates))," files to download..." + if VERBOSE: print(str(len(updates))," files to download...") import downloadwiki i = 1 for u in updates: - if VERBOSE: print i, ": Fetching ", u + if VERBOSE: print(i, ": Fetching ", u) downloadwiki.get(u) if not "/wiki/" in u: rev = getRevision(u) @@ -157,26 +158,26 @@ def update(pagename=None): if not u in wikifiles: wikifiles.append(u) i += 1 - if VERBOSE: print "Updating wikifiles and revisions..." + if VERBOSE: print("Updating wikifiles and revisions...") writeList(wikifiles,"wikifiles.txt") updatedrevs = [] - for k in revisions.keys(): + for k in list(revisions.keys()): updatedrevs.append(k+":"+revisions[k]) writeList(updatedrevs,"revisions.txt") os.remove("updates.txt") - if VERBOSE: print "All done!" + if VERBOSE: print("All done!") def getRevision(page): html = fetchPage(page) revs = re.findall("wgCurRevisionId\"\:(.*?),",html) if len(revs) == 1: return revs[0] - print 'Error: unable to get revision ID of ' + page + print('Error: unable to get revision ID of ' + page) sys.exit() def fetchPage(page): "retrieves given page from the wiki" - print "fetching: ",page + print("fetching: ",page) failcount = 0 while failcount < MAXFAIL: try: @@ -184,7 +185,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 writeList(pages,filename): @@ -192,7 +193,7 @@ def writeList(pages,filename): for p in pages: f.write(p+"\n") f.close() - if VERBOSE: print "written ",filename + if VERBOSE: print("written ",filename) if __name__ == "__main__": update(sys.argv[1:]) diff --git a/src/Tools/pythondoc.py b/src/Tools/pythondoc.py index 8536a1aac9..029934af40 100644 --- a/src/Tools/pythondoc.py +++ b/src/Tools/pythondoc.py @@ -1,89 +1,89 @@ -#! python -# -*- coding: utf-8 -*- -# (c) 2007 Werner Mayer LGPL -# Create HTML documentation from FreeCAD's Python modules and classes. - -import pydoc, pkgutil, sys, os, dircache, zipfile - -def generateDoc(): - # Get the path to the FreeCAD module relative to this directory - toolspath = os.path.dirname(__file__) - homepath = toolspath + '/../../' - homepath = os.path.realpath(homepath) - binpath = os.path.join(homepath, 'bin') - docpath = os.path.join(homepath, 'doc') - modpath = os.path.join(homepath, 'Mod') - - # Change to the doc directory - cwd = os.getcwd() - print 'Change to ' + docpath - os.chdir(homepath) - if os.path.exists('doc') == False: - os.mkdir('doc') - os.chdir('doc') - - # Add the bin path to the system path - if os.name == 'nt': - os.environ['PATH'] = os.environ['PATH'] + ';' + binpath - else: - os.environ['PATH'] = os.environ['PATH'] + ':' + binpath - - # Import FreeCAD module - sys.path.append(binpath) - print 'Write documentation for module \'FreeCAD\'' - pydoc.writedoc('FreeCAD') - print '' - - # Module directory - ModDirs = dircache.listdir(modpath) - - # Search for module paths and append them to Python path - #for Dir in ModDirs: - # if (Dir != '__init__.py'): - # sys.path.append( os.path.join(modpath,Dir) ) - - # Walk through the module paths again and try loading the modules to create HTML files - for Dir in ModDirs: - dest = os.path.join(modpath,Dir) - print 'Write documentation for module \'' + Dir + '\'' - if (Dir != '__init__.py'): - writedocs(dest) - print '' - - # Now we must create a document and create instances of all Python classes which - # cannot be directly created by a module. - - # Create a ZIP archive from all HTML files - print 'Creating ZIP archive \'docs.zip\'...' - zip = zipfile.ZipFile('docs.zip', 'w') - for file in os.listdir('.'): - if not os.path.isdir(file): - if file.find('.html') > 0: - print ' Adding file ' + file + ' to archive' - zip.write(file) - - print 'done.' - zip.close() - - # Remove all HTML files - print 'Cleaning up HTML files...' - for file in os.listdir('.'): - if not os.path.isdir(file): - if file.find('.html') > 0: - print ' Removing ' + file - os.remove(file) - - os.chdir(cwd) - print 'done.' - -def writedocs(dir, pkgpath='', done=None): - """Write out HTML documentation for all modules in a directory tree.""" - if done is None: done = {} - for importer, modname, ispkg in pkgutil.walk_packages([dir], pkgpath): - # Ignore all debug modules - if modname[-2:] != '_d': - pydoc.writedoc(modname) - return - -if __name__ == "__main__": - generateDoc() +#! python +# -*- coding: utf-8 -*- +# (c) 2007 Werner Mayer LGPL +# Create HTML documentation from FreeCAD's Python modules and classes. + +import pydoc, pkgutil, sys, os, dircache, zipfile + +def generateDoc(): + # Get the path to the FreeCAD module relative to this directory + toolspath = os.path.dirname(__file__) + homepath = toolspath + '/../../' + homepath = os.path.realpath(homepath) + binpath = os.path.join(homepath, 'bin') + docpath = os.path.join(homepath, 'doc') + modpath = os.path.join(homepath, 'Mod') + + # Change to the doc directory + cwd = os.getcwd() + print('Change to ' + docpath) + os.chdir(homepath) + if os.path.exists('doc') == False: + os.mkdir('doc') + os.chdir('doc') + + # Add the bin path to the system path + if os.name == 'nt': + os.environ['PATH'] = os.environ['PATH'] + ';' + binpath + else: + os.environ['PATH'] = os.environ['PATH'] + ':' + binpath + + # Import FreeCAD module + sys.path.append(binpath) + print('Write documentation for module \'FreeCAD\'') + pydoc.writedoc('FreeCAD') + print('') + + # Module directory + ModDirs = dircache.listdir(modpath) + + # Search for module paths and append them to Python path + #for Dir in ModDirs: + # if (Dir != '__init__.py'): + # sys.path.append( os.path.join(modpath,Dir) ) + + # Walk through the module paths again and try loading the modules to create HTML files + for Dir in ModDirs: + dest = os.path.join(modpath,Dir) + print('Write documentation for module \'' + Dir + '\'') + if (Dir != '__init__.py'): + writedocs(dest) + print('') + + # Now we must create a document and create instances of all Python classes which + # cannot be directly created by a module. + + # Create a ZIP archive from all HTML files + print('Creating ZIP archive \'docs.zip\'...') + zip = zipfile.ZipFile('docs.zip', 'w') + for file in os.listdir('.'): + if not os.path.isdir(file): + if file.find('.html') > 0: + print(' Adding file ' + file + ' to archive') + zip.write(file) + + print('done.') + zip.close() + + # Remove all HTML files + print('Cleaning up HTML files...') + for file in os.listdir('.'): + if not os.path.isdir(file): + if file.find('.html') > 0: + print(' Removing ' + file) + os.remove(file) + + os.chdir(cwd) + print('done.') + +def writedocs(dir, pkgpath='', done=None): + """Write out HTML documentation for all modules in a directory tree.""" + if done is None: done = {} + for importer, modname, ispkg in pkgutil.walk_packages([dir], pkgpath): + # Ignore all debug modules + if modname[-2:] != '_d': + pydoc.writedoc(modname) + return + +if __name__ == "__main__": + generateDoc() diff --git a/src/Tools/updatecrowdin.py b/src/Tools/updatecrowdin.py index 49c4db410e..032c497da6 100755 --- a/src/Tools/updatecrowdin.py +++ b/src/Tools/updatecrowdin.py @@ -123,14 +123,14 @@ if __name__ == "__main__": # only one argument allowed arg = sys.argv[1:] if len(arg) != 1: - print __doc__ + print(__doc__) sys.exit() arg = arg[0] # getting API key stored in ~/.crowdin-freecad configfile = os.path.expanduser("~")+os.sep+".crowdin-freecad" if not os.path.exists(configfile): - print "Config file not found!" + print("Config file not found!") sys.exit() f = open(configfile) url = "https://api.crowdin.com/api/project/freecad/" @@ -146,10 +146,10 @@ if __name__ == "__main__": c.close() handler = ResponseHandler() xml.sax.parseString(b.getvalue(),handler) - print handler.data + print(handler.data) elif arg == "build": - print "Building (warning, this can be invoked only once per 30 minutes)..." + print("Building (warning, this can be invoked only once per 30 minutes)...") c = pycurl.Curl() c.setopt(pycurl.URL, url+"export"+key) b = StringIO.StringIO() @@ -158,17 +158,17 @@ if __name__ == "__main__": c.close() handler = ResponseHandler() xml.sax.parseString(b.getvalue(),handler) - print handler.data + print(handler.data) elif arg == "download": - print "Downloading all.zip in current directory..." + print("Downloading all.zip in current directory...") cmd = "wget -O freecad.zip "+url+"download/all.zip"+key os.system(cmd) elif arg == "update": basepath = os.path.dirname(os.path.abspath(".")) for f in files: - print "Sending ",f[0],"..." + print("Sending ",f[0],"...") c = pycurl.Curl() fields = [('files['+f[0]+']', (c.FORM_FILE, basepath+f[1]))] c.setopt(pycurl.URL, url+"update-file"+key) @@ -179,9 +179,9 @@ if __name__ == "__main__": c.close() handler = ResponseHandler() xml.sax.parseString(b.getvalue(),handler) - print handler.data + print(handler.data) else: - print __doc__ + print(__doc__) diff --git a/src/Tools/updatefromcrowdin.py b/src/Tools/updatefromcrowdin.py index 360044cfa6..b2f4c516fd 100755 --- a/src/Tools/updatefromcrowdin.py +++ b/src/Tools/updatefromcrowdin.py @@ -98,11 +98,11 @@ default_languages = "af zh-CN zh-TW hr cs nl fi fr de hu ja no pl pt-PT ro ru sr def updateqrc(qrcpath,lncode): "updates a qrc file with the given translation entry" - print "opening " + qrcpath + "..." + print("opening " + qrcpath + "...") # getting qrc file contents if not os.path.exists(qrcpath): - print "ERROR: Resource file " + qrcpath + " doesn't exist" + print("ERROR: Resource file " + qrcpath + " doesn't exist") sys.exit() f = open(qrcpath,"ro") resources = [] @@ -114,7 +114,7 @@ def updateqrc(qrcpath,lncode): name = "_" + lncode + ".qm" for r in resources: if name in r: - print "language already exists in qrc file" + print("language already exists in qrc file") return # find the latest qm line @@ -123,12 +123,12 @@ def updateqrc(qrcpath,lncode): if ".qm" in resources[i]: pos = i if pos == None: - print "No existing .qm file in this resource. Appending to the end position" + print("No existing .qm file in this resource. Appending to the end position") for i in range(len(resources)): if "" in resources[i]: pos = i-1 if pos == None: - print "ERROR: couldn't add qm files to this resource: " + qrcpath + print("ERROR: couldn't add qm files to this resource: " + qrcpath) sys.exit() # inserting new entry just after the last one @@ -140,7 +140,7 @@ def updateqrc(qrcpath,lncode): line = " translations/"+modname+"_"+lncode+".qm\n" #print "ERROR: no existing qm entry in this resource: Please add one manually " + qrcpath #sys.exit() - print "inserting line: ",line + print("inserting line: ",line) resources.insert(pos+1,line) # writing the file @@ -148,7 +148,7 @@ def updateqrc(qrcpath,lncode): for r in resources: f.write(r) f.close() - print "successfully updated ",qrcpath + print("successfully updated ",qrcpath) def doFile(tsfilepath,targetpath,lncode,qrcpath): "updates a single ts file, and creates a corresponding qm file" @@ -161,7 +161,7 @@ def doFile(tsfilepath,targetpath,lncode,qrcpath): os.system("lrelease " + newpath) newqm = targetpath + os.sep + basename + "_" + lncode + ".qm" if not os.path.exists(newqm): - print "ERROR: impossible to create " + newqm + ", aborting" + print("ERROR: impossible to create " + newqm + ", aborting") sys.exit() updateqrc(qrcpath,lncode) @@ -178,24 +178,24 @@ def doLanguage(lncode,fmodule=""): else: mods = locations if not mods: - print "Error: Couldn't find module "+fmodule + print("Error: Couldn't find module "+fmodule) sys.exit() for target in mods: basefilepath = tempfolder + os.sep + lncode + os.sep + target[0] + ".ts" targetpath = os.path.abspath(target[1]) qrcpath = os.path.abspath(target[2]) doFile(basefilepath,targetpath,lncode,qrcpath) - print lncode + " done!" + print(lncode + " done!") if __name__ == "__main__": args = sys.argv[1:] if len(args) < 1: - print __doc__ + print(__doc__) sys.exit() try: opts, args = getopt.getopt(sys.argv[1:], "hd:z:m:", ["help", "directory=","zipfile=", "module="]) except getopt.GetoptError: - print __doc__ + print(__doc__) sys.exit() # checking on the options @@ -204,7 +204,7 @@ if __name__ == "__main__": fmodule = "" for o, a in opts: if o in ("-h", "--help"): - print __doc__ + print(__doc__) sys.exit() if o in ("-d", "--directory"): inputdir = a @@ -217,30 +217,30 @@ if __name__ == "__main__": if inputdir: tempfolder = os.path.realpath(inputdir) if not os.path.exists(tempfolder): - print "ERROR: " + tempfolder + " not found" + print("ERROR: " + tempfolder + " not found") sys.exit() elif inputzip: tempfolder = tempfile.mkdtemp() - print "creating temp folder " + tempfolder + print("creating temp folder " + tempfolder) os.chdir(tempfolder) inputzip=os.path.realpath(inputzip) if not os.path.exists(inputzip): - print "ERROR: " + inputzip + " not found" + print("ERROR: " + inputzip + " not found") sys.exit() shutil.copy(inputzip,tempfolder) zfile=zipfile.ZipFile("freecad.zip") - print "extracting freecad.zip..." + print("extracting freecad.zip...") zfile.extractall() else: tempfolder = tempfile.mkdtemp() - print "creating temp folder " + tempfolder + print("creating temp folder " + tempfolder) os.chdir(tempfolder) os.system("wget "+crowdinpath) if not os.path.exists("freecad.zip"): - print "download failed!" + print("download failed!") sys.exit() zfile=zipfile.ZipFile("freecad.zip") - print "extracting freecad.zip..." + print("extracting freecad.zip...") zfile.extractall() os.chdir(currentfolder) if not args: @@ -249,7 +249,7 @@ if __name__ == "__main__": args = default_languages.split() for ln in args: if not os.path.exists(tempfolder + os.sep + ln): - print "ERROR: language path for " + ln + " not found!" + print("ERROR: language path for " + ln + " not found!") else: doLanguage(ln,fmodule) diff --git a/src/Tools/updateppa.py b/src/Tools/updateppa.py index 896a1ede75..de63721b3a 100644 --- a/src/Tools/updateppa.py +++ b/src/Tools/updateppa.py @@ -27,8 +27,8 @@ def runUpdate(filename): try: wf = open(LOCAL_BRANCH + "/src/Build/Version.h", 'w') rf = open(filename, 'r') - except IOError, error: - raise IOError, error + except IOError as error: + raise error else: wf.write(rf.read()) wf.close() diff --git a/src/Tools/updatets.py b/src/Tools/updatets.py index 09678e05e3..4f8f2f125b 100755 --- a/src/Tools/updatets.py +++ b/src/Tools/updatets.py @@ -109,7 +109,7 @@ def find_tools(): PYLUPDATE = "pylupdate4" else: raise Exception("Cannot find pylupdate") - print "Qt tools:", QMAKE, LUPDATE, PYLUPDATE + print("Qt tools:", QMAKE, LUPDATE, PYLUPDATE) def filter_dirs(item): global DirFilter @@ -136,7 +136,7 @@ def update_python_translation(item): cur = os.getcwd() os.chdir(item[0]) execline = item[1].replace("pylupdate",PYLUPDATE) - print "Executing special command in ",item[0],": ",execline + print("Executing special command in ",item[0],": ",execline) os.system(execline) os.chdir(cur)