Commits

Luke Plant committed 3e2bf1a

Optimisation - avoid calling is_running() twice on every player.

Comments (0)

Files changed (1)

 
     return [x[2] for x in l]
 
-def get_running_players(players):
-    """
-    Given a list of Player classes, returns a list of players (instances) that
-    are running.
-    """
-    # Get running players
-    running_ps = []
-    for p in players:
-        try:
-            running = p.is_running()
-            if running:
-                running_ps.append(p)
-        except NotImplementedError:
-            pass
-
-    return running_ps
 
 def do_test(players):
     """
     """
     Execute the given command, given a list of Player classes
     """
-    candidates = get_running_players(players)
-    if len(candidates) == 0:
-        sys.stderr.write("No players running!\n")
-        sys.exit(1)
+    for player in players:
+        try:
+            if not player.is_running():
+                continue
+        except NotImplementedError:
+            continue
 
-    # Use the first one
-    player = candidates[0]
-    try:
-        player.do_command(command)
-    except NotImplementedError:
-        sys.stderr.write("Operation '%s' not supported for player '%s'.\n" %
-                         (command, player.friendly_name))
-        sys.exit(1)
-    except PlayerException, e:
-        sys.stderr.write(e.message + "\n")
-        sys.exit(1)
+        # Use the first one
+        try:
+            player.do_command(command)
+            return
+        except NotImplementedError:
+            sys.stderr.write("Operation '%s' not supported for player '%s'.\n" %
+                             (command, player.friendly_name))
+            sys.exit(1)
+        except PlayerException, e:
+            sys.stderr.write(e.message + "\n")
+            sys.exit(1)
+    sys.stderr.write("No players running!\n")
+    sys.exit(1)
+
 
 def find_players():
     return sort_players([v() for v in globals().values()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.