def get_session_stats(): try: check_preallocation() except PreallocationException: raise logger.info('Will attempt to get session stats') return util.object_to_json(rpc.session_stats())
def add_torrent_magnet_link(magnet_link): try: check_preallocation() except PreallocationException: raise logger.info('Got magnet_link: "%s"', magnet_link) added_torrent = rpc.add_torrent(magnet_link) json_torrent_data = util.object_to_json(added_torrent) logger.debug('Added torrent data:\n%s', json.dumps(json_torrent_data)) return json_torrent_data
def get_torrent_info_by_id(ids): try: check_preallocation() except PreallocationException: raise ids = handle_ids_argument(ids) logger.info('Will attempt to get information for torrents with ids: %s', json.dumps(ids)) return [util.object_to_json(x) for x in rpc.get_torrents(ids)]
def pause_torrent(hash_or_id): try: check_preallocation() except PreallocationException: raise if util.is_hash_not_id(hash_or_id): logger.debug('%s seems to be a torrent hash. Proceeding...', hash_or_id) hash_or_id = torrent_hash_to_id(hash_or_id) else: logger.debug('%s seems to be a torrent id. Proceeding...', hash_or_id) return util.object_to_json(rpc.get_torrents(hash_or_id)[0])
def on_close(self): WSHandler.clients.remove(self) WSHandler.broadcast(object_to_json(CloseData(id(self))))
def open(self): WSHandler.clients.add(self) self.write_message(object_to_json(InitData(id(self))))
def initialize(): global rpc logger.info('Initializing Transmission Daemon Driver module at [%s:%s]', TRANSMISSION_DAEMON_HOSTNAME, TRANSMISSION_DAEMON_PORT) rpc = transmissionrpc.Client(address=TRANSMISSION_DAEMON_HOSTNAME, port=TRANSMISSION_DAEMON_PORT) logger.debug('Initialized session information:\n%s', json.dumps(util.object_to_json(rpc.get_session()))) logger.debug('RPC timeout: %s', rpc.timeout)