How to use the stig.objects.localcfg 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 / hooks.py View on Github external
from .utils import convert
from .views.torrent import COLUMNS as TORRENT_COLUMNS
from .views.file import COLUMNS as FILE_COLUMNS
from .views.peer import COLUMNS as PEER_COLUMNS


def _make_connection_callback(attr):
    def on_set(settings, name, value):
        log.debug('Setting rpc.%s=%r', attr, value)
        setattr(srvapi.rpc, attr, value)
    return on_set
localcfg.on_change(_make_connection_callback('host'),     name='connect.host',     autoremove=False)
localcfg.on_change(_make_connection_callback('port'),     name='connect.port',     autoremove=False)
localcfg.on_change(_make_connection_callback('path'),     name='connect.path',     autoremove=False)
localcfg.on_change(_make_connection_callback('user'),     name='connect.user',     autoremove=False)
localcfg.on_change(_make_connection_callback('password'), name='connect.password', autoremove=False)
localcfg.on_change(_make_connection_callback('tls'),      name='connect.tls',      autoremove=False)
localcfg.on_change(_make_connection_callback('timeout'),  name='connect.timeout',  autoremove=False)


_BANDWIDTH_COLUMNS = (TORRENT_COLUMNS['rate-up'], TORRENT_COLUMNS['rate-down'],
                      TORRENT_COLUMNS['limit-rate-up'], TORRENT_COLUMNS['limit-rate-down'],
                      PEER_COLUMNS['rate-up'], PEER_COLUMNS['rate-down'], PEER_COLUMNS['rate-est'])
def _set_bandwidth_unit(settings, name, value):
    convert.bandwidth.unit = value
    unit_short = convert.bandwidth.unit
    for column in _BANDWIDTH_COLUMNS:
        column.set_unit(unit_short)
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_bandwidth_unit, name='unit.bandwidth')
github rndusr / stig / stig / tui / main.py View on Github external
def run(command_runner):
    """
    Run commands and start TUI

    Return False if any of the commands failed, True otherwise.
    """
    from .. import objects
    from .import tuiobjects

    # Don't catch theme.ParserError - a broken default theme should make us
    # croak obviously and horribly
    tuiobjects.theme.init(objects.localcfg.default('tui.theme'), tuiobjects.urwidscreen)

    # Load tui-specific hooks before commands run (commands may trigger hooks)
    from . import hooks

    try:
        if not command_runner():
            return False
    # Make 'quit' behave as expected
    except urwid.ExitMainLoop:
        return True

    # Load/Download GeoIP database
    if objects.geoip.available and objects.localcfg['geoip']:
        tuiobjects.load_geoip_db()

    # Start logging to TUI widget instead of stdout/stderr
github rndusr / stig / stig / tui / miscwidgets.py View on Github external
def _mk_tail_canv(self, direction, icon):
        unit = {'bit': 'b', 'byte': 'B'}[objects.localcfg['unit.bandwidth']]
        text = urwid.Text('%s/s%s' % (unit, icon))
        attr_text = urwid.AttrMap(text, 'bottombar.bandwidth.%s' % direction)
        return attr_text.render((self._TAIL_WIDTH,))
github rndusr / stig / stig / tui / hooks.py View on Github external
try:
        tuiobjects.theme.load(value.full_path, tuiobjects.urwidscreen)
    except tuiobjects.theme.ThemeError as e:
        raise ValueError(e)
localcfg.on_change(_set_theme, name='tui.theme')


def _set_tui_marked_char(methodname, settings, name, value):
    getattr(TORRENT_COLUMNS['marked'], methodname)(value)
    getattr(FILE_COLUMNS['marked'], methodname)(value)
    for widget in tuiobjects.tabs:
        if isinstance(widget, (TorrentListWidget, FileListWidget)):
            widget.refresh_marks()
localcfg.on_change(partial(_set_tui_marked_char, 'set_marked_char'), name='tui.marked.on', autoremove=False)
localcfg.on_change(partial(_set_tui_marked_char, 'set_unmarked_char'), name='tui.marked.off', autoremove=False)
_set_tui_marked_char('set_marked_char', localcfg, name='tui.marked.on', value=localcfg['tui.marked.on'])
_set_tui_marked_char('set_unmarked_char', localcfg, name='tui.marked.off', value=localcfg['tui.marked.off'])


def _update_quickhelp(keymap):
    tuiobjects.topbar.help.update()
tuiobjects.keymap.on_bind_unbind(_update_quickhelp)


def _set_geoip(settings, name, value):
    if value:
        tuiobjects.load_geoip_db()
localcfg.on_change(_set_geoip, name='geoip')
github rndusr / stig / stig / commands / base / _mixin.py View on Github external
def get_setting_columns(self, columns):
        """
        Check if each item in iterable `columns` is a valid setting list column name

        Raise ValueError or return a new list of `columns`.
        """
        return objects.localcfg.validate('columns.settings', columns)
github rndusr / stig / stig / tui / hooks.py View on Github external
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')


def _set_poll_interval(settings, name, value):
    srvapi.interval = value
localcfg.on_change(_set_poll_interval, name='tui.poll')


def _set_cli_history_dir(settings, name, value):
    tuiobjects.cli.original_widget.history_file = os.path.join(value.full_path, 'commands')
localcfg.on_change(_set_cli_history_dir, name='tui.cli.history-dir')

def _set_cli_history_size(settings, name, value):
    tuiobjects.cli.original_widget.history_size = value
localcfg.on_change(_set_cli_history_size, name='tui.cli.history-size')


def _set_autohide_delay(settings, name, value):
    tuiobjects.logwidget.autohide_delay = value
localcfg.on_change(_set_autohide_delay, name='tui.log.autohide')
github rndusr / stig / stig / views / peer.py View on Github external
def get_cli_value(self):
        from ..objects import localcfg
        if localcfg['reverse-dns']:
            from ..client import rdns
            return rdns.gethostbyaddr(self.data['ip'])
        return self.data['ip']