commit ab5d1043d42ee019fde0ae3de16d32ce34076d35 Author: Daniel Martí mvdan@mvdan.cc Date: Mon Aug 25 09:01:07 2014 +0200
Simplify more code by restructuring a bit --- lib/chutney/TorNet.py | 13 +++++-------- lib/chutney/Traffic.py | 10 ++-------- 2 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py index 9e07c02..1d9326d 100644 --- a/lib/chutney/TorNet.py +++ b/lib/chutney/TorNet.py @@ -601,11 +601,10 @@ class LocalNodeController(NodeController):
def cleanup_lockfile(self): lf = self._env['lockfile'] - if self.isRunning() or (not os.path.exists(lf)): - return - print 'Removing stale lock file for {0} ...'.format( - self._env['nick']) - os.remove(lf) + if not self.isRunning() and os.path.exists(lf): + print 'Removing stale lock file for {0} ...'.format( + self._env['nick']) + os.remove(lf)
def waitOnLaunch(self): """Check whether we can wait() for the tor process to launch""" @@ -776,9 +775,7 @@ class Network(object): statuses = [n.getController().check() for n in self._nodes] n_ok = len([x for x in statuses if x]) print "%d/%d nodes are running" % (n_ok, len(self._nodes)) - if n_ok != len(self._nodes): - return False - return True + return n_ok == len(self._nodes)
def restart(self): self.stop() diff --git a/lib/chutney/Traffic.py b/lib/chutney/Traffic.py index 55e75f2..56a0006 100644 --- a/lib/chutney/Traffic.py +++ b/lib/chutney/Traffic.py @@ -210,11 +210,7 @@ class Source(Peer): return 1 # Keep us around for writing.
def want_to_write(self): - if self.state == self.CONNECTING: - return True - if len(self.outbuf) > 0: - return True - return False + return self.state == self.CONNECTING or len(self.outbuf) > 0
def on_writable(self): """Invoked when the socket becomes writable. @@ -281,9 +277,7 @@ class TrafficTester(): self.pending_close.append(peer.s)
def run(self): - while True: - if self.tests.all_done() or self.timeout == 0: - break + while not self.tests.all_done() and self.timeout > 0: rset = [self.listener.fd()] + list(self.peers) wset = [p.fd() for p in filter(lambda x: x.want_to_write(), self.sources())]
tor-commits@lists.torproject.org