Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except geoip.GeoIPError as e:
log.error(e)
exit_code = 1
try:
if not run_commands():
exit_code = 1
except KeyboardInterrupt:
log.debug('Caught SIGINT')
elif cmdmgr.active_interface == 'tui':
from .tui import main as tui
if not tui.run(run_commands):
exit_code = 1
aioloop.run_until_complete(srvapi.rpc.disconnect('Quit'))
# We're not calling aioloop.close() here because it sometimes complains
# about unfinished tasks and not calling it seems to work fine.
sys.exit(exit_code)
def _set_size_prefix(settings, name, value):
convert.size.prefix = value
for column in _SIZE_COLUMNS:
column.clearcache()
srvapi.torrent.clearcache()
srvapi.poll()
localcfg.on_change(_set_size_prefix, name='unitprefix.size')
async def run(self, TORRENT_FILTER):
try:
tfilter = self.select_torrents(TORRENT_FILTER,
allow_no_filter=False,
discover_torrent=True,
prefer_focused=False)
except ValueError as e:
raise CmdError(e)
else:
try:
uris = await objects.srvapi.torrent.get_magnet_uris(tfilter)
except objects.srvapi.ClientError as e:
raise CmdError(e)
else:
self.display_uris(uris)
def _set_poll_interval(settings, name, value):
srvapi.interval = value
localcfg.on_change(_set_poll_interval, name='tui.poll')
def _reconnect(settings, name, value):
# See also ..hooks
log.debug('Reconnecting because %s changed to %r', name, value)
srvapi.poll()
localcfg.on_change(_reconnect, name='connect.host')
localcfg.on_change(_reconnect, name='connect.port')
localcfg.on_change(_reconnect, name='connect.path')
localcfg.on_change(_reconnect, name='connect.user')
localcfg.on_change(_reconnect, name='connect.password')
localcfg.on_change(_reconnect, name='connect.tls')
def _update_pollers(rpc):
srvapi.poll()
srvapi.rpc.on('connected', _update_pollers)
srvapi.rpc.on('disconnected', _update_pollers)
def _refresh_lists(settings, name, value):
for widget in tuiobjects.tabs:
if isinstance(widget, (TorrentListWidget, FileListWidget, PeerListWidget)):
widget.clear()
widget.refresh()
localcfg.on_change(_refresh_lists, name='unit.bandwidth')
localcfg.on_change(_refresh_lists, name='unit.size')
localcfg.on_change(_refresh_lists, name='unitprefix.bandwidth')
localcfg.on_change(_refresh_lists, name='unitprefix.size')
localcfg.on_change(_refresh_lists, name='reverse-dns')
localcfg.on_change(_refresh_lists, name='geoip')
async def coro():
log.debug('Setting poll interval to %s for %s seconds', short_interval, duration)
orig_interval = objects.srvapi.interval
objects.srvapi.interval = short_interval
import asyncio
await asyncio.sleep(duration, loop=objects.aioloop)
objects.srvapi.interval = orig_interval
log.debug('Interval restored to %s', objects.srvapi.interval)
objects.aioloop.create_task(coro())
async def _set_global_limits(self, directions, limit, quiet=False, adjust=False):
for d in directions:
log.debug('Setting global %s rate limit: %r', d, limit)
set_method = getattr(objects.srvapi.settings,
('adjust' if adjust else 'set') + '_limit_rate_' + d)
get_method = getattr(objects.srvapi.settings, 'get_limit_rate_' + d)
try:
try:
await set_method(limit)
except ValueError as e:
raise CmdError('%s: %r' % (e, limit))
if not quiet:
limit = await get_method()
self.info('Global %sload rate limit: %s' % (d, limit))
except ClientError as e:
raise CmdError(e)
discover_torrent=True)
except ValueError as e:
raise CmdError(e)
else:
async def do_remove(tfilter=tfilter, delete_files=delete_files):
response = await self.make_request(
objects.srvapi.torrent.remove(tfilter, delete=delete_files),
polling_frenzy=True)
if not response.success:
raise CmdError()
async def do_keep(tfilter=tfilter):
self.error(('Keeping %s torrents: Too many hits ' % tfilter) +
'(use --force or increase remove.max-hits setting)')
response = await objects.srvapi.torrent.torrents(tfilter, keys=('id',))
hits = len(response.torrents)
success = hits > 0
if force or objects.localcfg['remove.max-hits'] < 0 or hits < objects.localcfg['remove.max-hits']:
return await do_remove()
else:
await self.show_list_of_hits(tfilter)
if hits > 0:
question = 'Are you sure you want to remove %d torrent%s' % (
hits, '' if hits == 1 else 's')
if delete_files:
question += ' and their files'
question += '?'
success = await self.ask_yes_no(question, yes=do_remove, no=do_keep,
after=self.remove_list_of_hits)
if not success:
raise CmdError()