def hEntryPlaying(self, _, entry, ed): """ Message Bus handler """ self.TrackChange(ed) def sRateCurrentPlaying(self, rating): """ DBus signal handler - /Player/RateCurrentPlaying """ Bus.publish(self, "rate-current", rating) player=hPlayer() Bus.subscribe("entry-playing", player.hEntryPlaying) dbus.Bus().add_signal_receiver(player.sRateCurrentPlaying, signal_name="RateCurrentPlaying", dbus_interface="org.freedesktop.MediaPlayer", bus_name=None, path="/Player") class hTrack(dbus.service.Object): """ DBus signals for the /Track path """ PATH="/Track" def __init__(self): dbus.service.Object.__init__(self, dbus.SessionBus(), self.PATH)
""" Performs 'dependency checks' of the received parameters against the 'root parameters' """ for key in iparams: if key in self.rootParams: self._updateParams({"auth_token":"", "token":""}) self.q_user_params() break ## ========================================================== Bus Interfacing user=User() Bus.subscribe("user_params?", user.q_user_params) Bus.subscribe("user_params", user.h_user_params) Bus.subscribe("method_call", user.h_method_call) ## ========================================================== TESTS if __name__ == '__main__': class Logger(object): def __call__(self, msgType, e): print "Logger: Error: msgType(%s) Exception(%s)" % (msgType, str(e)) class Test(object): def handler(self, msgType, params): print params Bus.logger=Logger()
print "setRating: exception(%s)" % str(e) def setRatings(self, entries, rating): """ Set the rating of a batch of entries """ def _rate(model, _path, iter): entry = model.get(iter, 0)[0] self.db.set(entry, rhythmdb.PROP_RATING, rating) entries.foreach(_rate) th = TrackHelper() Bus.subscribe("db", th.hDb) class TrackHandler(object): def __init__(self, trackHelper): self.th = trackHelper self.currentEntry = None def hEntryPlaying(self, _, entry, _entryDic): """ Intercepts the current playing entry """ self.currentEntry = entry def hRateCurrent(self, _, rating): """
""" @author: jldupont Created on 2010-02-01 """ from twisted.python import log from mbus import Bus class Logger(object): """ Simple Logger """ def _log(self, _, _msg): log.msg(_msg) logger=Logger() Bus.subscribe("log", logger._log)
if ws_method.is_error(): cdic["e"](["error", ws_method.get_error()]) return ctx=(ws_method.method, cdic, udic) make_ws_request(ctx, ws_method.url, http_method=ws_method.http_method, postdata=ws_method.body) def _session_required_flow(self, mdic, cdic, udic): """ A session must be authenticated before calling the method We need to have a "token" as starting point """ #Bus.publish(self, "log", "_session_required_flow: mdic(%s)" % mdic) auth_token=udic.get("auth_token", "") if not auth_token: cdic["e"](["error", "session_required"]) return cdic.update({"original_mdic":mdic}) Bus.publish(self, "method_call", {"method":"auth.getSession"}, cdic) wsh=WsMethodHandler() Bus.subscribe("umethod_call", wsh.h_umethod_call) ## Test string for 'track.getTags' #"depeche mode", "little 15"
self.db.set(entry, rhythmdb.PROP_RATING, fvalue) except: print "setRating: expecting a float for 'rating', got: %s" % rating def setRatings(self, entries, rating): """ """ def _rate(model, _path, iter): entry=model.get(iter, 0)[0] self.db.set(entry, rhythmdb.PROP_RATING, rating) entries.foreach(_rate) th=TrackHelper() Bus.subscribe("db", th.hDb) class TrackHandler(object): def __init__(self, trackHelper): self.th=trackHelper self.currentEntry=None def hEntryPlaying(self, _, entry): """ Intercepts the current playing entry """ self.currentEntry=entry
Bus.publish(self, "log", "h_auth_gettoken, status: %s" % status) if status!="200": cdic["e"](["error", "method_failed", "Cannot retrieve 'auth token' from Last.fm"]) return if not response: cdic["e"](["error", "invalid_response", "Invalid response received from Last.fm"]) return match=re.search("\<token\>(.*)\<\/token\>", response) if match is None: cdic["e"](["error", "token_missing", "Missing 'auth token' from Last.fm response"]) return auth_token=match.group(1) Bus.publish(self, "user_params", {"auth_token":auth_token, "token":""}) api_key=udic.get("api_key", "") ## Return URL that must be used by the user for authentication ## =========================================================== url=self.auth_url % (api_key, auth_token) cdic["c"](["ok", url]) wsrh=WsResponseHandler() Bus.subscribe("ws_response", wsrh.h_ws_response)