pyrocore.scripts package

Basic Command Line Scripts.

Copyright (c) 2009 The PyroScope Project <pyroscope.project@gmail.com>

Submodules

pyrocore.scripts.base module

Command Line Script Support.

Copyright (c) 2009, 2010 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.base.PromptDecorator(script_obj)[source]

Bases: object

Decorator for interactive commands.

QUIT_RC = 75
add_options()[source]

Add program options, must be called in script’s addOptions().

ask_bool(question, default=True)[source]

Ask the user for Y)es / N)o / Q)uit.

If “Q” ist entered, this method will exit with RC=3. Else, the user’s choice is returned.

Note that the options –non-interactive and –defaults also influence the outcome.

quit()[source]

Exit the program due to user’s choices.

class pyrocore.scripts.base.ScriptBase[source]

Bases: object

Base class for command line interfaces.

ADDITIONAL_HELP = []
ARGS_HELP = '<log-base>...'
COPYRIGHT = 'Copyright (c) 2009 - 2018 Pyroscope Project'
LOGGING_CFG = '~/.pyroscope/logging.%s.ini'
STD_LOG_LEVEL = 20
VERSION = None
add_bool_option(*args, **kwargs)[source]

Add a boolean option.

@keyword help: Option description.

add_options()[source]

Add program options.

add_value_option(*args, **kwargs)[source]

Add a value option.

@keyword dest: Destination attribute, derived from long option name if not given. @keyword action: How to handle the option. @keyword help: Option description. @keyword default: If given, add this value to the help string.

fatal(msg, exc=None)[source]

Exit on a fatal error.

get_options()[source]

Get program options.

handle_completion()[source]

Handle shell completion stuff.

help_completion_options()[source]

Return options of this command.

mainloop()[source]

The main loop.

run()[source]

The main program skeleton.

classmethod setup(cron_cfg='cron')[source]

Set up the runtime environment.

class pyrocore.scripts.base.ScriptBaseWithConfig[source]

Bases: pyrocore.scripts.base.ScriptBase

CLI tool with configuration support.

CONFIG_DIR_DEFAULT = '~/.pyroscope'
OPTIONAL_CFG_FILES = []
add_options()[source]

Add configuration options.

get_options()[source]

Get program options.

pyrocore.scripts.chtor module

Metafile Editor.

