From bdb42af31624b7dde0f76cdffafd24d7c456585d Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Tue, 3 Jun 2014 16:00:17 +0200 Subject: [PATCH] Run autopep8 on all Python files This change should be a functional no-op. TODO: script this into the git commit process or at least into the source tarball creation step. --- transonic.py | 34 ++++++++++++++++++---------------- transonic2.py | 29 +++++++++++++++++------------ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/transonic.py b/transonic.py index a114827..4946ead 100755 --- a/transonic.py +++ b/transonic.py @@ -32,7 +32,9 @@ class Pingresult: + """Encapsulate one ping result, including RTT et al""" + def __init__(self, hostname="UNKNOWN", pstats=None, rtt=None, retval=-1): self.hostname = hostname self.retval = retval @@ -47,8 +49,8 @@ def __init__(self, hostname="UNKNOWN", pstats=None, rtt=None, retval=-1): def __str__(self): return ("%s S%s/R%s, maMD: %s/%s/%s/%s" % - (self.hostname, self.pstats.txcount, self.pstats.rxcount, - self.rtt.rmin, self.rtt.ravg, self.rtt.rmax, self.rtt.rmdev)) + (self.hostname, self.pstats.txcount, self.pstats.rxcount, + self.rtt.rmin, self.rtt.ravg, self.rtt.rmax, self.rtt.rmdev)) def eprint(fmt, *args): @@ -79,8 +81,8 @@ def pinger(host, count): (retval, output) = subprocess.getstatusoutput(cmd) for line in output.split("\n"): - #print(line) - if line[2:2+len("packets transmitted")] == "packets transmitted": + # print(line) + if line[2:2 + len("packets transmitted")] == "packets transmitted": stats = line.split() if "errors," in stats: pstat = __Pingstats__(int(stats[0]), int(stats[3]), @@ -95,8 +97,8 @@ def pinger(host, count): r_min, r_avg, r_max, r_mdev = rtts.split("/") rtts = __RTTstats__(r_min, r_avg, r_max, r_mdev) continue - res = Pingresult(host, pstat, rtts, retval) - #print(res) + res = Pingresult(host, pstat, rtts, retval) + # print(res) return res @@ -105,6 +107,7 @@ def frl_list(resultlist, _): return "\n".join(str(x) for x in resultlist) FORMATTERS["list"] = frl_list + def frl_cell(resultlist, replies): """ Format the resultlist as "cells" @@ -124,7 +127,7 @@ def frl_cell(resultlist, replies): else: counts[0] += 1 res.append(pres.hostname) - return " ".join(res)+"\n%i up, %i down" % (counts[0], counts[1]) + return " ".join(res) + "\n%i up, %i down" % (counts[0], counts[1]) FORMATTERS["cell"] = frl_cell @@ -143,7 +146,7 @@ def frl_ccell(resultlist, replies): else: counts[0] += 1 res.append(".") - return "".join(res)+"\n%i up, %i down" % (counts[0], counts[1]) + return "".join(res) + "\n%i up, %i down" % (counts[0], counts[1]) FORMATTERS["ccell"] = frl_ccell @@ -185,8 +188,8 @@ def main(): print_version() sys.exit(0) - cmdp = argparse.ArgumentParser(description= - 'Ping hosts in parallel and show results') + cmdp = argparse.ArgumentParser( + description='Ping hosts in parallel and show results') cmdp.add_argument('targets', metavar='target', nargs='+', help='Hostname or IPv4 to ping') cmdp.add_argument('--count', "-c", metavar='count', default=5, type=int, @@ -200,9 +203,9 @@ def main(): 'Note: the actual number will be the minimum of this and ' 'the number of hosts to ping') cmdp.add_argument('--mode', '-m', metavar='mode', - help='Output mode, one of %s (list)' % - (", ".join(sorted(FORMATTERS.keys()))), - choices=FORMATTERS.keys(), default='list') + help='Output mode, one of %s (list)' % + (", ".join(sorted(FORMATTERS.keys()))), + choices=FORMATTERS.keys(), default='list') cmdp.add_argument('--terse', '-t', default=False, action="store_true", help='Terse output. This will not ' 'output anything except whatever the result formatter ' @@ -216,7 +219,6 @@ def main(): 'number of replies, even if larger than number of ' 'requests sent.') - args = cmdp.parse_args() TERSE = args.terse @@ -239,10 +241,10 @@ def main(): ppinger = partial(pinger, count=args.count) results = pool.map(ppinger, args.targets) end = time.time() - #print(results) + # print(results) print(formatresultlist(results, args.mode, args.replies)) eprint("Time taken: %.3f seconds (%.3f per host)" % - (end-start, (end-start)/len(args.targets))) + (end - start, (end - start) / len(args.targets))) if __name__ == "__main__": diff --git a/transonic2.py b/transonic2.py index 52654cd..e6958cb 100755 --- a/transonic2.py +++ b/transonic2.py @@ -32,10 +32,13 @@ __RTTstats__ = namedtuple('__RTTstats__', "rmin ravg rmax rmdev") # The next two functions make partial() objects pickleable in 2.6 + + def _pickle_partial(obj): """Pickle a functools.partial()""" return _unpickle_partial, (obj.func, obj.args, obj.keywords) + def _unpickle_partial(func, args, keywords): """Unpickle a functools.partial()""" # pylint: disable-msg=W0142 @@ -47,7 +50,9 @@ def _unpickle_partial(func, args, keywords): class Pingresult: + """Encapsulate one ping result, including RTT et al""" + def __init__(self, hostname="UNKNOWN", pstats=None, rtt=None): self.hostname = hostname if pstats: @@ -61,8 +66,8 @@ def __init__(self, hostname="UNKNOWN", pstats=None, rtt=None): def __str__(self): return ("%s S%s/R%s, maMD: %s/%s/%s/%s" % - (self.hostname, self.pstats.txcount, self.pstats.rxcount, - self.rtt.rmin, self.rtt.ravg, self.rtt.rmax, self.rtt.rmdev)) + (self.hostname, self.pstats.txcount, self.pstats.rxcount, + self.rtt.rmin, self.rtt.ravg, self.rtt.rmax, self.rtt.rmdev)) def eprint(fmt, *args): @@ -92,18 +97,18 @@ def pinger(host, count): cmd = ['ping', '-W', '1', '-c', str(count), '-q', host] pcomm = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - output, _ = pcomm.communicate() # we drop stderr and ignore it + output, _ = pcomm.communicate() # we drop stderr and ignore it # pylint gets confused here; pylint: disable-msg=E1103 for line in output.split("\n"): - if line[2:2+len("packets transmitted")] == "packets transmitted": + if line[2:2 + len("packets transmitted")] == "packets transmitted": stats = line.split() if "errors," in stats: pstat = __Pingstats__(int(stats[0]), int(stats[3]), - int(stats[7][:-1]), int(stats[11][:-2])) + int(stats[7][:-1]), int(stats[11][:-2])) else: pstat = __Pingstats__(int(stats[0]), int(stats[3]), - int(stats[5][:-1]), int(stats[9][:-2])) + int(stats[5][:-1]), int(stats[9][:-2])) continue if line.startswith("rtt min/avg/max/mdev"): @@ -111,8 +116,8 @@ def pinger(host, count): r_min, r_avg, r_max, r_mdev = rtts.split("/") rtts = __RTTstats__(r_min, r_avg, r_max, r_mdev) continue - res = Pingresult(host, pstat, rtts) - #print(res) + res = Pingresult(host, pstat, rtts) + # print(res) return res @@ -141,7 +146,7 @@ def frl_cell(resultlist, replies): else: counts[0] += 1 res.append(pres.hostname) - return " ".join(res)+"\n%i up, %i down" % (counts[0], counts[1]) + return " ".join(res) + "\n%i up, %i down" % (counts[0], counts[1]) FORMATTERS["cell"] = frl_cell @@ -160,7 +165,7 @@ def frl_ccell(resultlist, replies): else: counts[0] += 1 res.append(".") - return "".join(res)+"\n%i up, %i down" % (counts[0], counts[1]) + return "".join(res) + "\n%i up, %i down" % (counts[0], counts[1]) FORMATTERS["ccell"] = frl_ccell @@ -253,10 +258,10 @@ def main(): start = time.time() results = pool.map(ppinger, arguments) end = time.time() - #print(results) + # print(results) print(formatresultlist(results, opts.mode, opts.replies)) eprint("Time taken: %.3f seconds (%.3f per host)" % - (end-start, (end-start)/len(arguments))) + (end - start, (end - start) / len(arguments))) if __name__ == "__main__": main()