diff --git a/scripts/approve.py b/scripts/approve.py index 78a2a9e1..f03417dc 100755 --- a/scripts/approve.py +++ b/scripts/approve.py @@ -11,23 +11,23 @@ from scriptCommon import catchPath rootPath = os.path.join( catchPath, 'projects/SelfTest/Baselines' ) if len(sys.argv) > 1: - files = [os.path.join( rootPath, f ) for f in sys.argv[1:]] + files = [os.path.join( rootPath, f ) for f in sys.argv[1:]] else: - files = glob.glob( os.path.join( rootPath, "*.unapproved.txt" ) ) + files = glob.glob( os.path.join( rootPath, "*.unapproved.txt" ) ) def approveFile( approvedFile, unapprovedFile ): - justFilename = unapprovedFile[len(rootPath)+1:] - if os.path.exists( unapprovedFile ): - if os.path.exists( approvedFile ): - os.remove( approvedFile ) - os.rename( unapprovedFile, approvedFile ) - print( "approved " + justFilename ) - else: - print( "approval file " + justFilename + " does not exist" ) + justFilename = unapprovedFile[len(rootPath)+1:] + if os.path.exists( unapprovedFile ): + if os.path.exists( approvedFile ): + os.remove( approvedFile ) + os.rename( unapprovedFile, approvedFile ) + print( "approved " + justFilename ) + else: + print( "approval file " + justFilename + " does not exist" ) -if len(files) > 0: - for unapprovedFile in files: - approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile ) +if files: + for unapprovedFile in files: + approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile ) else: - print( "no files to approve" ) + print( "no files to approve" ) diff --git a/scripts/embed.py b/scripts/embed.py index 23b157c8..66757033 100644 --- a/scripts/embed.py +++ b/scripts/embed.py @@ -25,7 +25,7 @@ class LineMapper: # TBD: # #if, #ifdef, comments after #else def mapLine( self, lineNo, line ): - for idFrom, idTo in self.idMap.iteritems(): + for idFrom, idTo in self.idMap.items(): r = re.compile("(.*)" + idFrom + "(.*)") m = r.match( line ) @@ -38,7 +38,7 @@ class LineMapper: # print("[{0}] originalNs: '{1}' - closing".format(lineNo, originalNs)) # print( " " + line ) # print( " 1:[{0}]\n 2:[{1}]\n 3:[{2}]\n 4:[{3}]\n 5:[{4}]".format( m.group(1), m.group(2), m.group(3), m.group(4), m.group(5) ) ) - if self.outerNamespace.has_key(originalNs): + if originalNs in self.outerNamespace: outerNs, innerNs = self.outerNamespace[originalNs] return "{0}}}{1}{2}::{3}{4}{5}\n".format( m.group(1), m.group(2), outerNs, innerNs, m.group(4), m.group(5)) m = nsRe.match( line ) @@ -47,7 +47,7 @@ class LineMapper: # print("[{0}] originalNs: '{1}'".format(lineNo, originalNs)) # print( " " + line ) # print( " 1:[{0}]\n 2:[{1}]\n 3:[{2}]\n 4:[{3}]".format( m.group(1), m.group(2), m.group(3), m.group(4) ) ) - if self.outerNamespace.has_key(originalNs): + if originalNs in self.outerNamespace: outerNs, innerNs = self.outerNamespace[originalNs] return "{0}{1} {{ namespace {2}{3}{4}\n".format( m.group(1), outerNs, innerNs, m.group(3), m.group(4) ) diff --git a/scripts/fixWhitespace.py b/scripts/fixWhitespace.py index 6f37c539..bfa4aa08 100755 --- a/scripts/fixWhitespace.py +++ b/scripts/fixWhitespace.py @@ -4,19 +4,20 @@ from __future__ import print_function import os from scriptCommon import catchPath -changedFiles = 0 - def isSourceFile( path ): return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" ) def fixAllFilesInDir( dir ): + changedFiles = 0 for f in os.listdir( dir ): path = os.path.join( dir,f ) if os.path.isfile( path ): if isSourceFile( path ): - fixFile( path ) + if fixFile( path ): + changedFiles += 1 else: fixAllFilesInDir( path ) + return changedFiles def fixFile( path ): f = open( path, 'r' ) @@ -41,8 +42,10 @@ def fixFile( path ): f2.write( line ) f2.close() os.remove( altPath ) + return True + return False -fixAllFilesInDir(catchPath) +changedFiles = fixAllFilesInDir(catchPath) if changedFiles > 0: print( "Fixed " + str(changedFiles) + " file(s)" ) else: diff --git a/scripts/generateSingleHeader.py b/scripts/generateSingleHeader.py index 471b872e..c3ce1aec 100755 --- a/scripts/generateSingleHeader.py +++ b/scripts/generateSingleHeader.py @@ -7,7 +7,6 @@ import io import sys import re import datetime -import string from glob import glob from scriptCommon import catchPath @@ -34,7 +33,7 @@ def generate(v): } for arg in sys.argv[1:]: - arg = string.lower(arg) + arg = arg.lower() if arg == "noimpl": globals['includeImpl'] = False print( "Not including impl code" ) @@ -82,7 +81,7 @@ def generate(v): if m: header = m.group(1) headerPath, sep, headerFile = header.rpartition( "/" ) - if not headerFile in seenHeaders: + if headerFile not in seenHeaders: if headerFile != "tbc_text_format.h" and headerFile != "clara.h": seenHeaders.add( headerFile ) if headerPath == "internal" and path.endswith("internal/"): diff --git a/scripts/releaseNotes.py b/scripts/releaseNotes.py index 80fffbf2..5e770bba 100755 --- a/scripts/releaseNotes.py +++ b/scripts/releaseNotes.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + import os import re import urllib2 @@ -41,7 +43,6 @@ for line in lines: pass elif line.startswith( "Date:"): dates.append( line[5:].lstrip() ) - pass elif line == "" and prevLine == "": pass else: @@ -58,7 +59,7 @@ for line in lines: else: messages.append( line2 ) -print "All changes between {0} and {1}:\n".format( dates[-1], dates[0] ) +print("All changes between {0} and {1}:\n".format( dates[-1], dates[0] )) for line in messages: - print line + print(line) diff --git a/scripts/scriptCommon.py b/scripts/scriptCommon.py index 9adadb6d..1415be0b 100644 --- a/scripts/scriptCommon.py +++ b/scripts/scriptCommon.py @@ -15,7 +15,7 @@ def runAndCapture( args ): line = "" while True: out = child.stdout.read(1) - if out == '' and child.poll() != None: + if out == '' and child.poll(): break if out != '': if out == '\n': diff --git a/scripts/updateDocumentToC.py b/scripts/updateDocumentToC.py index e706c5c3..d3b8bf0f 100644 --- a/scripts/updateDocumentToC.py +++ b/scripts/updateDocumentToC.py @@ -12,7 +12,6 @@ # from __future__ import print_function -from scriptCommon import catchPath import argparse import glob @@ -20,6 +19,8 @@ import os import re import sys +from scriptCommon import catchPath + # Configuration: minTocEntries = 4 @@ -431,7 +432,7 @@ def updateDocumentToCMain(): args = parser.parse_args() - paths = args.Input if len(args.Input) > 0 else [documentsDefault] + paths = args.Input if args.Input else [documentsDefault] changedFiles = updateDocumentToC(paths=paths, min_toc_len=args.minTocEntries, verbose=args.verbose) diff --git a/scripts/updateVcpkgPackage.py b/scripts/updateVcpkgPackage.py index fd7b759a..c1f40b59 100644 --- a/scripts/updateVcpkgPackage.py +++ b/scripts/updateVcpkgPackage.py @@ -31,7 +31,6 @@ def get_hash(path): def update_control(path): v = Version() - ver_string = v.getVersionString() # Update control lines = [] @@ -48,7 +47,6 @@ def update_control(path): def update_portfile(path, header_hash, licence_hash): print('Updating portfile') v = Version() - ver_string = v.getVersionString() # Update portfile lines = [] diff --git a/scripts/updateWandbox.py b/scripts/updateWandbox.py index 25a74631..5785feb4 100644 --- a/scripts/updateWandbox.py +++ b/scripts/updateWandbox.py @@ -41,7 +41,7 @@ def uploadFiles(): 'save': True }) - if 'status' in response and not 'compiler_error' in response: + if 'status' in response and 'compiler_error' not in response: return True, response['url'] else: return False, response