From 88447385c26a412e968f4e404b40b64edfb62386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 18 Oct 2013 17:35:59 +0200 Subject: [PATCH] autopep8 formatting --- tools/argparse.py | 27 +++++--- tools/daca2-report.py | 120 ++++++++++++++++++------------------ tools/daca2.py | 6 +- tools/extracttests.py | 53 ++++++++++------ tools/test_matchcompiler.py | 34 ++++++---- 5 files changed, 142 insertions(+), 98 deletions(-) diff --git a/tools/argparse.py b/tools/argparse.py index 32d948c03..fd7e23fed 100644 --- a/tools/argparse.py +++ b/tools/argparse.py @@ -130,7 +130,9 @@ _UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args' # Utility functions and classes # ============================= + class _AttributeHolder(object): + """Abstract base class that provides __repr__. The __repr__ method returns a string in the format:: @@ -166,6 +168,7 @@ def _ensure_value(namespace, name, value): # =============== class HelpFormatter(object): + """Formatter for generating usage messages and argument help strings. Only the name of this class is considered a public API. All the methods @@ -639,13 +642,14 @@ class HelpFormatter(object): def _fill_text(self, text, width, indent): text = self._whitespace_matcher.sub(' ', text).strip() return _textwrap.fill(text, width, initial_indent=indent, - subsequent_indent=indent) + subsequent_indent=indent) def _get_help_string(self, action): return action.help class RawDescriptionHelpFormatter(HelpFormatter): + """Help message formatter which retains any formatting in descriptions. Only the name of this class is considered a public API. All the methods @@ -657,6 +661,7 @@ class RawDescriptionHelpFormatter(HelpFormatter): class RawTextHelpFormatter(RawDescriptionHelpFormatter): + """Help message formatter which retains formatting of all help text. Only the name of this class is considered a public API. All the methods @@ -668,6 +673,7 @@ class RawTextHelpFormatter(RawDescriptionHelpFormatter): class ArgumentDefaultsHelpFormatter(HelpFormatter): + """Help message formatter which adds default values to argument help. Only the name of this class is considered a public API. All the methods @@ -692,7 +698,7 @@ def _get_action_name(argument): if argument is None: return None elif argument.option_strings: - return '/'.join(argument.option_strings) + return '/'.join(argument.option_strings) elif argument.metavar not in (None, SUPPRESS): return argument.metavar elif argument.dest not in (None, SUPPRESS): @@ -702,6 +708,7 @@ def _get_action_name(argument): class ArgumentError(Exception): + """An error from creating or using an argument (optional or positional). The string value of this exception is the message, augmented with @@ -722,6 +729,7 @@ class ArgumentError(Exception): class ArgumentTypeError(Exception): + """An error from trying to convert a command line string to a type.""" pass @@ -731,6 +739,7 @@ class ArgumentTypeError(Exception): # ============== class Action(_AttributeHolder): + """Information about how to convert command line strings to Python objects. Action objects are used by an ArgumentParser to represent the information @@ -1108,7 +1117,8 @@ class _SubParsersAction(Action): # parse all the remaining options into the namespace # store any unrecognized options on the object, so that the top # level parser can decide what to do with them - namespace, arg_strings = parser.parse_known_args(arg_strings, namespace) + namespace, arg_strings = parser.parse_known_args( + arg_strings, namespace) if arg_strings: vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, []) getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings) @@ -1119,6 +1129,7 @@ class _SubParsersAction(Action): # ============== class FileType(object): + """Factory for creating file object types Instances of FileType are typically passed as type= arguments to the @@ -1161,7 +1172,9 @@ class FileType(object): # Optional and Positional Parsing # =========================== + class Namespace(_AttributeHolder): + """Simple object for storing attributes. Implements equality by attribute names and values, and provides a simple @@ -1263,7 +1276,6 @@ class _ActionsContainer(object): return action.default return self._defaults.get(dest, None) - # ======================= # Adding argument actions # ======================= @@ -1535,6 +1547,7 @@ class _MutuallyExclusiveGroup(_ArgumentGroup): class ArgumentParser(_AttributeHolder, _ActionsContainer): + """Object for parsing command line strings into Python objects. Keyword Arguments: @@ -1610,12 +1623,12 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): default_prefix = prefix_chars[0] if self.add_help: self.add_argument( - default_prefix+'h', default_prefix*2+'help', + default_prefix + 'h', default_prefix * 2 + 'help', action='help', default=SUPPRESS, help=_('show this help message and exit')) if self.version: self.add_argument( - default_prefix+'v', default_prefix*2+'version', + default_prefix + 'v', default_prefix * 2 + 'version', action='version', default=SUPPRESS, version=self.version, help=_("show program's version number and exit")) @@ -2075,7 +2088,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): # if multiple actions match, the option string was ambiguous if len(option_tuples) > 1: options = ', '.join([option_string - for action, option_string, explicit_arg in option_tuples]) + for action, option_string, explicit_arg in option_tuples]) tup = arg_string, options self.error(_('ambiguous option: %s could match %s') % tup) diff --git a/tools/daca2-report.py b/tools/daca2-report.py index 2e1aa958d..2a7d2b7cd 100644 --- a/tools/daca2-report.py +++ b/tools/daca2-report.py @@ -2,33 +2,34 @@ import os import sys + def readdate(data): - datepos = -1 - if data[:5] == 'DATE ': - datepos = 0 - else: - datepos = data.find('\nDATE ') - if datepos >= 0: - datepos = datepos + 1 + datepos = -1 + if data[:5] == 'DATE ': + datepos = 0 + else: + datepos = data.find('\nDATE ') + if datepos >= 0: + datepos = datepos + 1 - if datepos < 0: - return None + if datepos < 0: + return None - datestr = '' - datepos = datepos + 5 - while True: - if datepos >= len(data): - return None - d = data[datepos] - if d>='0' and d<='9': - datestr = datestr + d - elif d=='\n': - if len(datestr) == 8: - return datestr[:4] + '-' + datestr[4:6] + '-' + datestr[6:] - return None - elif d!=' ' and d!='-': - return None - datepos = datepos + 1 + datestr = '' + datepos = datepos + 5 + while True: + if datepos >= len(data): + return None + d = data[datepos] + if d >= '0' and d <= '9': + datestr = datestr + d + elif d == '\n': + if len(datestr) == 8: + return datestr[:4] + '-' + datestr[4:6] + '-' + datestr[6:] + return None + elif d != ' ' and d != '-': + return None + datepos = datepos + 1 path = '.' if len(sys.argv) == 2: @@ -46,47 +47,48 @@ recent = [] daca2 = os.path.expanduser('~/daca2/') for lib in range(2): - for a in "0123456789abcdefghijklmnopqrstuvwxyz": - if lib == 1: - a = "lib" + a - if os.path.isfile(daca2 + a + '/results.txt'): - f = open(daca2 + a + '/results.txt', 'rt') - data = f.read() - f.close() + for a in "0123456789abcdefghijklmnopqrstuvwxyz": + if lib == 1: + a = "lib" + a + if os.path.isfile(daca2 + a + '/results.txt'): + f = open(daca2 + a + '/results.txt', 'rt') + data = f.read() + f.close() - datestr = readdate(data) - if datestr: - if not lastupdate or datestr > lastupdate: - lastupdate = datestr - recent = [] - if datestr == lastupdate: - recent.append(a) + datestr = readdate(data) + if datestr: + if not lastupdate or datestr > lastupdate: + lastupdate = datestr + recent = [] + if datestr == lastupdate: + recent.append(a) - mainpage.write(''+a+'
\n') + mainpage.write( + '' + a + '
\n') - data = data.replace('&', ' ') - data = data.replace('<', '<') - data = data.replace('>', '>') - data = data.replace('\'', ''') - data = data.replace('"', '"') - data = data.replace('\n', '\n') + data = data.replace('&', ' ') + data = data.replace('<', '<') + data = data.replace('>', '>') + data = data.replace('\'', ''') + data = data.replace('"', '"') + data = data.replace('\n', '\n') - f = open(path+'/daca2-'+a+'.html', 'wt') - f.write('\n') - f.write('DACA2 - ' + a + '\n') - f.write('\n') - f.write('

DACA2 - ' + a + '

') - f.write('
\n' + data + '
\n') - f.write('\n') - f.write('\n') - f.close() + f = open(path + '/daca2-' + a + '.html', 'wt') + f.write('\n') + f.write('DACA2 - ' + a + '\n') + f.write('\n') + f.write('

DACA2 - ' + a + '

') + f.write('
\n' + data + '
\n') + f.write('\n') + f.write('\n') + f.close() if lastupdate: - mainpage.write('

Last update: ' + lastupdate + '

') - allrecent = '' - for r in recent: - allrecent = allrecent + ' ' + r + '' - mainpage.write('

Most recently updated: ' + allrecent + '

') + mainpage.write('

Last update: ' + lastupdate + '

') + allrecent = '' + for r in recent: + allrecent = allrecent + ' ' + r + '' + mainpage.write('

Most recently updated: ' + allrecent + '

') mainpage.write('\n') mainpage.write('\n') diff --git a/tools/daca2.py b/tools/daca2.py index 31d7d1666..146fc74aa 100644 --- a/tools/daca2.py +++ b/tools/daca2.py @@ -21,6 +21,7 @@ FTPSERVER = 'ftp.sunet.se' FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/' FOLDER = 'b' + def handleRemoveReadonly(func, path, exc): import stat if not os.access(path, os.W_OK): @@ -30,6 +31,7 @@ def handleRemoveReadonly(func, path, exc): else: raise + def removeAllExceptResults(): count = 5 while count > 0: @@ -63,9 +65,10 @@ def removeAllExceptResults(): continue count = 0 + def removeLargeFiles(path): for g in glob.glob(path + '*'): - if g=='.' or g=='..': + if g == '.' or g == '..': continue if os.path.isdir(g): removeLargeFiles(g + '/') @@ -74,6 +77,7 @@ def removeLargeFiles(path): if statinfo.st_size > 100000: os.remove(g) + def scanarchive(fullpath): results = open('results.txt', 'at') results.write(fullpath + '\n') diff --git a/tools/extracttests.py b/tools/extracttests.py index 640e6dd70..d6eb2690b 100755 --- a/tools/extracttests.py +++ b/tools/extracttests.py @@ -27,6 +27,7 @@ import re class Extract: + """ Read Cppcheck test file and create data representation @@ -50,7 +51,7 @@ class Extract: fin = open(filename, 'r') for line in fin: # testclass starts - res = re.match('class ('+name+')', line) + res = re.match('class (' + name + ')', line) if res is not None: testclass = res.group(1) @@ -59,7 +60,7 @@ class Extract: testclass = None # function start - res = re.match('\\s+void ('+name+')\\(\\)', line) + res = re.match('\\s+void (' + name + ')\\(\\)', line) if res is not None: functionName = res.group(1) @@ -70,12 +71,12 @@ class Extract: continue # check - res = re.match('\s+check.*\('+string, line) + res = re.match('\s+check.*\(' + string, line) if res is not None: code = res.group(1) # code.. - res = re.match('\\s+'+string, line) + res = re.match('\\s+' + string, line) if res is not None: code = code + res.group(1) @@ -114,7 +115,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly): fout.write('\n') fout.write(' \n') @@ -123,9 +125,10 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly): fout.write('Home -- ') if errorsOnly: - fout.write('All test cases') + fout.write('All test cases') else: - fout.write('Error test cases') + fout.write( + 'Error test cases') fout.write('

') testclass = None @@ -138,13 +141,17 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly): if not testclass: testclass = node['testclass'] - fout.write('

' + node['testclass'] + '::' + functionName + '

') + fout.write( + '

' + node['testclass'] + '::' + functionName + '

') fout.write('\n') - fout.write(' \n') + fout.write( + ' \n') fout.write(' ') - fout.write('') - fout.write('') + fout.write('') + fout.write( + '') fout.write('\n') if testclass is not None: @@ -155,7 +162,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly): if len(sys.argv) <= 1 or '--help' in sys.argv: print ('Extract test cases from test file') - print ('Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp') + print ( + 'Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp') sys.exit(0) # parse command line @@ -189,7 +197,7 @@ if filename is not None: print ('') count = 0 for node in e.nodes: - s = ' \n') findex.write('
NrCodeExpected
NrCodeExpected
' + str(num) + '
' + strtoxml(node['code']).replace('\\n', '\n') + '
' + strtoxml(node['expected']).replace('\\n', '
') + '
' + strtoxml(
+                node['code']).replace('\\n', '\n') + '
' + strtoxml(node['expected']).replace('\\n', '
') + '