How to use the stig.commands.base.torrent 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 / commands / cli / torrent.py View on Github external
if torrents:
            print_table(torrents, columns, TORRENT_COLUMNS)
        else:
            raise CmdError()


class TorrentMagnetURICmd(base.TorrentMagnetURICmdbase,
                          mixin.select_torrents):
    provides = {'cli'}

    def display_uris(self, uris):
        for uri in uris:
            print(uri)


class MoveTorrentsCmd(base.MoveTorrentsCmdbase,
                      mixin.make_request, mixin.select_torrents):
    provides = {'cli'}

    @classmethod
    async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        if args.curarg_index == 1:
            log.debug('Getting torrent filter candidates from %r', candidates.torrent_filter)
            return await candidates.torrent_filter(args.curarg)
        elif args.curarg_index == 2:
            return candidates.fs_path(args.curarg.before_cursor,
                                      base=objects.remotecfg['path.complete'],
                                      directories_only=True)


class RemoveTorrentsCmd(base.RemoveTorrentsCmdbase,
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
class RenameCmd(base.RenameCmdbase,
                mixin.make_request, mixin.select_torrents, mixin.select_files):
    provides = {'cli'}


class StartTorrentsCmd(base.StartTorrentsCmdbase,
                       mixin.make_request, mixin.select_torrents):
    provides = {'cli'}


class StopTorrentsCmd(base.StopTorrentsCmdbase,
                      mixin.make_request, mixin.select_torrents):
    provides = {'cli'}


class VerifyTorrentsCmd(base.VerifyTorrentsCmdbase,
                        mixin.make_request, mixin.select_torrents):
    provides = {'cli'}
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
async def show_list_of_hits(self, tfilter):
        import sys
        if sys.stdout.isatty():
            cmd = 'ls --sort name %s' % tfilter
            await objects.cmdmgr.run_async(cmd)

    def remove_list_of_hits(self):
        pass


class RenameCmd(base.RenameCmdbase,
                mixin.make_request, mixin.select_torrents, mixin.select_files):
    provides = {'cli'}


class StartTorrentsCmd(base.StartTorrentsCmdbase,
                       mixin.make_request, mixin.select_torrents):
    provides = {'cli'}


class StopTorrentsCmd(base.StopTorrentsCmdbase,
                      mixin.make_request, mixin.select_torrents):
    provides = {'cli'}


class VerifyTorrentsCmd(base.VerifyTorrentsCmdbase,
                        mixin.make_request, mixin.select_torrents):
    provides = {'cli'}
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
class AddTorrentsCmd(base.AddTorrentsCmdbase,
                     mixin.make_request):
    provides = {'cli'}

    @classmethod
    def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        # Use current working directory as base
        return candidates.fs_path(args.curarg.before_cursor,
                                  base='.',
                                  glob=r'*.torrent')


class TorrentDetailsCmd(base.TorrentDetailsCmdbase,
                        mixin.make_request, mixin.select_torrents):
    provides = {'cli'}

    async def display_details(self, torrent_id):
        from ...views.details import SECTIONS
        needed_keys = set(('name',))
        for _section in SECTIONS:
            for _item in _section['items']:
                needed_keys.update(_item.needed_keys)

        response = await self.make_request(
            objects.srvapi.torrent.torrents((torrent_id,), keys=needed_keys),
            quiet=True)
        if not response.torrents:
            raise CmdError()
        else:
github rndusr / stig / stig / commands / tui / torrent.py View on Github external
# http://www.gnu.org/licenses/gpl-3.0.txt

from ...logging import make_logger
log = make_logger(__name__)

from ..base import torrent as base
from . import _mixin as mixin
from ... import objects
from ._common import make_tab_title_widget
from ...completion import candidates
from ...utils.cliparser import Arg
import functools
import os


class AddTorrentsCmd(base.AddTorrentsCmdbase,
                     mixin.polling_frenzy, mixin.make_request):
    provides = {'tui'}

    @staticmethod
    def make_path_absolute(path):
        if path.startswith('magnet:?'):
            return path
        else:
            # In the TUI, it makes more sense to use $HOME as the base directory for
            # relative paths instead of the current working directory.
            return os.path.join(os.environ.get('HOME', '.'),
                                os.path.normpath(os.path.expanduser(path)))

    @classmethod
    def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
mixin.make_request, mixin.select_torrents):
    provides = {'cli'}

    @classmethod
    async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        if args.curarg_index == 1:
            log.debug('Getting torrent filter candidates from %r', candidates.torrent_filter)
            return await candidates.torrent_filter(args.curarg)
        elif args.curarg_index == 2:
            return candidates.fs_path(args.curarg.before_cursor,
                                      base=objects.remotecfg['path.complete'],
                                      directories_only=True)


