diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
commit | 2e2851dc13d73352530dd4495c7e05603b2e520d (patch) | |
tree | 622b9cd8e5d32091c9aa9e4937b533975a40356c /deluge/ui/console/cmdline/commands/rm.py | |
parent | Initial commit. (diff) | |
download | deluge-ba36a3baaa52c6e8dc58a724548d75d3db6e8ef9.tar.xz deluge-ba36a3baaa52c6e8dc58a724548d75d3db6e8ef9.zip |
Adding upstream version 2.1.2~dev0+20240219.upstream/2.1.2_dev0+20240219upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'deluge/ui/console/cmdline/commands/rm.py')
-rw-r--r-- | deluge/ui/console/cmdline/commands/rm.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/deluge/ui/console/cmdline/commands/rm.py b/deluge/ui/console/cmdline/commands/rm.py new file mode 100644 index 0000000..4a3fd00 --- /dev/null +++ b/deluge/ui/console/cmdline/commands/rm.py @@ -0,0 +1,82 @@ +# +# Copyright (C) 2008-2009 Ido Abramovich <ido.deluge@gmail.com> +# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +import logging + +import deluge.component as component +from deluge.ui.client import client + +from . import BaseCommand + +log = logging.getLogger(__name__) + + +class Command(BaseCommand): + """Remove a torrent""" + + aliases = ['del'] + + def add_arguments(self, parser): + parser.add_argument( + '--remove_data', + action='store_true', + default=False, + help=_('Also removes the torrent data'), + ) + parser.add_argument( + '-c', + '--confirm', + action='store_true', + default=False, + help=_('List the matching torrents without removing.'), + ) + parser.add_argument( + 'torrent_ids', + metavar='<torrent-id>', + nargs='+', + help=_('One or more torrent ids'), + ) + + def handle(self, options): + self.console = component.get('ConsoleUI') + torrent_ids = self.console.match_torrents(options.torrent_ids) + + if not options.confirm: + self.console.write( + '{!info!}%d %s %s{!info!}' + % ( + len(torrent_ids), + _n('torrent', 'torrents', len(torrent_ids)), + _n('match', 'matches', len(torrent_ids)), + ) + ) + for t_id in torrent_ids: + name = self.console.get_torrent_name(t_id) + self.console.write('* %-50s (%s)' % (name, t_id)) + self.console.write( + _('Confirm with -c to remove the listed torrents (Count: %d)') + % len(torrent_ids) + ) + return + + def on_removed_finished(errors): + if errors: + self.console.write( + 'Error(s) occurred when trying to delete torrent(s).' + ) + for t_id, e_msg in errors: + self.console.write(f'Error removing torrent {t_id} : {e_msg}') + + log.info('Removing %d torrents', len(torrent_ids)) + d = client.core.remove_torrents(torrent_ids, options.remove_data) + d.addCallback(on_removed_finished) + + def complete(self, line): + # We use the ConsoleUI torrent tab complete method + return component.get('ConsoleUI').tab_complete_torrent(line) |