Renamed ls function to get_all. Also updated the remove function to delete by id, not name and to have better error handling and reporting.

This commit is contained in:
2018-05-06 18:04:48 +02:00
parent a6198e0b5c
commit 0230298479

View File

@@ -98,7 +98,7 @@ class Deluge(object):
if (url.startswith('magnet')): if (url.startswith('magnet')):
return self.client.call('core.add_torrent_magnet', url, {}) return self.client.call('core.add_torrent_magnet', url, {})
def ls(self, _filter=None): def get_all(self, _filter=None):
if (type(_filter) is list and len(_filter)): if (type(_filter) is list and len(_filter)):
if ('seeding' in _filter): if ('seeding' in _filter):
response = self.client.call('core.get_torrents_status', {'state': 'Seeding'}, []) response = self.client.call('core.get_torrents_status', {'state': 'Seeding'}, [])
@@ -113,7 +113,7 @@ class Deluge(object):
def search(self, query): def search(self, query):
q_list = split_words(query) q_list = split_words(query)
return [ t for t in self.ls() if (set(q_list) <= set(split_words(t.name))) ] return [ t for t in self.get_all() if (set(q_list) <= set(split_words(t.name))) ]
def get(self, id): def get(self, id):
response = self.client.call('core.get_torrent_status', id, {}) response = self.client.call('core.get_torrent_status', id, {})
@@ -128,15 +128,17 @@ class Deluge(object):
print('Response:', response) print('Response:', response)
def remove(self, name): def remove(self, torrent_id):
for torrent in self.ls(): for torrent in self.get_all():
if (name == torrent.name): if (torrent_id == torrent.key):
response = self.client.call('core.remove_torrent', torrent.id, False) response = self.client.call('core.remove_torrent', torrent.key, False)
logger.info('Response: ', response) logger.info('Response: {}'.format(str(response)))
break
if (response == False): if (response == False):
raise AttributeError('Unable to remove torrent.') raise AttributeError('Unable to remove torrent.')
return response
logger.error('ERROR: No torrent found with that id.')
def status(self): def status(self):
response = self.client.call('core.get_torrents_status', {}, ['progress']) response = self.client.call('core.get_torrents_status', {}, ['progress'])
@@ -251,7 +253,7 @@ def main():
elif arguments['ls']: elif arguments['ls']:
logger.info('List cmd selected') logger.info('List cmd selected')
[ pprint(t.toJSON()) for t in deluge.ls(_filter=_filter) ] [ pprint(t.toJSON()) for t in deluge.get_all(_filter=_filter) ]
elif arguments['toggle']: elif arguments['toggle']:
logger.info('Toggling id: {}'.format(_id)) logger.info('Toggling id: {}'.format(_id))