Minor fixes to python scripts by pycodestyle

This commit is contained in:
Marcus Näslund 2018-04-19 15:02:15 +02:00 committed by Martin Hořeňovský
parent 64be2ad96c
commit 9e7c281e6e
9 changed files with 35 additions and 33 deletions

View File

@ -26,7 +26,7 @@ def approveFile( approvedFile, unapprovedFile ):
else: else:
print( "approval file " + justFilename + " does not exist" ) print( "approval file " + justFilename + " does not exist" )
if len(files) > 0: if files:
for unapprovedFile in files: for unapprovedFile in files:
approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile ) approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile )
else: else:

View File

@ -25,7 +25,7 @@ class LineMapper:
# TBD: # TBD:
# #if, #ifdef, comments after #else # #if, #ifdef, comments after #else
def mapLine( self, lineNo, line ): def mapLine( self, lineNo, line ):
for idFrom, idTo in self.idMap.iteritems(): for idFrom, idTo in self.idMap.items():
r = re.compile("(.*)" + idFrom + "(.*)") r = re.compile("(.*)" + idFrom + "(.*)")
m = r.match( line ) m = r.match( line )
@ -38,7 +38,7 @@ class LineMapper:
# print("[{0}] originalNs: '{1}' - closing".format(lineNo, originalNs)) # print("[{0}] originalNs: '{1}' - closing".format(lineNo, originalNs))
# print( " " + line ) # 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) ) ) # 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] 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)) 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 ) m = nsRe.match( line )
@ -47,7 +47,7 @@ class LineMapper:
# print("[{0}] originalNs: '{1}'".format(lineNo, originalNs)) # print("[{0}] originalNs: '{1}'".format(lineNo, originalNs))
# print( " " + line ) # 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) ) ) # 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] 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) ) return "{0}{1} {{ namespace {2}{3}{4}\n".format( m.group(1), outerNs, innerNs, m.group(3), m.group(4) )

View File

@ -4,19 +4,20 @@ from __future__ import print_function
import os import os
from scriptCommon import catchPath from scriptCommon import catchPath
changedFiles = 0
def isSourceFile( path ): def isSourceFile( path ):
return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" ) return path.endswith( ".cpp" ) or path.endswith( ".h" ) or path.endswith( ".hpp" )
def fixAllFilesInDir( dir ): def fixAllFilesInDir( dir ):
changedFiles = 0
for f in os.listdir( dir ): for f in os.listdir( dir ):
path = os.path.join( dir,f ) path = os.path.join( dir,f )
if os.path.isfile( path ): if os.path.isfile( path ):
if isSourceFile( path ): if isSourceFile( path ):
fixFile( path ) if fixFile( path ):
changedFiles += 1
else: else:
fixAllFilesInDir( path ) fixAllFilesInDir( path )
return changedFiles
def fixFile( path ): def fixFile( path ):
f = open( path, 'r' ) f = open( path, 'r' )
@ -41,8 +42,10 @@ def fixFile( path ):
f2.write( line ) f2.write( line )
f2.close() f2.close()
os.remove( altPath ) os.remove( altPath )
return True
return False
fixAllFilesInDir(catchPath) changedFiles = fixAllFilesInDir(catchPath)
if changedFiles > 0: if changedFiles > 0:
print( "Fixed " + str(changedFiles) + " file(s)" ) print( "Fixed " + str(changedFiles) + " file(s)" )
else: else:

View File

@ -7,7 +7,6 @@ import io
import sys import sys
import re import re
import datetime import datetime
import string
from glob import glob from glob import glob
from scriptCommon import catchPath from scriptCommon import catchPath
@ -34,7 +33,7 @@ def generate(v):
} }
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
arg = string.lower(arg) arg = arg.lower()
if arg == "noimpl": if arg == "noimpl":
globals['includeImpl'] = False globals['includeImpl'] = False
print( "Not including impl code" ) print( "Not including impl code" )
@ -82,7 +81,7 @@ def generate(v):
if m: if m:
header = m.group(1) header = m.group(1)
headerPath, sep, headerFile = header.rpartition( "/" ) 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": if headerFile != "tbc_text_format.h" and headerFile != "clara.h":
seenHeaders.add( headerFile ) seenHeaders.add( headerFile )
if headerPath == "internal" and path.endswith("internal/"): if headerPath == "internal" and path.endswith("internal/"):

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import os import os
import re import re
import urllib2 import urllib2
@ -41,7 +43,6 @@ for line in lines:
pass pass
elif line.startswith( "Date:"): elif line.startswith( "Date:"):
dates.append( line[5:].lstrip() ) dates.append( line[5:].lstrip() )
pass
elif line == "" and prevLine == "": elif line == "" and prevLine == "":
pass pass
else: else:
@ -58,7 +59,7 @@ for line in lines:
else: else:
messages.append( line2 ) 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: for line in messages:
print line print(line)

View File

@ -15,7 +15,7 @@ def runAndCapture( args ):
line = "" line = ""
while True: while True:
out = child.stdout.read(1) out = child.stdout.read(1)
if out == '' and child.poll() != None: if out == '' and child.poll():
break break
if out != '': if out != '':
if out == '\n': if out == '\n':

View File

@ -12,7 +12,6 @@
# #
from __future__ import print_function from __future__ import print_function
from scriptCommon import catchPath
import argparse import argparse
import glob import glob
@ -20,6 +19,8 @@ import os
import re import re
import sys import sys
from scriptCommon import catchPath
# Configuration: # Configuration:
minTocEntries = 4 minTocEntries = 4
@ -431,7 +432,7 @@ def updateDocumentToCMain():
args = parser.parse_args() 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) changedFiles = updateDocumentToC(paths=paths, min_toc_len=args.minTocEntries, verbose=args.verbose)

View File

@ -31,7 +31,6 @@ def get_hash(path):
def update_control(path): def update_control(path):
v = Version() v = Version()
ver_string = v.getVersionString()
# Update control # Update control
lines = [] lines = []
@ -48,7 +47,6 @@ def update_control(path):
def update_portfile(path, header_hash, licence_hash): def update_portfile(path, header_hash, licence_hash):
print('Updating portfile') print('Updating portfile')
v = Version() v = Version()
ver_string = v.getVersionString()
# Update portfile # Update portfile
lines = [] lines = []

View File

@ -41,7 +41,7 @@ def uploadFiles():
'save': True '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'] return True, response['url']
else: else:
return False, response return False, response