Browse Source

Simplify more code by restructuring a bit

Daniel Martí 9 years ago
parent
commit
ab5d1043d4
2 changed files with 7 additions and 16 deletions
  1. 5 8
      lib/chutney/TorNet.py
  2. 2 8
      lib/chutney/Traffic.py

+ 5 - 8
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()

+ 2 - 8
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())]