From 07b43c69291e48a179f89bec2287a2c62fae8687 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 23 Jul 2016 14:44:05 +0300 Subject: [PATCH] Ran autopep8. --- addons/cppcheckdata.py | 23 +-- addons/y2038/y2038.py | 8 +- tools/daca2.py | 2 +- tools/reduce.py | 380 ++++++++++++++++++++--------------------- tools/rundaca2.py | 12 +- tools/times-vs.py | 41 +++-- 6 files changed, 233 insertions(+), 233 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index e5cb5bfce..6ae232884 100644 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -578,10 +578,11 @@ class CppCheckFormatter(argparse.HelpFormatter): ''' Properly formats multiline argument helps ''' + def _split_lines(self, text, width): # this is the RawTextHelpFormatter._split_lines if text.startswith('R|'): - return text[2:].splitlines() + return text[2:].splitlines() return argparse.HelpFormatter._split_lines(self, text, width) def ArgumentParser(): @@ -591,20 +592,20 @@ def ArgumentParser(): ''' parser = argparse.ArgumentParser(formatter_class=CppCheckFormatter) parser.add_argument('-t', '--template', metavar='', - default='{callstack}: ({severity}) {message}', - help="R|Format the error messages. E.g.\n" \ - "'{file}:{line},{severity},{id},{message}' or\n" \ - "'{file}({line}):({severity}) {message}' or\n" \ - "'{callstack} {message}'\n" \ - "Pre-defined templates: gcc, vs, edit") + default='{callstack}: ({severity}) {message}', + help="R|Format the error messages. E.g.\n" + "'{file}:{line},{severity},{id},{message}' or\n" + "'{file}({line}):({severity}) {message}' or\n" + "'{callstack} {message}'\n" + "Pre-defined templates: gcc, vs, edit") return parser # Format an error message. - + def reportError(template, callstack=[], severity='', message='', id=''): ''' Format an error message according to the template. - + :param template: format string, or 'gcc', 'vs' or 'edit'. :param callstack: e.g. [['file1.cpp',10],['file2.h','20'], ... ] :param severity: e.g. 'error', 'warning' ... @@ -619,9 +620,9 @@ def reportError(template, callstack=[], severity='', message='', id=''): elif template == 'edit': template = '{file} +{line}: {severity}: {message}' # compute 'callstack}, {file} and {line} replacements - stack = ' -> '.join(['['+f+':'+str(l)+']' for (f,l) in callstack]) + stack = ' -> '.join(['[' + f + ':' + str(l) + ']' for (f, l) in callstack]) file = callstack[-1][0] line = str(callstack[-1][1]) # format message return template.format(callstack=stack, file=file, line=line, - severity=severity, message=message, id=id) + severity=severity, message=message, id=id) diff --git a/addons/y2038/y2038.py b/addons/y2038/y2038.py index 06b6c97b2..a5f16c38d 100644 --- a/addons/y2038/y2038.py +++ b/addons/y2038/y2038.py @@ -198,7 +198,7 @@ def find_dump_files(paths): for (top, subdirs, files) in os.walk(path): for file in files: if file.endswith('.dump'): - f = top+'/'+file + f = top + '/' + file if not f in dumpfiles: dumpfiles.append(f) dumpfiles.sort() @@ -212,9 +212,9 @@ def find_dump_files(paths): parser = cppcheckdata.ArgumentParser() parser.add_argument('-q', '--quiet', action='store_true', - help='do not print "Checking ..." lines') + help='do not print "Checking ..." lines') parser.add_argument('paths', nargs='+', metavar='path', - help='path to dump file or directory') + help='path to dump file or directory') # parse command line @@ -258,7 +258,7 @@ for dumpfile in dumpfiles: safe = int(srclinenr) # warn about _TIME_BITS not being defined if time_bits_defined == False: - reportDirDiag(args.template, + reportDirDiag(args.template, cfg, srcfile, srclinenr, directive, 'warning', '_USE_TIME_BITS64 is defined but _TIME_BITS was not') elif re_undef_use_time_bits64.match(directive.str): diff --git a/tools/daca2.py b/tools/daca2.py index c81d250ec..ef6d2d86c 100644 --- a/tools/daca2.py +++ b/tools/daca2.py @@ -150,7 +150,7 @@ def scanarchive(filepath, jobs): removeLargeFiles('') - print(strfCurrTime('[%H:%M] cppcheck ' ) + filename) + print(strfCurrTime('[%H:%M] cppcheck ') + filename) p = subprocess.Popen( ['nice', diff --git a/tools/reduce.py b/tools/reduce.py index 6da9c5355..6aaba3fb9 100644 --- a/tools/reduce.py +++ b/tools/reduce.py @@ -9,224 +9,224 @@ SEGFAULT = False FILE = None BACKUPFILE = None for arg in sys.argv[1:]: - if arg.startswith('--cmd='): - CMD = arg[arg.find('=')+1:] - elif arg.startswith('--expected='): - EXPECTED = arg[arg.find('=')+1:] - elif arg.startswith('--file='): - FILE = arg[arg.find('=')+1:] - BACKUPFILE = FILE + '.bak' - elif arg == '--segfault': - SEGFAULT = True + if arg.startswith('--cmd='): + CMD = arg[arg.find('=') + 1:] + elif arg.startswith('--expected='): + EXPECTED = arg[arg.find('=') + 1:] + elif arg.startswith('--file='): + FILE = arg[arg.find('=') + 1:] + BACKUPFILE = FILE + '.bak' + elif arg == '--segfault': + SEGFAULT = True if CMD is None: - print('Abort: No --cmd') - sys.exit(1) + print('Abort: No --cmd') + sys.exit(1) if SEGFAULT == False and EXPECTED is None: - print('Abort: No --expected') - sys.exit(1) + print('Abort: No --expected') + sys.exit(1) if FILE is None: - print('Abort: No --file') - sys.exit(1) + print('Abort: No --file') + sys.exit(1) -print('CMD='+CMD) +print('CMD=' + CMD) if SEGFAULT: - print('EXPECTED=SEGFAULT') + print('EXPECTED=SEGFAULT') else: - print('EXPECTED='+EXPECTED) -print('FILE='+FILE) + print('EXPECTED=' + EXPECTED) +print('FILE=' + FILE) def runtool(): - p = subprocess.Popen(CMD.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - comm = p.communicate() - if SEGFAULT: - if p.returncode != 0: - return True - elif p.returncode == 0: - out = comm[0] + '\n' + comm[1] - if (out.find('error:') < 0) and (out.find(EXPECTED) > 0): - return True - return False + p = subprocess.Popen(CMD.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + comm = p.communicate() + if SEGFAULT: + if p.returncode != 0: + return True + elif p.returncode == 0: + out = comm[0] + '\n' + comm[1] + if (out.find('error:') < 0) and (out.find(EXPECTED) > 0): + return True + return False def writefile(filename, filedata): - f = open(filename, 'wt') - for line in filedata: - f.write(line) - f.close() + f = open(filename, 'wt') + for line in filedata: + f.write(line) + f.close() def replaceandrun(what, filedata, i, line): - print(what + ' ' + str(i+1) + '/' + str(len(filedata)) + '..') - bak = filedata[i] - filedata[i] = line - writefile(FILE, filedata) - if runtool() == True: - print('pass') - writefile(BACKUPFILE, filedata) - return True - print('fail') - filedata[i] = bak - return False + print(what + ' ' + str(i + 1) + '/' + str(len(filedata)) + '..') + bak = filedata[i] + filedata[i] = line + writefile(FILE, filedata) + if runtool() == True: + print('pass') + writefile(BACKUPFILE, filedata) + return True + print('fail') + filedata[i] = bak + return False def replaceandrun2(what, filedata, i, line1, line2): - print(what + ' ' + str(i+1) + '/' + str(len(filedata)) + '..') - bak1 = filedata[i] - bak2 = filedata[i+1] - filedata[i] = line1 - filedata[i+1] = line2 - writefile(FILE, filedata) - if runtool() == True: - print('pass') - writefile(BACKUPFILE, filedata) - else: - print('fail') - filedata[i] = bak1 - filedata[i+1] = bak2 + print(what + ' ' + str(i + 1) + '/' + str(len(filedata)) + '..') + bak1 = filedata[i] + bak2 = filedata[i + 1] + filedata[i] = line1 + filedata[i + 1] = line2 + writefile(FILE, filedata) + if runtool() == True: + print('pass') + writefile(BACKUPFILE, filedata) + else: + print('fail') + filedata[i] = bak1 + filedata[i + 1] = bak2 def clearandrun(what, filedata, i1, i2): - print(what + ' ' + str(i1+1) + '/' + str(len(filedata)) + '..') - filedata2 = list(filedata) - i = i1 - while i <= i2 and i < len(filedata2): - filedata2[i] = '' - i = i + 1 - writefile(FILE, filedata2) - if runtool() == True: - print('pass') - writefile(BACKUPFILE, filedata2) - return filedata2 - print('fail') - return filedata + print(what + ' ' + str(i1 + 1) + '/' + str(len(filedata)) + '..') + filedata2 = list(filedata) + i = i1 + while i <= i2 and i < len(filedata2): + filedata2[i] = '' + i = i + 1 + writefile(FILE, filedata2) + if runtool() == True: + print('pass') + writefile(BACKUPFILE, filedata2) + return filedata2 + print('fail') + return filedata def removecomments(filedata): - for i in range(len(filedata)): - line = filedata[i] - if line.find('//') >= 0: - replaceandrun('remove comment', filedata, i, line[:line.find('//')].rstrip()) + for i in range(len(filedata)): + line = filedata[i] + if line.find('//') >= 0: + replaceandrun('remove comment', filedata, i, line[:line.find('//')].rstrip()) def checkpar(line): - par = 0 - for c in line: - if c=='(' or c=='[': - par = par + 1 - elif c==')' or c==']': - par = par - 1 - if par<0: - return False - return par == 0 + par = 0 + for c in line: + if c == '(' or c == '[': + par = par + 1 + elif c == ')' or c == ']': + par = par - 1 + if par < 0: + return False + return par == 0 def combinelines(filedata): - if len(filedata) < 3: - return + if len(filedata) < 3: + return - lines = [] + lines = [] - for i in range(len(filedata)-1): - fd1 = filedata[i].rstrip() - if fd1.endswith(','): - fd2 = filedata[i+1].lstrip() - if fd2 != '': - lines.append(i) + for i in range(len(filedata) - 1): + fd1 = filedata[i].rstrip() + if fd1.endswith(','): + fd2 = filedata[i + 1].lstrip() + if fd2 != '': + lines.append(i) - chunksize = len(lines) - while chunksize > 10: - i = 0 - while i < len(lines): - i1 = i - i2 = i + chunksize - i = i2 - if i2 > len(lines): - i2 = len(lines) + chunksize = len(lines) + while chunksize > 10: + i = 0 + while i < len(lines): + i1 = i + i2 = i + chunksize + i = i2 + if i2 > len(lines): + i2 = len(lines) - filedata2 = list(filedata) - for line in lines[i1:i2]: - filedata2[line] = filedata2[line].rstrip() + filedata2[line+1].lstrip() - filedata2[line+1] = '' + filedata2 = list(filedata) + for line in lines[i1:i2]: + filedata2[line] = filedata2[line].rstrip() + filedata2[line + 1].lstrip() + filedata2[line + 1] = '' - if replaceandrun('combine lines', filedata2, lines[i1]+1, ''): - filedata = filedata2 - lines[i1:i2] = [] - i = i1 + if replaceandrun('combine lines', filedata2, lines[i1] + 1, ''): + filedata = filedata2 + lines[i1:i2] = [] + i = i1 - chunksize = chunksize / 2 + chunksize = chunksize / 2 - for line in lines: - fd1 = filedata[line].rstrip() - fd2 = filedata[line+1].lstrip() - replaceandrun2('combine lines', filedata, line, fd1+fd2, '') + for line in lines: + fd1 = filedata[line].rstrip() + fd2 = filedata[line + 1].lstrip() + replaceandrun2('combine lines', filedata, line, fd1 + fd2, '') def removedirectives(filedata): - for i in range(len(filedata)): - if filedata[i].lstrip().startswith('#'): - replaceandrun('remove preprocessor directive', filedata, i, '') + for i in range(len(filedata)): + if filedata[i].lstrip().startswith('#'): + replaceandrun('remove preprocessor directive', filedata, i, '') def removeblocks(filedata): - if len(filedata) < 3: + if len(filedata) < 3: + return filedata + + for i in range(len(filedata)): + strippedline = filedata[i].strip() + if len(strippedline) == 0: + continue + if ';{}'.find(strippedline[-1]) < 0: + continue + + i1 = i + 1 + while i1 < len(filedata) and filedata[i1].startswith('#'): + i1 = i1 + 1 + + i2 = i1 + indent = 0 + while i2 < len(filedata): + for c in filedata[i2]: + if c == '}': + indent = indent - 1 + if indent == 0: + indent = -100 + elif c == '{': + indent = indent + 1 + if indent < 0: + break + i2 = i2 + 1 + if indent == -100: + indent = 0 + if i2 == i1 or i2 >= len(filedata): + continue + if filedata[i2].strip() != '}' and filedata[i2].strip() != '};': + continue + if indent < 0: + i2 = i2 - 1 + filedata = clearandrun('remove codeblock', filedata, i1, i2) + return filedata - - for i in range(len(filedata)): - strippedline = filedata[i].strip() - if len(strippedline)==0: - continue - if ';{}'.find(strippedline[-1]) < 0: - continue - - i1 = i + 1 - while i1 < len(filedata) and filedata[i1].startswith('#'): - i1 = i1 + 1 - - i2 = i1 - indent = 0 - while i2 < len(filedata): - for c in filedata[i2]: - if c == '}': - indent = indent - 1 - if indent == 0: - indent = -100 - elif c == '{': - indent = indent + 1 - if indent < 0: - break - i2 = i2 + 1 - if indent == -100: - indent = 0 - if i2 == i1 or i2 >= len(filedata): - continue - if filedata[i2].strip() != '}' and filedata[i2].strip() != '};': - continue - if indent < 0: - i2 = i2 - 1 - filedata = clearandrun('remove codeblock', filedata, i1, i2) - - return filedata def removeline(filedata): - stmt = True - for i in range(len(filedata)): - line = filedata[i] - strippedline = line.strip() + stmt = True + for i in range(len(filedata)): + line = filedata[i] + strippedline = line.strip() - if len(strippedline) == 0: - continue + if len(strippedline) == 0: + continue - if stmt and strippedline[-1]==';' and checkpar(line) and line.find('{')<0 and line.find('}')<0: - replaceandrun('remove line', filedata, i, '') + if stmt and strippedline[-1] == ';' and checkpar(line) and line.find('{') < 0 and line.find('}') < 0: + replaceandrun('remove line', filedata, i, '') - elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1: - replaceandrun('remove line', filedata, i, '') + elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1: + replaceandrun('remove line', filedata, i, '') - if ';{}'.find(strippedline[-1]) >= 0: - stmt = True - else: - stmt = False + if ';{}'.find(strippedline[-1]) >= 0: + stmt = True + else: + stmt = False # reduce.. print('Make sure error can be reproduced...') if runtool() == False: - print("Cannot reproduce") - sys.exit(1) + print("Cannot reproduce") + sys.exit(1) f = open(FILE, 'rt') filedata = f.readlines() @@ -235,31 +235,31 @@ f.close() writefile(BACKUPFILE, filedata) while True: - filedata1 = list(filedata) + filedata1 = list(filedata) - print('remove comments...') - removecomments(filedata) + print('remove comments...') + removecomments(filedata) - print('remove preprocessor directives...') - removedirectives(filedata) + print('remove preprocessor directives...') + removedirectives(filedata) - print('remove blocks...') - filedata = removeblocks(filedata) + print('remove blocks...') + filedata = removeblocks(filedata) - print('combine lines..') - combinelines(filedata) + print('combine lines..') + combinelines(filedata) - print('remove line...') - removeline(filedata) + print('remove line...') + removeline(filedata) - # if filedata and filedata2 are identical then stop - if len(filedata1) == len(filedata): - i = 0 - while i < len(filedata1): - if filedata[i] != filedata1[i]: - break - i = i + 1 - if i == len(filedata1): - break + # if filedata and filedata2 are identical then stop + if len(filedata1) == len(filedata): + i = 0 + while i < len(filedata1): + if filedata[i] != filedata1[i]: + break + i = i + 1 + if i == len(filedata1): + break writefile(FILE, filedata) diff --git a/tools/rundaca2.py b/tools/rundaca2.py index f51313767..7efe29c9d 100644 --- a/tools/rundaca2.py +++ b/tools/rundaca2.py @@ -10,12 +10,12 @@ import sys START = 0 PASSWORD = '' for arg in sys.argv[1:]: - if len(arg)==1: - START = '0123456789abcdefghijklmnopqrstuvwxyz'.find(arg) - if START < 0: - START = 0 - else: - PASSWORD = arg + if len(arg) == 1: + START = '0123456789abcdefghijklmnopqrstuvwxyz'.find(arg) + if START < 0: + START = 0 + else: + PASSWORD = arg # Upload file to sourceforge web server using scp def upload(file_to_upload, destination): diff --git a/tools/times-vs.py b/tools/times-vs.py index 2e542af82..30093b4d9 100644 --- a/tools/times-vs.py +++ b/tools/times-vs.py @@ -21,20 +21,20 @@ import re import sys if len(sys.argv) != 2: - print('revisions not specified') - sys.exit(1) + print('revisions not specified') + sys.exit(1) res = re.match(r'([0-9]+):([0-9]+)', sys.argv[1]) if res is None: - print('invalid format, 11111:22222') - sys.exit(1) + print('invalid format, 11111:22222') + sys.exit(1) rev1 = int(res.group(1)) rev2 = int(res.group(2)) -if rev1>rev2 or rev1<10000 or rev2>20000 or rev2-rev1>500: - print('range, aborting') - sys.exit(1) +if rev1 > rev2 or rev1 < 10000 or rev2 > 20000 or rev2 - rev1 > 500: + print('range, aborting') + sys.exit(1) print('Revisions: ' + str(rev1) + ':' + str(rev2)) @@ -42,17 +42,16 @@ f = open('results.txt', 'wt') f.write('\n') f.close() -for rev in range(rev1,rev2): - subprocess.call(['svn', 'revert', '-R', '.']) - subprocess.call(['svn', 'up', '-r' + str(rev)]) - for vcxproj in glob.glob('*/*.vcxproj'): - subprocess.call([r'c:\cygwin64\bin\sed.exe', '-i', 's/140/120/', vcxproj]) - subprocess.call('msbuild cppcheck.sln /t:build /p:configuration=Release,platform=x64'.split()) - print('Revision:' + str(rev)) - p = subprocess.Popen(r'bin\cppcheck.exe src -q --showtime=summary'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - comm = p.communicate() - f = open('results.txt', 'at') - f.write('\nREV ' + str(rev) + '\n') - f.write(comm[0].decode('utf-8')) - f.close() - +for rev in range(rev1, rev2): + subprocess.call(['svn', 'revert', '-R', '.']) + subprocess.call(['svn', 'up', '-r' + str(rev)]) + for vcxproj in glob.glob('*/*.vcxproj'): + subprocess.call([r'c:\cygwin64\bin\sed.exe', '-i', 's/140/120/', vcxproj]) + subprocess.call('msbuild cppcheck.sln /t:build /p:configuration=Release,platform=x64'.split()) + print('Revision:' + str(rev)) + p = subprocess.Popen(r'bin\cppcheck.exe src -q --showtime=summary'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + comm = p.communicate() + f = open('results.txt', 'at') + f.write('\nREV ' + str(rev) + '\n') + f.write(comm[0].decode('utf-8')) + f.close()