From e2bb84fd2f802268582c202a511ff58d55efafe7 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Thu, 25 Feb 2021 22:48:01 -0600 Subject: [PATCH] [Tools] Fix static analyis issues This commit addresses issues identified by LGTM for the various independent (and mostly-independent) files in the Tools subdirectory. The vast majority of the issues are trivial, and are things like unused imports or catching BaseException. There was one true bug identified, a global variable being changed in a function where it was not marked global, but it only affected output quantity (the variable is named "VERBOSE"). A couple of other issues identified variables that appear to represent no-longer-existing options in the code. The options were left, but a deprecation printout replaces the variable in the event the option is provided. --- src/Tools/ArchiveNameFromVersionHeader.py | 2 +- src/Tools/DistTools.py | 69 +++-------- src/Tools/FCFileTools.py | 24 ++-- src/Tools/LicenseChecker.py | 2 +- src/Tools/MakeApp.py | 11 +- src/Tools/MakeAppTools.py | 138 +++++++++++----------- src/Tools/MakeMacBundleRelocatable.py | 7 +- src/Tools/MemoryLeaks.py | 2 +- src/Tools/PythonToCPP.py | 2 +- src/Tools/SubWCRev.py | 15 +-- src/Tools/WinVersion.py | 3 +- src/Tools/catfiles.py | 3 +- src/Tools/dir2qrc.py | 4 +- src/Tools/doctools.py | 5 +- src/Tools/fcbt.py | 2 +- src/Tools/freecad-thumbnailer | 2 +- src/Tools/generate.py | 15 ++- src/Tools/makedist.py | 3 +- src/Tools/pythondoc.py | 3 +- src/Tools/updatecrowdin.py | 1 + src/Tools/updateppa.py | 4 +- src/Tools/wiki2qhelp.py | 10 +- 22 files changed, 144 insertions(+), 183 deletions(-) diff --git a/src/Tools/ArchiveNameFromVersionHeader.py b/src/Tools/ArchiveNameFromVersionHeader.py index eba3d6df4a..6ed557d198 100644 --- a/src/Tools/ArchiveNameFromVersionHeader.py +++ b/src/Tools/ArchiveNameFromVersionHeader.py @@ -3,7 +3,7 @@ # A convenience script to generate a deployment archive name of the form # FreeCAD_{Major Version Number}.{Minor Version Number}-{Git Revision Count}.{Git Short SHA}-{OS}-{Arch} # -import sys,string,getopt,platform +import sys,getopt,platform def deserializeVersionHeader(path): version = {} diff --git a/src/Tools/DistTools.py b/src/Tools/DistTools.py index 14468a7bc3..39bab66ada 100644 --- a/src/Tools/DistTools.py +++ b/src/Tools/DistTools.py @@ -43,7 +43,7 @@ def cpall(dirFrom, dirTo): if verbose > 1: print('copying', pathFrom, 'to', pathTo) cpfile(pathFrom, pathTo) fcount = fcount+1 - except: + except Exception: print('Error copying', pathFrom, to, pathTo, '--skipped') print(sys.exc_type, sys.exc_value) else: @@ -52,7 +52,7 @@ def cpall(dirFrom, dirTo): os.mkdir(pathTo) # make new subdir cpall(pathFrom, pathTo) # recur into subdirs dcount = dcount+1 - except: + except Exception: print('Error creating', pathTo, '--skipped') print(sys.exc_type, sys.exc_value) @@ -82,7 +82,7 @@ def cpallWithFilter(dirFrom, dirTo,MatchList): if verbose > 1: print('copying', pathFrom, 'to', pathTo) cpfile(pathFrom, pathTo) fcount = fcount+1 - except: + except Exception: print('Error copying', pathFrom, to, pathTo, '--skipped') print(sys.exc_type, sys.exc_value) else: @@ -91,7 +91,7 @@ def cpallWithFilter(dirFrom, dirTo,MatchList): os.mkdir(pathTo) # make new subdir cpallWithFilter(pathFrom, pathTo,MatchList) # recur into subdirs dcount = dcount+1 - except: + except Exception: print('Error creating', pathTo, '--skipped') print(sys.exc_type, sys.exc_value) @@ -119,13 +119,6 @@ def rmall(dirPath): # delete dirPath and below dcount = dcount + 1 def BuildDistName(): - # line separator - ls = os.linesep - # path separator - ps = os.pathsep - # dir separator - ds = os.sep - # Building dist name # reading the last Version information [FCVersionMajor,FCVersionMinor,FCVersionBuild,FCVersionDisDa] = open("../Version.h",'r').readlines() @@ -133,13 +126,6 @@ def BuildDistName(): return DistName def BuildSetupName(): - # line separator - ls = os.linesep - # path separator - ps = os.pathsep - # dir separator - ds = os.sep - # Building dist name # reading the last Version information [FCVersionMajor,FCVersionMinor,FCVersionBuild,FCVersionDisDa] = open("../Version.h",'r').readlines() @@ -148,39 +134,18 @@ def BuildSetupName(): return DistName def GetVersion(): - # line separator - ls = os.linesep - # path separator - ps = os.pathsep - # dir separator - ds = os.sep - # Building dist name # reading the last Version information [FCVersionMajor,FCVersionMinor,FCVersionBuild,FCVersionDisDa] = open("../Version.h",'r').readlines() return FCVersionMajor[23:-1] + '.' +FCVersionMinor[23:-1] def GetBuildNbr(): - # line separator - ls = os.linesep - # path separator - ps = os.pathsep - # dir separator - ds = os.sep - # Building dist name # reading the last Version information [FCVersionMajor,FCVersionMinor,FCVersionBuild,FCVersionDisDa] = open("../Version.h",'r').readlines() return FCVersionBuild[23:-1] def GetBuildDate(): - # line separator - ls = os.linesep - # path separator - ps = os.pathsep - # dir separator - ds = os.sep - # Building dist name # reading the last Version information [FCVersionMajor,FCVersionMinor,FCVersionBuild,FCVersionDisDa] = open("../Version.h",'r').readlines() @@ -236,12 +201,12 @@ BinFilter = ["^Plugin\\.*$", "^.*\\.lib$", "^.*\\.exp$", "^.*\\.bsc$", - "^.*\\CADD.exe$", - "^.*\\CADAppD.dll$", - "^.*\\CmdD.exe$", - "^.*\\BaseD.dll$", - "^.*\\CADDCmdPy.dll$", - "^.*\\GuiD.dll$", + "^.*CADD.exe$", + "^.*CADAppD.dll$", + "^.*CmdD.exe$", + "^.*BaseD.dll$", + "^.*CADDCmdPy.dll$", + "^.*GuiD.dll$", "^.*\\.bsc$", "^.*\\.FCScript\\..*$", "^.*\\.FCParam$", @@ -256,11 +221,11 @@ LibFilter = ["^Plugin\\.*$", "^.*\\.exe$", "^.*\\.exp$", "^.*\\.bsc$", - "^.*\\CADD.lib$", - "^.*\\CADAppD.lib$", - "^.*\\CmdD.lib$", - "^.*\\BaseD.lib$", - "^.*\\GuiD.lib$", + "^.*CADD.lib$", + "^.*CADAppD.lib$", + "^.*CmdD.lib$", + "^.*BaseD.lib$", + "^.*GuiD.lib$", "^.*\\.FCScript\\..*$", "^.*\\.FCParam$"] @@ -278,7 +243,7 @@ ModFilter = ["^.*\\.o$", "^CVS$", "^Attic$", "^.*\\.opt$", - "^.*\\_d\.pyd$", + "^.*_d\.pyd$", "^.*\\.opt$", "^.*\\.ilg$", "^.*\\.ps$", @@ -299,7 +264,7 @@ ModFilter = ["^.*\\.o$", "^.*\\.exp$", "^.*\\.lib$", "^.*\\.ui$", - "^.*\\Makefile$", + "^.*Makefile$", "^.*\\.plg$",] DocFilter = ["^.*\\.o$", diff --git a/src/Tools/FCFileTools.py b/src/Tools/FCFileTools.py index 15ed557f3a..1d9505e026 100644 --- a/src/Tools/FCFileTools.py +++ b/src/Tools/FCFileTools.py @@ -40,20 +40,20 @@ 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') + except Exception: + 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) + 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') + except Exception: + print('Error creating ', pathTo, ' -- skipped') print(sys.exc_info()[0], sys.exc_info()[1]) def SetUpFilter(MatchList): @@ -79,20 +79,20 @@ 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') + except Exception: + 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) + 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') + except Exception: + print('Error creating ', pathTo, ' -- skipped') print(sys.exc_info()[0], sys.exc_info()[1]) ################################################################ diff --git a/src/Tools/LicenseChecker.py b/src/Tools/LicenseChecker.py index 381b68bd81..29745cd922 100644 --- a/src/Tools/LicenseChecker.py +++ b/src/Tools/LicenseChecker.py @@ -84,7 +84,7 @@ def parsefile(fn): return print ("Missing license text in file %s") % (fn) - except: + except Exception: pass if __name__ == "__main__": diff --git a/src/Tools/MakeApp.py b/src/Tools/MakeApp.py index fd1563b687..93d9c791e0 100644 --- a/src/Tools/MakeApp.py +++ b/src/Tools/MakeApp.py @@ -3,14 +3,13 @@ # (c) 2003 Werner Mayer LGPL # Create a new application module -import os,sys,string -import FCFileTools +import os,sys import MakeAppTools if(len(sys.argv) != 2): - sys.stdout.write("Please enter a name for your application.\n") - sys.exit() + sys.stdout.write("Please enter a name for your application.\n") + sys.exit() Application = sys.argv[1] @@ -18,8 +17,8 @@ Application = sys.argv[1] if not os.path.isdir("../Mod/"+Application): os.mkdir("../Mod/"+Application) else: - sys.stdout.write(Application + " already exists. Please enter another name.\n") - sys.exit() + sys.stdout.write(Application + " already exists. Please enter another name.\n") + sys.exit() # copying files from _TEMPLATE_ to ../Mod/ diff --git a/src/Tools/MakeAppTools.py b/src/Tools/MakeAppTools.py index ae58f2ea13..d799b2bdb4 100644 --- a/src/Tools/MakeAppTools.py +++ b/src/Tools/MakeAppTools.py @@ -3,75 +3,75 @@ 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 (line.find(oldName) != -1): # search for 'oldName' and replace it - line = line.replace(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]) + """ + 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 (line.find(oldName) != -1): # search for 'oldName' and replace it + line = line.replace(oldName, newName) + output.write(line) # write the modified line back + output.close # close the file + except Exception: + print('Error modifying ', pathName, ' -- skipped') + print(sys.exc_info()[0], sys.exc_info()[1]) + else: + try: + replaceTemplate(pathName, oldName, newName) + except Exception: + 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 (pathTo.find(oldName) != -1): - pathTo = pathTo.replace(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]) + """ + 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 (pathTo.find(oldName) != -1): + pathTo = pathTo.replace(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 Exception: + 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) # recurse into subdirs + dcount = dcount+1 + except Exception: + 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 26e43b9d2f..bfa259fa45 100755 --- a/src/Tools/MakeMacBundleRelocatable.py +++ b/src/Tools/MakeMacBundleRelocatable.py @@ -1,7 +1,6 @@ import os import sys -from subprocess import Popen, PIPE, check_call, check_output -import pprint +from subprocess import check_call, check_output import re import logging @@ -237,7 +236,7 @@ def build_deps_graph(graph, bundle_path, dirs_filter=None, search_paths=[]): try: deps = create_dep_nodes(list_install_names(k2), s_paths) - except: + except Exception: logging.error("Failed to resolve dependency in " + k2) raise @@ -341,7 +340,7 @@ def change_libid(graph, node, bundle_path): logging.debug(" ~ id: " + node.name) try: check_call([ "install_name_tool", "-id", node.name, lib ]) - except: + except Exception: logging.warning("Failed to change bundle id {} in lib {}".format(node.name, lib)) def print_child(graph, node, path): diff --git a/src/Tools/MemoryLeaks.py b/src/Tools/MemoryLeaks.py index d0f019a301..225b21a012 100755 --- a/src/Tools/MemoryLeaks.py +++ b/src/Tools/MemoryLeaks.py @@ -3,7 +3,7 @@ # (c) 2006 Werner Mayer LGPL # FreeCAD report memory leaks script to get provide the log file of Visual Studio in more readable file. -import os,sys,string,re +import string,re # Open the memory leak file file = open("MemLog.txt") diff --git a/src/Tools/PythonToCPP.py b/src/Tools/PythonToCPP.py index 06289083ed..0b60a9325d 100644 --- a/src/Tools/PythonToCPP.py +++ b/src/Tools/PythonToCPP.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # (c) 2004 Werner Mayer LGPL -import os,sys,string +import os,sys #os.chdir("E:\\Develop\\FreeCADWin\\scripts") diff --git a/src/Tools/SubWCRev.py b/src/Tools/SubWCRev.py index 9795450226..5619b283fb 100644 --- a/src/Tools/SubWCRev.py +++ b/src/Tools/SubWCRev.py @@ -9,7 +9,7 @@ # 2012/02/01: The script was extended to support git # 2011/02/05: The script was extended to support also Bazaar -import os,sys,string,re,time,getopt +import os,sys,re,time,getopt import xml.sax import xml.sax.handler import xml.sax.xmlreader @@ -21,6 +21,7 @@ except ImportError: # SAX handler to parse the subversion output class SvnHandler(xml.sax.handler.ContentHandler): def __init__(self): + super().__init__() self.inUrl = 0 self.inDate = 0 self.mapping = {} @@ -91,7 +92,7 @@ class DebianChangelog(VersionControl): return False try: f = open(srcdir+"/debian/changelog") - except: + except Exception: return False c = f.readline() f.close() @@ -134,7 +135,7 @@ class DebianGitHub(VersionControl): def extractInfo(self, srcdir, bindir): try: f = open(srcdir+"/debian/git-build-recipe.manifest") - except: + except Exception: return False # Read the first two lines @@ -157,7 +158,7 @@ class DebianGitHub(VersionControl): commit_date = commit_req.headers.get('last-modified') - except: + except Exception: # if connection fails then use the date of the file git-build-recipe.manifest commit_date = recipe[recipe.rfind('~') + 1 : -1] @@ -166,7 +167,7 @@ class DebianGitHub(VersionControl): # Try to convert into the same format as GitControl t = time.strptime(commit_date, "%a, %d %b %Y %H:%M:%S GMT") commit_date = ("%d/%02d/%02d %02d:%02d:%02d") % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec) - except: + except Exception: t = time.strptime(commit_date, "%Y%m%d%H%M") commit_date = ("%d/%02d/%02d %02d:%02d:%02d") % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec) @@ -192,7 +193,7 @@ class DebianGitHub(VersionControl): beg = link.rfind("&page=") + 6 end = link.rfind(">") self.rev = link[beg:end] + " (GitHub)" - except: + except Exception: pass self.url = "git://github.com/{}/{}.git {}".format(owner, repo, self.branch) @@ -395,7 +396,7 @@ class Subversion(VersionControl): strio=StringIO.StringIO(Info) inpsrc.setByteStream(strio) parser.parse(inpsrc) - except: + except Exception: return False #Information of the Subversion stuff diff --git a/src/Tools/WinVersion.py b/src/Tools/WinVersion.py index c75e6cc6bd..eb02f62229 100644 --- a/src/Tools/WinVersion.py +++ b/src/Tools/WinVersion.py @@ -11,7 +11,6 @@ def main(): input="" output="." - dir="." try: opts, args = getopt.getopt(sys.argv[1:], "dso:", ["dir=","src=","out="]) @@ -20,7 +19,7 @@ def main(): for o, a in opts: if o in ("-d", "--dir"): - dir = a + print ("The %s option is deprecated. Ignoring." % (o)) if o in ("-s", "--src"): input = a if o in ("-o", "--out"): diff --git a/src/Tools/catfiles.py b/src/Tools/catfiles.py index fd9c31bfdf..1fbac086b8 100644 --- a/src/Tools/catfiles.py +++ b/src/Tools/catfiles.py @@ -3,7 +3,8 @@ # (c) 2018 Werner Mayer LGPL # -import os,sys,getopt +import sys,getopt +#import os # The code that needs this is commented out import shutil def main(): diff --git a/src/Tools/dir2qrc.py b/src/Tools/dir2qrc.py index 1f7680f526..dbf2fc6913 100644 --- a/src/Tools/dir2qrc.py +++ b/src/Tools/dir2qrc.py @@ -29,8 +29,8 @@ Version: 0.1 """ -import os,sys,string,re,getopt,codecs -from os.path import join, getsize +import os,sys,string,getopt +from os.path import join # Globals Verbose = False diff --git a/src/Tools/doctools.py b/src/Tools/doctools.py index 94c2a76abf..321725e6d2 100644 --- a/src/Tools/doctools.py +++ b/src/Tools/doctools.py @@ -3,7 +3,7 @@ # (c) 2010 Werner Mayer LGPL # FreeCAD Python script to work with the FCStd file format. -import os,sys,string +import os import xml.sax import xml.sax.handler import xml.sax.xmlreader @@ -12,12 +12,13 @@ import zipfile # SAX handler to parse the Document.xml class DocumentHandler(xml.sax.handler.ContentHandler): def __init__(self, dirname): + super().__init__() self.files = [] self.dirname = dirname def startElement(self, name, attributes): item=attributes.get("file") - if item != None: + if item is not None: self.files.append(os.path.join(self.dirname,str(item))) def characters(self, data): diff --git a/src/Tools/fcbt.py b/src/Tools/fcbt.py index 6d63a50eb9..cb6fd467e5 100644 --- a/src/Tools/fcbt.py +++ b/src/Tools/fcbt.py @@ -3,7 +3,7 @@ # (c) 2004 Juergen Riegel -import os,sys +import sys help1 = """ FreeCAD Build Tool diff --git a/src/Tools/freecad-thumbnailer b/src/Tools/freecad-thumbnailer index 8e3a439b0a..56b9f20d31 100644 --- a/src/Tools/freecad-thumbnailer +++ b/src/Tools/freecad-thumbnailer @@ -62,6 +62,6 @@ try: thumb.write(image) thumb.close() -except: +except Exception: print("Error creating FreeCAD thumbnail for file ", input_file) sys.exit(1) diff --git a/src/Tools/generate.py b/src/Tools/generate.py index 2bc9c29a5c..3d63ad7749 100644 --- a/src/Tools/generate.py +++ b/src/Tools/generate.py @@ -4,6 +4,11 @@ from __future__ import print_function # this allows py2 to print(str1, str2) correctly +import os,sys,getopt +import generateBase.generateModel_Module +import generateTemplates.templateModule +import generateTemplates.templateClassPyExport + Usage = """generate - generates a FreeCAD Module out of an XML model Usage: @@ -24,11 +29,6 @@ Version: 0.2 """ -import os,sys,string,re,getopt,codecs,binascii -import generateBase.generateModel_Module -import generateTemplates.templateModule -import generateTemplates.templateClassPyExport - # Globals @@ -45,7 +45,7 @@ def generate(filename,path): else: Export = generateTemplates.templateClassPyExport.TemplateClassPyExport() Export.path = path+"/" - Export.dirname = os.path.dirname(filename)+"/"; + Export.dirname = os.path.dirname(filename)+"/" Export.export = GenerateModelInst.PythonExport[0] Export.Generate() print("Done generating: " + GenerateModelInst.PythonExport[0].Name) @@ -83,8 +83,7 @@ def main(): # running through the files if (len(args) ==0): - #sys.stderr.write(Usage) - generate("../Mod/PartDesign/PartDesign_Model.xml") + sys.stderr.write(Usage) else: for i in args: filename = os.path.abspath(i) diff --git a/src/Tools/makedist.py b/src/Tools/makedist.py index 8e02d13d24..f4118fe68c 100644 --- a/src/Tools/makedist.py +++ b/src/Tools/makedist.py @@ -8,7 +8,6 @@ import sys, os, getopt, tarfile, gzip, time, io, platform, shutil def main(): - srcdir="." bindir="." dfsg=False check=False @@ -20,7 +19,7 @@ def main(): for o, a in opts: if o in ("-s", "--srcdir"): - srcdir = a + print("%s is deprecated -- ignoring" % (o)) if o in ("-b", "--bindir"): bindir = a if o in ("--dfsg"): diff --git a/src/Tools/pythondoc.py b/src/Tools/pythondoc.py index 029934af40..3fbb5046e0 100644 --- a/src/Tools/pythondoc.py +++ b/src/Tools/pythondoc.py @@ -76,9 +76,8 @@ def generateDoc(): os.chdir(cwd) print('done.') -def writedocs(dir, pkgpath='', done=None): +def writedocs(dir, pkgpath=''): """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': diff --git a/src/Tools/updatecrowdin.py b/src/Tools/updatecrowdin.py index 2ce9c30de2..9ed08e58f8 100755 --- a/src/Tools/updatecrowdin.py +++ b/src/Tools/updatecrowdin.py @@ -87,6 +87,7 @@ files = [ ["AddonManager.ts", "/Mod/AddonManager/Resources/translations/Add class ResponseHandler( xml.sax.ContentHandler ): def __init__(self): + super().__init__() self.current = "" self.data = "" self.translated = 1 diff --git a/src/Tools/updateppa.py b/src/Tools/updateppa.py index de63721b3a..60c49c2a55 100644 --- a/src/Tools/updateppa.py +++ b/src/Tools/updateppa.py @@ -3,18 +3,15 @@ # (c) 2012 Werner Mayer LGPL import sys -from os import chdir from os import path from tempfile import gettempdir -from bzrlib.transport import get_transport from bzrlib.branch import Branch from bzrlib.workingtree import WorkingTree def runUpdate(filename): branch = "versioning.git" REMOTE_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch) - PUSHTO_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch) LOCAL_BRANCH=path.join(gettempdir(),branch) # Location of branch on Launchpad @@ -22,6 +19,7 @@ def runUpdate(filename): # Location of branch on local system local_branch = remote_branch.bzrdir.sprout(LOCAL_BRANCH).open_branch() + False if local_branch.__name__ else True # "Use" to silence analyzers, pending PEP 640 or similar # Change a file in the local branch try: diff --git a/src/Tools/wiki2qhelp.py b/src/Tools/wiki2qhelp.py index 1b442d3036..16f115b73c 100755 --- a/src/Tools/wiki2qhelp.py +++ b/src/Tools/wiki2qhelp.py @@ -165,7 +165,7 @@ def crawl(site=DEFAULTURL): if PDFCONVERTOR == 'pisa': try: import ho.pisa as pisa - except: ("Error: Python-pisa not installed, exiting.") + except Exception: ("Error: Python-pisa not installed, exiting.") return 1 else: if os.system('htmldoc --version'): @@ -173,7 +173,7 @@ def crawl(site=DEFAULTURL): return 1 try: from pyPdf import PdfFileReader,PdfFileWriter - except: + except Exception: print ("Error: Python-pypdf not installed, exiting.") # run ######################################################## @@ -273,7 +273,7 @@ def joinpdf(folder=TMPFOLDER,startpage=INDEX,outputname='freecad.pdf'): if exists(p[:-5]): if VERBOSE: print ('Appending',p) try: inputfile = PdfFileReader(open(folder+os.sep+p[:-5]+'.pdf','rb')) - except: print ('Unable to append',p) + except Exception: print ('Unable to append',p) else: for i in range(inputfile.getNumPages()): result.addPage(inputfile.getPage(i)) @@ -538,7 +538,7 @@ def fetchimage(imagelink): file.close() processed.append(filename) return - except: + except Exception: failcount += 1 print ('Error: unable to fetch file ' + filename) @@ -574,7 +574,7 @@ def output(html,page): file.close() def main(arg): - global QHELPCOMPILER,QCOLLECTIOMGENERATOR,OUTPUTPATH,PDFOUTPUT,PDFCONVERTOR,TMPFOLDER + global QHELPCOMPILER,QCOLLECTIOMGENERATOR,OUTPUTPATH,PDFOUTPUT,PDFCONVERTOR,TMPFOLDER,VERBOSE try: opts, args = getopt.getopt(sys.argv[1:], "hp:t:c:g:o:", ["help", "pdf=", "noremove", "tempfolder=", "helpcompiler-exe=", "out-path=", "helpgenerator-exe="]) except getopt.GetoptError: