playerdo / playerdo /

from playerdo.backends import *
from playerdo.backends.base import Player
from playerdo.utils import PlayerException
import sys

def get_running_players(players):
    Given a list of Player classes, returns a list of players (instances) that
    are running, sorted by priority they should be tried.

    # Get running players
    running_ps = []
    for P in players:
        p = P()
            running = p.is_running()
            if running:
        except NotImplementedError:

    # Try to find out which one is playing
    state = []
    for p in running_ps:
            is_stopped = p.is_stopped()
        except NotImplementedError:
            is_stopped = None

        if is_stopped == True:
        elif is_stopped == False:
            # In-between value for unknowns, because a player that is
            # definitely stopped is less preferred than one that *might* be
            # playing.

    l = zip(state, running_ps)

    return [x[1] for x in l]

def do_test(players):
    Checks that all backends have required dependencies, printing any failures
    for P in players:
        p = P()
        failures = p.check_dependencies()
        if len(failures) > 0:
            sys.stdout.write("Player '%s' has missing dependencies:\n" % p.friendly_name)
            for l in failures:
                sys.stdout.write("  " + l + "\n")

def do_command(command, 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")

    # Use the first one
    player = candidates[0]
    except NotImplementedError:
        sys.stderr.write("Operation '%s' not supported for player '%s'.\n" %
                         (command, player.friendly_name))
    except PlayerException, e:
        sys.stderr.write(e.message + "\n")

def find_players():
    return [v for v in globals().values()
            if type(v) is type and issubclass(v, Player)]
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
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.