How to use the stig.objects.srvapi function in stig

To help you get started, we’ve selected a few stig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rndusr / stig / stig / main.py View on Github external
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)
github rndusr / stig / stig / hooks.py View on Github external
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')
github rndusr / stig / stig / commands / base / torrent.py View on Github external
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)
github rndusr / stig / stig / tui / hooks.py View on Github external
def _set_poll_interval(settings, name, value):
    srvapi.interval = value
localcfg.on_change(_set_poll_interval, name='tui.poll')
github rndusr / stig / stig / tui / hooks.py View on Github external
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')
github rndusr / stig / stig / commands / tui / _mixin.py View on Github external
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())
github rndusr / stig / stig / commands / base / config.py View on Github external
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)
github rndusr / stig / stig / commands / base / torrent.py View on Github external
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()