class RemoveTorrentsCmd(base.RemoveTorrentsCmdbase,
                        mixin.make_request, mixin.select_torrents, mixin.ask_yes_no):
    provides = {'cli'}

    async def show_list_of_hits(self, tfilter):
        import sys
        if sys.stdout.isatty():
            cmd = 'ls --sort name %s' % tfilter
            await objects.cmdmgr.run_async(cmd)

    def remove_list_of_hits(self):
        pass


class RenameCmd(base.RenameCmdbase,
                mixin.make_request, mixin.select_torrents, mixin.select_files):
    provides = {'cli'}
github rndusr / stig / stig / commands / tui / torrent.py View on Github external
mixin.ask_yes_no):
    provides = {'tui'}
    CONFIRMATION_TAB_TITLE = 'Removal Confirmation'

    async def show_list_of_hits(self, tfilter):
        from ...objects import cmdmgr
        cmd = 'tab --title %r ls --sort name %s' % (self.CONFIRMATION_TAB_TITLE, tfilter)
        await cmdmgr.run_async(cmd)

    async def remove_list_of_hits(self):
        from ...objects import cmdmgr
        cmd = 'tab --close %r --focus left' % self.CONFIRMATION_TAB_TITLE
        await cmdmgr.run_async(cmd)


class RenameCmd(base.RenameCmdbase,
                mixin.polling_frenzy, mixin.make_request, mixin.select_torrents, mixin.select_files):
    provides = {'tui'}

    @classmethod
    async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        # We don't care about options
        args = args.without_options()

        # If there is only one argument and it doesn't contain a path separator,
        # that means the user might want to rename the focused torrent, file or
        # directory.  In that case, the first argument is the destination and
        # the source is picked from the TUI.
        if len(args) == 2 and args.curarg_index == 1 and '/' not in args.curarg:
            source = cls._get_focused_item_source()
            if source is not None:
github rndusr / stig / stig / commands / tui / torrent.py View on Github external
directories_only=True)

        curarg = args.curarg
        if len(args) >= 3:
            if args.curarg_index == 1:
                return await candidates.torrent_filter(curarg)
            elif args.curarg_index == 2:
                return dest_path_candidates(curarg)
        elif len(args) == 2:
            # Single argument may be a path or a filter
            filter_cands = await candidates.torrent_filter(curarg)
            path_cands = dest_path_candidates(curarg)
            return (path_cands,) + filter_cands


class RemoveTorrentsCmd(base.RemoveTorrentsCmdbase,
                        mixin.polling_frenzy, mixin.make_request, mixin.select_torrents,
                        mixin.ask_yes_no):
    provides = {'tui'}
    CONFIRMATION_TAB_TITLE = 'Removal Confirmation'

    async def show_list_of_hits(self, tfilter):
        from ...objects import cmdmgr
        cmd = 'tab --title %r ls --sort name %s' % (self.CONFIRMATION_TAB_TITLE, tfilter)
        await cmdmgr.run_async(cmd)

    async def remove_list_of_hits(self):
        from ...objects import cmdmgr
        cmd = 'tab --close %r --focus left' % self.CONFIRMATION_TAB_TITLE
        await cmdmgr.run_async(cmd)
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details
# http://www.gnu.org/licenses/gpl-3.0.txt

from ...logging import make_logger
log = make_logger(__name__)

from ..base import torrent as base
from . import _mixin as mixin
from ... import objects
from .. import CmdError
from ._table import (print_table, TERMSIZE)
from ...completion import candidates


class AddTorrentsCmd(base.AddTorrentsCmdbase,
                     mixin.make_request):
    provides = {'cli'}

    @classmethod
    def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        # Use current working directory as base
        return candidates.fs_path(args.curarg.before_cursor,
                                  base='.',
                                  glob=r'*.torrent')


class TorrentDetailsCmd(base.TorrentDetailsCmdbase,
                        mixin.make_request, mixin.select_torrents):
    provides = {'cli'}
github rndusr / stig / stig / commands / tui / torrent.py View on Github external
title_str = self.title if hasattr(self, 'title') else None
        detailsw = TorrentDetailsWidget_keymapped(torrent_id, title=title_str)
        tabid = tabs.load(make_titlew(detailsw.title), detailsw)

        def set_tab_title(text):
            # set_title() throws IndexError if the tab was removed, which may
            # have happened while TorrentDetailsWidget was waiting for a
            # response.
            try:
                tabs.set_title(make_titlew(text), position=tabid)
            except IndexError:
                pass
        detailsw.title_updater = set_tab_title


class ListTorrentsCmd(base.ListTorrentsCmdbase,
                      mixin.select_torrents,
                      mixin.create_list_widget):
    provides = {'tui'}

    def make_torrent_list(self, tfilter, sort, columns):
        from ...tui.views.torrent_list import TorrentListWidget
        self.create_list_widget(TorrentListWidget, theme_name='torrentlist',
                                tfilter=tfilter, sort=sort, columns=columns,
                                markable_items=True)


class TorrentMagnetURICmd(base.TorrentMagnetURICmdbase,
                          mixin.select_torrents):
    provides = {'tui'}

    def display_uris(self, uris):