本文整理汇总了Python中deluge_client.DelugeRPCClient.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python DelugeRPCClient.disconnect方法的具体用法?Python DelugeRPCClient.disconnect怎么用?Python DelugeRPCClient.disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类deluge_client.DelugeRPCClient
的用法示例。
在下文中一共展示了DelugeRPCClient.disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DelugeRPC
# 需要导入模块: from deluge_client import DelugeRPCClient [as 别名]
# 或者: from deluge_client.DelugeRPCClient import disconnect [as 别名]
class DelugeRPC(object):
"""Deluge RPC client class."""
def __init__(self, host='localhost', port=58846, username=None, password=None):
"""Constructor.
:param host:
:type host: str
:param port:
:type port: int
:param username:
:type username: str
:param password:
:type password: str
"""
super(DelugeRPC, self).__init__()
self.host = host
self.port = int(port)
self.username = username
self.password = password
def connect(self):
"""Connect to the host using synchronousdeluge API."""
self.client = DelugeRPCClient(self.host, self.port, self.username, self.password, decode_utf8=True)
self.client.connect()
def test(self):
"""Test connection.
:return:
:rtype: bool
"""
try:
self.connect()
except Exception:
return False
else:
return True
def remove_torrent_data(self, torrent_id):
"""Remove torrent from client using given info_hash.
:param torrent_id:
:type torrent_id: str
:return:
:rtype: str or bool
"""
try:
self.connect()
self.client.core.remove_torrent(torrent_id, True)
except Exception:
return False
else:
return True
finally:
if self.client:
self.disconnect()
def move_storage(self, torrent_id, location):
"""Move torrent to new location and return torrent id/hash.
:param torrent_id:
:type torrent_id: str
:param location:
:type location: str
:return:
:rtype: str or bool
"""
try:
self.connect()
self.client.core.move_storage(torrent_id, location)
except Exception:
return False
else:
return True
finally:
if self.client:
self.disconnect()
def add_torrent_magnet(self, torrent, options, info_hash):
"""Add Torrent magnet and return torrent id/hash.
:param torrent:
:type torrent: str
:param options:
:type options: dict
:param info_hash:
:type info_hash: str
:return:
:rtype: str or bool
"""
try:
self.connect()
torrent_id = self.client.core.add_torrent_magnet(torrent, options)
if not torrent_id:
torrent_id = self._check_torrent(info_hash)
except Exception:
raise
return False
else:
#.........这里部分代码省略.........
示例2: DelugePlugin
# 需要导入模块: from deluge_client import DelugeRPCClient [as 别名]
# 或者: from deluge_client.DelugeRPCClient import disconnect [as 别名]
class DelugePlugin(object):
"""Base class for deluge plugins, contains settings and methods for connecting to a deluge daemon."""
def on_task_start(self, task, config):
"""Raise a DependencyError if our dependencies aren't available"""
try:
from deluge_client import DelugeRPCClient
except ImportError as e:
log.debug('Error importing deluge-client: %s' % e)
raise plugin.DependencyError('deluge', 'deluge-client',
'deluge-client >=1.5 is required. `pip install deluge-client` to install.',
log)
config = self.prepare_config(config)
if config['host'] in ['localhost', '127.0.0.1'] and not config.get('username'):
# If an username is not specified, we have to do a lookup for the localclient username/password
auth = self.get_localhost_auth()
if auth and auth[0]:
config['username'], config['password'] = auth
else:
raise plugin.PluginError('Unable to get local authentication info for Deluge. You may need to '
'specify an username and password from your Deluge auth file.')
self.client = DelugeRPCClient(config['host'], config['port'], config['username'], config['password'],
decode_utf8=True)
def on_task_abort(self, task, config):
pass
def prepare_config(self, config):
config.setdefault('host', 'localhost')
config.setdefault('port', 58846)
return config
def connect(self):
"""Connects to the deluge daemon and runs on_connect_success """
self.client.connect()
if not self.client.connected:
raise plugin.PluginError('Deluge failed to connect.')
def disconnect(self):
self.client.disconnect()
def get_torrents_status(self, fields, filters=None):
"""Fetches all torrents and their requested fields optionally filtered"""
if filters is None:
filters = {}
return self.client.call('core.get_torrents_status', filters, fields)
@staticmethod
def get_localhost_auth():
if sys.platform.startswith('win'):
auth_file = os.path.join(os.getenv('APPDATA'), 'deluge', 'auth')
else:
auth_file = os.path.expanduser('~/.config/deluge/auth')
if not os.path.isfile(auth_file):
return None
with open(auth_file) as auth:
for line in auth:
line = line.strip()
if line.startswith('#') or not line:
# This is a comment or blank line
continue
lsplit = line.split(':')
if lsplit[0] == 'localclient':
username, password = lsplit[:2]
return username, password