Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
phspecs = self._placeholder_specs['torrent']
needed_keys = sum((phspec.needed_keys for phspec in phspecs), ())
if all(key in focused_item.data for key in needed_keys):
# Cached Torrent object has everything we need
data = focused_item.data
else:
# Fetch data we need for placeholders
data = await self._fetch_torrent_data(torrent_id, needed_keys)
elif isinstance(focused_list, FileListWidget):
phspecs = self._placeholder_specs['file']
# We don't need to fetch data because the file list item
# already has everything
data = focused_item.data
else:
raise CmdError(self._NOT_SUPPORTED_ERROR)
self._placeholders = {phspec.name:phspec.evaluate(data)
for phspec in phspecs}
log.debug('Placeholders: %r', self._placeholders)
return self._placeholders
from ...tui.views.setting_list import SettingListWidget
if isinstance(current_tab, TorrentListWidget):
sortcls = self.TorrentSorter
elif isinstance(current_tab, PeerListWidget):
sortcls = self.PeerSorter
elif isinstance(current_tab, TrackerListWidget):
sortcls = self.TrackerSorter
elif isinstance(current_tab, SettingListWidget):
sortcls = self.SettingSorter
else:
raise CmdError('Current tab is not sortable.')
try:
new_sort = sortcls(utils.listify_args(ORDER))
except ValueError as e:
raise CmdError(e)
if add and current_tab.sort is not None:
current_tab.sort += new_sort
else:
current_tab.sort = new_sort
def run(self, clear, next, previous, PHRASE):
from ...tui.tuiobjects import tabs
content = tabs.focus.base_widget
if not hasattr(content, 'search_phrase'):
raise CmdError('This tab does not support finding.')
elif next and previous:
raise CmdError('The options --next and --previous contradict each other.')
elif next:
if content.search_phrase is None:
raise CmdError('Set a search phrase first with `find `.')
else:
content.jump_to_next_match()
elif previous:
if content.search_phrase is None:
raise CmdError('Set a search phrase first with `find `.')
else:
content.jump_to_prev_match()
elif clear:
content.search_phrase = None
else:
try:
content.search_phrase = ' '.join(PHRASE)
content.maybe_jump_to_next_match()
except ValueError as e:
raise CmdError(e)
else:
lines.extend(l)
lines.extend(self.TOPIC_DELIMITER)
existing_topics.append(topic)
if lines:
# Remove last TOPIC_DELIMITER
for _ in range(len(self.TOPIC_DELIMITER)):
lines.pop(-1)
if not existing_topics:
existing_topics.append(__appname__)
self.display_help(existing_topics, lines)
if not success:
raise CmdError()
def run(self, clear, FILTER):
from ...tui.tuiobjects import tabs
content = tabs.focus.base_widget
if not hasattr(content, 'secondary_filter'):
raise CmdError('This tab does not support limiting.')
else:
if clear or not FILTER:
content.secondary_filter = None
else:
try:
content.secondary_filter = FILTER
except ValueError as e:
raise CmdError(e)
async def run(self, TORRENT_FILTER, PEER_FILTER, sort, columns):
columns = objects.localcfg['columns.peers'] if columns is None else columns
sort = objects.localcfg['sort.peers'] if sort is None else sort
try:
tfilter = self.select_torrents(TORRENT_FILTER,
allow_no_filter=True,
discover_torrent=True)
pfilter = self.get_peer_filter(PEER_FILTER)
sort = self.get_peer_sorter(sort)
columns = self.get_peer_columns(columns)
except ValueError as e:
raise CmdError(e)
# Unless we're listing peers of exactly one torrent, specified by its
# ID, automatically add the 'torrent' column.
if 'torrent' not in columns and \
(not isinstance(tfilter, abc.Sequence) or len(tfilter) != 1):
columns += ('torrent',)
log.debug('Listing %s peers of %s torrents', pfilter, tfilter)
if asyncio.iscoroutinefunction(self.make_peer_list):
await self.make_peer_list(tfilter, pfilter, sort, columns)
else:
self.make_peer_list(tfilter, pfilter, sort, columns)
async def run(self, TORRENT_FILTER, FILE_FILTER, columns):
columns = objects.localcfg['columns.files'] if columns is None else columns
try:
columns = self.get_file_columns(columns)
tfilter = self.select_torrents(TORRENT_FILTER,
allow_no_filter=False,
discover_torrent=True)
ffilter = self.select_files(FILE_FILTER,
allow_no_filter=True,
discover_file=False)
except ValueError as e:
raise CmdError(e)
log.debug('Listing %s files of %s torrents', ffilter, tfilter)
if asyncio.iscoroutinefunction(self.make_file_list):
await self.make_file_list(tfilter, ffilter, columns)
else:
self.make_file_list(tfilter, ffilter, columns)
def run(self, ACTION):
if len(ACTION) < 1:
raise CmdError('Missing at least one argument')
elif ACTION[0] == 'clear':
return self._do('clear', *ACTION[1:])
elif ACTION[0] == 'scroll':
return self._do('scroll', *ACTION[1:])
elif ACTION[0] == 'error':
self.error(' '.join(ACTION[1:]))
elif ACTION[0] == 'info':
self.info(' '.join(ACTION[1:]))
else:
self.info(' '.join(ACTION))
async def run(self, ACTION, TORRENT_FILTER, URL):
urls = tuple(URL)
try:
tfilter = self.select_torrents(TORRENT_FILTER,
allow_no_filter=False,
discover_torrent=True)
except ValueError as e:
raise CmdError(e)
if any(ACTION == action for action in self._ADD_ACTIONS):
request = objects.srvapi.torrent.tracker_add(tfilter, urls)
log.debug('Adding trackers to %s torrents: %s', tfilter, ', '.join(urls))
elif any(ACTION == action for action in self._REMOVE_ACTIONS):
request = objects.srvapi.torrent.tracker_remove(tfilter, urls, partial_match=True)
log.debug('Removing trackers from %s torrents: %s', tfilter, ', '.join(urls))
else:
raise CmdError('Invalid ACTION: %r' % (ACTION,))
response = await self.make_request(request, polling_frenzy=True)
if not response.success:
raise CmdError()
if ORDER:
# Find appropriate sorter class for focused list
from ...tui.views.torrent_list import TorrentListWidget
from ...tui.views.peer_list import PeerListWidget
from ...tui.views.tracker_list import TrackerListWidget
from ...tui.views.setting_list import SettingListWidget
if isinstance(current_tab, TorrentListWidget):
sortcls = self.TorrentSorter
elif isinstance(current_tab, PeerListWidget):
sortcls = self.PeerSorter
elif isinstance(current_tab, TrackerListWidget):
sortcls = self.TrackerSorter
elif isinstance(current_tab, SettingListWidget):
sortcls = self.SettingSorter
else:
raise CmdError('Current tab is not sortable.')
try:
new_sort = sortcls(utils.listify_args(ORDER))
except ValueError as e:
raise CmdError(e)
if add and current_tab.sort is not None:
current_tab.sort += new_sort
else:
current_tab.sort = new_sort