Copyright (c) 2010 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.chtor.MetafileChanger[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Change attributes of a bittorrent metafile.

ARGS_HELP = '<metafile>...'
RT_RESUMT_KEYS = ('libtorrent_resume', 'log_callback', 'err_callback', 'rtorrent')
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

pyrocore.scripts.chtor.replace_fields(meta, patterns)[source]

Replace patterns in fields.

pyrocore.scripts.chtor.run()[source]

The entry point.

pyrocore.scripts.hashcheck module

Metafile Checker.

Copyright (c) 2011 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.hashcheck.MetafileChecker[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Check a bittorrent metafile.

ARGS_HELP = '<metafile> [<data-dir-or-file>]'
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

pyrocore.scripts.hashcheck.run()[source]

The entry point.

pyrocore.scripts.lstor module

Metafile Lister.

Copyright (c) 2009, 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.lstor.MetafileLister[source]

Bases: pyrocore.scripts.base.ScriptBase

List contents of a bittorrent metafile.

ARGS_HELP = '<metafile>...'
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

pyrocore.scripts.lstor.run()[source]

The entry point.

pyrocore.scripts.mktor module

Metafile Creator.

Copyright (c) 2009, 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.mktor.MetafileCreator[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Create a bittorrent metafile.

If passed a magnet URI as the only argument, a metafile is created in the directory specified via the configuration value ‘magnet_watch’, loadable by rTorrent. Which means you can register ‘mktor’ as a magnet: URL handler in Firefox.

ARGS_HELP = '<dir-or-file> <tracker-url-or-alias>... | <magnet-uri>'
ENTROPY_BITS = 512
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

make_magnet_meta(magnet_uri)[source]

Create a magnet-uri torrent.

pyrocore.scripts.mktor.run()[source]

The entry point.

pyrocore.scripts.pyroadmin module

Administration Tool.

Copyright (c) 2010 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.pyroadmin.AdminTool[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Support for administrative tasks.

ARGS_HELP = u''
CONFIG_DIRS = [u'log', u'data', u'run', u'htdocs']
OPTIONAL_CFG_FILES = [u'torque.ini']
RC_CONTINUATION_THRESHOLD = 50
add_options()[source]

Add program options.

download_resource(download_url, target, guard)[source]

Helper to download and install external resources.

mainloop()[source]

The main loop.

pyrocore.scripts.pyroadmin.run()[source]

The entry point.

pyrocore.scripts.pyrotorque module

rTorrent queue manager & daemon.

Copyright (c) 2012 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.pyrotorque.RtorrentQueueManager[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

rTorrent queue manager & daemon.

ARGS_HELP = ''
OPTIONAL_CFG_FILES = ['torque.ini']
POLL_TIMEOUT = 1.0
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

pyrocore.scripts.pyrotorque.run()[source]

The entry point.

pyrocore.scripts.rtcontrol module

rTorrent Control.

Copyright (c) 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.rtcontrol.FieldStatistics(size)[source]

Bases: object

Collect statistical values for the fields of a search result.

add(field, val)[source]

Add a sample

average

Calculate average

class pyrocore.scripts.rtcontrol.RtorrentControl[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Control and inspect rTorrent from the command line.

Filter expressions take the form “<field>=<value>”, and all expressions must be met (AND). If a field name is omitted, “name” is assumed. You can also use uppercase OR to build a list of alternative conditions.

For numeric fields, a leading “+” means greater than, a leading “-” means less than. For string fields, the value is a glob pattern (*, ?, [a-z], [!a-z]), or a regex match enclosed by slashes. All string comparisons are case-ignoring. Multiple values separated by a comma indicate several possible choices (OR). “!” in front of a filter value negates it (NOT).

See https://pyrocore.readthedocs.io/en/latest/usage.html#rtcontrol for more.

Examples:
  • All 1:1 seeds ratio=+1
  • All active torrents xfer=+0
  • All seeding torrents up=+0
  • Slow torrents down=+0 down=-5k
  • Older than 2 weeks completed=+2w
  • Big stuff size=+4g
  • 1:1 seeds not on NAS ratio=+1 ‘realpath=!/mnt/*
  • Music kind=flac,mp3
ACTION_MODES = (Bunch(help='start torrent', name='start', options=('--start',)), Bunch(help='stop torrent', method='stop', name='close', options=('--close', '--stop')), Bunch(help='hash-check torrent', interactive=True, label='HASH', name='hash_check', options=('-H', '--hash-check')), Bunch(help='remove torrent from client', interactive=True, name='delete', options=('--delete',)), Bunch(help='delete PARTIAL data files and remove torrent from client', interactive=True, name='purge', options=('--purge', '--delete-partial')), Bunch(help='delete ALL data files and remove torrent from client', interactive=True, name='cull', options=('--cull', '--exterminate', '--delete-all')), Bunch(argshelp='NAME', help='assign to named throttle group (NULL=unlimited, NONE=global)', interactive=True, method='set_throttle', name='throttle', options=('-T', '--throttle')), Bunch(argshelp='"TAG +TAG -TAG..."', help='add or remove tag(s)', interactive=False, name='tag', options=('--tag',)), Bunch(argshelp='KEY=VALUE', help="set value of 'custom_KEY' field (KEY might also be 1..5)", interactive=False, label='SET_CUSTOM', method='set_custom', name='custom', options=('--custom',)), Bunch(argshelp='CMD', help='execute XMLRPC command pattern', interactive=True, label='EXEC', method='execute', name='exec', options=('--exec', '--xmlrpc')))
ADDITIONAL_HELP = ['', '', 'Use --help to get a list of all options.', 'Use --help-fields to list all fields and their description.']
ALTER_MODES = ('append', 'remove')
ARGS_HELP = '<filter>...'
FORMATTER_DEFAULTS = {'now': 1541555814.763098}
IGNORE_OPTIONS = ('0', '1')
PRIO_OPTIONS = ('0', '1', '2', '3')
add_options()[source]

Add program options.

anneal(mode, matches, orig_matches)[source]

Perform post-processing.

Return True when any changes were applied.

emit(item, defaults=None, stencil=None, to_log=False, item_formatter=None)[source]

Print an item to stdout, or the log on INFO level.

format_item(item, defaults=None, stencil=None)[source]

Format an item.

get_output_fields()[source]

Get field names from output template.

help_completion_fields()[source]

Return valid field names.

mainloop()[source]

The main loop.

show_in_view(sourceview, matches, targetname=None)[source]

Show search result in ncurses view.

validate_output_format(default_format)[source]

Prepare output format for later use.

validate_sort_fields()[source]

Take care of sorting.

pyrocore.scripts.rtcontrol.print_help_fields()[source]

Print help about fields and field formatters.

pyrocore.scripts.rtcontrol.run()[source]

The entry point.

pyrocore.scripts.rtevent module

Rtorrent event handler.

Copyright (c) 2011 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.rtevent.RtorrentEventHandler[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Handle rTorrent events.

ARGS_HELP = '<event> <infohash> [<args>...]'
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

pyrocore.scripts.rtevent.run()[source]

The entry point.

pyrocore.scripts.rtmv module

Move seeding data.

Copyright (c) 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.rtmv.RtorrentMove[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Move data actively seeded in rTorrent.

ARGS_HELP = '<source>... <target>'
PREFETCH_FIELDS = ['hash', 'name', 'size', 'path', 'is_complete']
add_options()[source]

Add program options.

guarded(call, *args)[source]

Catch exceptions thrown by filesystem calls, and don’t really execute them in dry-run mode.

mainloop()[source]

The main loop.

resolve_slashed(path)[source]

Resolve symlinked directories if they end in a ‘/’, remove trailing ‘/’ otherwise.

pyrocore.scripts.rtmv.pretty_path(path)[source]

Prettify path for logging.

pyrocore.scripts.rtmv.run()[source]

The entry point.

pyrocore.scripts.rtsweep module

Rtorrent disk space management.

Copyright (c) 2018 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.rtsweep.RtorrentSweep[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Manage disk space by deleting items loaded into rTorrent, including their data, following configured rules that define an order of what to remove first.

The required space is passed as the first argument, either in bytes or qualified with a unit character (K=KiB, M=MiB, G=GiB). Alternatively, you can pass a metafile path, with the requirement calculated from its content size.

Use “show” instead to list the active rules, ordered by their priority.

ARGS_HELP = '<space requirement>|SHOW'
add_options()[source]

Add program options.

mainloop()[source]

The main loop.

pyrocore.scripts.rtsweep.run()[source]

The entry point.

pyrocore.scripts.rtxmlrpc module

Perform raw XMLRPC calls.

Copyright (c) 2010 The PyroScope Project <pyroscope.project@gmail.com>

class pyrocore.scripts.rtxmlrpc.RtorrentXmlRpc[source]

Bases: pyrocore.scripts.base.ScriptBaseWithConfig

Perform raw rTorrent XMLRPC calls, like “rtxmlrpc throttle.global_up.max_rate”. To enter a XMLRPC REPL, pass no arguments at all.

Start arguments with “+” or “-” to indicate they’re numbers (type i4 or i8). Use “[1,2,…” for arrays. Use “@” to indicate binary data, which can be followed by a file path (e.g. “@/path/to/file”), a URL (https, http, ftp, and file are supported), or ‘-‘ to read from stdin.

ARGS_HELP = '<method> <args>... |\n -i <commands>... | -i @<filename> | -i @- |\n --session <session-file>... | --session <directory> |\n --session @<filename-list> | --session @-'
STD_LOG_LEVEL = 10
add_options()[source]

Add program options.

cooked(raw_args)[source]

Return interpreted / typed list of args.

do_command()[source]

Call a single command with arguments.

do_import()[source]

Handle import files or streams passed with ‘-i’.

do_repl()[source]

REPL for rTorrent XMLRPC commands.

do_session()[source]

Restore state from session files.

execute(proxy, method, args)[source]

Execute given XMLRPC call.

mainloop()[source]

The main loop.

open()[source]

Open connection and return proxy.

repl_usage()[source]

Print a short REPL usage summary.

pyrocore.scripts.rtxmlrpc.read_blob(arg)[source]

Read a BLOB from given @arg.

pyrocore.scripts.rtxmlrpc.run()[source]

The entry point.