From 2e21cd93a5c3b3b8402c31cc2f47a6b70b044d8f Mon Sep 17 00:00:00 2001 From: "adrian.sampson" Date: Fri, 3 Apr 2009 09:19:29 +0000 Subject: [PATCH] password half-implemented --HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40167 --- beets/player/bpd.py | 16 +++++++++++----- bts | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/beets/player/bpd.py b/beets/player/bpd.py index 8abd96827..1d0298b5d 100755 --- a/beets/player/bpd.py +++ b/beets/player/bpd.py @@ -44,6 +44,11 @@ ERROR_EXIST = 56 VOLUME_MIN = 0 VOLUME_MAX = 100 +SAFE_COMMANDS = ( + # Commands that should be available when unauthenticated. + 'close', 'commands', 'notcommands', 'password', 'ping', +) + # Logger. log = logging.getLogger('bpd') @@ -169,11 +174,12 @@ class BaseServer(object): This is a generic superclass and doesn't support many commands. """ - def __init__(self, host='', port=DEFAULT_PORT): + def __init__(self, host='', port=DEFAULT_PORT, password=''): """Create a new server bound to address `host` and listening - on port `port`. + on port `port`. If `password` is given, it is required to do + anything significant on the server. """ - self.host, self.port = host, port + self.host, self.port, self.password = host, port, password # Default server values. self.random = False @@ -644,9 +650,9 @@ class Server(BaseServer): to store its library. """ - def __init__(self, library, host='', port=DEFAULT_PORT): + def __init__(self, library, host='', port=DEFAULT_PORT, password=''): from beets.player.gstplayer import GstPlayer - super(Server, self).__init__(host, port) + super(Server, self).__init__(host, port, password) self.lib = library self.player = GstPlayer(self.play_finished) diff --git a/bts b/bts index 01e34d590..9b1f496ed 100755 --- a/bts +++ b/bts @@ -11,6 +11,7 @@ CONFIG_DEFAULTS = { # bpd 'host': '', 'port': '6600', + 'password': '', } CONFIG_FILE = os.path.expanduser('~/.beetsrc') @@ -73,9 +74,10 @@ def bpd(lib, config, opts): host = host if host else config.get('bpd', 'host') port = int(opts.pop(0)) if opts else None port = port if port else config.getint('bpd', 'port') + password = config.get('bpd', 'password') from beets.player.bpd import Server - Server(lib, host, port).run() + Server(lib, host, port, password).run() if __name__ == "__main__": # parse options