pyrocore.util package¶
Utility Modules.
Copyright (c) 2010 The PyroScope Project <pyroscope.project@gmail.com>
Submodules¶
pyrocore.util.algo module¶
Helper Algorithms.
Copyright (c) 2009, 2010 The PyroScope Project <pyroscope.project@gmail.com>
pyrocore.util.load_config module¶
Configuration Loader.
For details, see https://pyrocore.readthedocs.io/en/latest/setup.html
Copyright (c) 2009, 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>
-
class
pyrocore.util.load_config.
ConfigLoader
(config_dir=None)[source]¶ Bases:
object
Populates this module’s dictionary with the user-defined configuration values.
-
CONFIG_INI
= 'config.ini'¶
-
CONFIG_PY
= 'config.py'¶
-
INTERPOLATION_ESCAPE
= <_sre.SRE_Pattern object at 0x3925b30>¶
-
pyrocore.util.matching module¶
Torrent Item Filters.
Copyright (c) 2009, 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>
-
class
pyrocore.util.matching.
BoolFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.FieldFilter
Filter boolean values.
-
class
pyrocore.util.matching.
ByteSizeFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.NumericFilterBase
Filter size and bandwidth values.
-
UNITS
= {'k': 1024, 'b': 1, 'm': 1048576, 'g': 1073741824}¶
-
-
class
pyrocore.util.matching.
CompoundFilterAll
[source]¶ Bases:
pyrocore.util.matching.CompoundFilterBase
List of filters that must all match (AND).
-
class
pyrocore.util.matching.
CompoundFilterAny
[source]¶ Bases:
pyrocore.util.matching.CompoundFilterBase
List of filters where at least one must match (OR).
-
class
pyrocore.util.matching.
CompoundFilterBase
[source]¶ Bases:
pyrocore.util.matching.Filter
,list
List of filters.
-
class
pyrocore.util.matching.
ConditionParser
(lookup, default_field=None, ident_re='[_A-Za-z][_A-Za-z0-9]*')[source]¶ Bases:
object
Filter condition parser.
-
COMPARISON_OPS
= {'>=': '!-%s', '<>': '!%s', '<=': '!+%s', '~': '/%s/', '!=': '!%s', '<': '-%s', '>': '+%s'}¶
-
-
class
pyrocore.util.matching.
DurationFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.TimeFilter
Filter durations in seconds.
-
class
pyrocore.util.matching.
EqualsFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.FieldFilter
Filter fields equal to the given value.
-
class
pyrocore.util.matching.
FieldFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.Filter
Base class for all field filters.
-
PRE_FILTER_FIELDS
= {'uploaded': 'd.up.total=', 'custom_tm_completed': 'd.custom=tm_completed', 'tagged': 'd.custom=tags', 'hash': 'd.hash=', 'prio': 'd.priority=', 'started': 'd.custom=tm_started', 'completed': 'd.custom=tm_completed', 'is_active': 'd.is_active=', 'custom_tm_started': 'd.custom=tm_started', 'up': 'd.up.rate=', 'down': 'd.down.rate=', 'is_open': 'd.is_open=', 'path': 'd.base_path=', 'loaded': 'd.custom=tm_loaded', 'message': 'd.message=', 'size': 'd.size_bytes=', 'ratio': 'd.ratio=', 'name': 'd.name=', 'metafile': 'd.tied_to_file=', 'is_ignored': 'd.ignore_commands=', 'throttle': 'd.throttle_name=', 'custom_tm_loaded': 'd.custom=tm_loaded', 'is_complete': 'd.complete=', 'is_multi_file': 'd.is_multi_file='}¶
-
-
class
pyrocore.util.matching.
FilesFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.PatternFilter
Case-insensitive pattern filter on filenames in a torrent.
-
exception
pyrocore.util.matching.
FilterError
[source]¶ Bases:
pyrocore.error.UserError
(Syntax) error in filter.
-
class
pyrocore.util.matching.
FloatFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.NumericFilterBase
Filter float values.
-
FIELD_SCALE
= {'ratio': 1000}¶
-
-
class
pyrocore.util.matching.
MagicFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.FieldFilter
Filter that looks at the comparison value and automatically decides what type of filter to use.
-
class
pyrocore.util.matching.
NegateFilter
(inner)[source]¶ Bases:
pyrocore.util.matching.Filter
Negate result of another filter (NOT).
-
class
pyrocore.util.matching.
NumericFilterBase
(name, value)[source]¶ Bases:
pyrocore.util.matching.FieldFilter
Base class for numerical value filters.
-
class
pyrocore.util.matching.
PatternFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.FieldFilter
Case-insensitive pattern filter, either a glob or a /regex/ pattern.
-
CLEAN_PRE_VAL_RE
= <_sre.SRE_Pattern object at 0x440ff80>¶
-
SPLIT_PRE_GLOB_RE
= <_sre.SRE_Pattern object at 0x408bdf0>¶
-
SPLIT_PRE_VAL_RE
= <_sre.SRE_Pattern object at 0x42585f0>¶
-
-
class
pyrocore.util.matching.
TaggedAsFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.FieldFilter
Case-insensitive tags filter. Tag fields are white-space separated lists of tags.
-
class
pyrocore.util.matching.
TimeFilter
(name, value)[source]¶ Bases:
pyrocore.util.matching.NumericFilterBase
Filter UNIX timestamp values.
-
TIMEDELTA_RE
= <_sre.SRE_Pattern object at 0x44156c0>¶
-
TIMEDELTA_UNITS
= {'y': <function <lambda> at 0x4337a28>, 's': <function <lambda> at 0x4337cf8>, 'd': <function <lambda> at 0x4337b90>, 'w': <function <lambda> at 0x4337b18>, 'i': <function <lambda> at 0x4337c80>, 'h': <function <lambda> at 0x4337c08>, 'm': <function <lambda> at 0x4337aa0>}¶
-
-
class
pyrocore.util.matching.
TimeFilterNotNull
(name, value)[source]¶ Bases:
pyrocore.util.matching.TimeFilter
Filter UNIX timestamp values, ignore unset values unless compared to 0.
pyrocore.util.metafile module¶
Metafile Support.
Copyright (c) 2009, 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>
-
class
pyrocore.util.metafile.
MaskingPrettyPrinter
(indent=1, width=80, depth=None, stream=None)[source]¶ Bases:
pprint.PrettyPrinter
A PrettyPrinter that masks strings in the object tree.
-
class
pyrocore.util.metafile.
Metafile
(filename, datapath=None)[source]¶ Bases:
object
A torrent metafile.
-
IGNORE_GLOB
= [u'core', u'CVS', u'.*', u'*~', u'*.swp', u'*.tmp', u'*.bak', u'[Tt]humbs.db', u'[Dd]esktop.ini', u'ehthumbs_vista.db']¶
-
check
(metainfo, datapath, progress=None)[source]¶ Check piece hashes of a metafile against the given datapath.
-
create
(datapath, tracker_urls, comment=None, root_name=None, created_by=None, private=False, no_date=False, progress=None, callback=None)[source]¶ Create a metafile with the path given on object creation. Returns the last metafile dict that was written (as an object, not bencoded).
-
datapath
¶ Get a valid datapath, else raise an exception.
-
-
pyrocore.util.metafile.
add_fast_resume
(meta, datapath)[source]¶ Add fast resume data to a metafile dict.
-
pyrocore.util.metafile.
assign_fields
(meta, assignments)[source]¶ Takes a list of C{key=value} strings and assigns them to the given metafile. If you want to set nested keys (e.g. “info.source”), you have to use a dot as a separator. For exotic keys containing a dot, double that dot (“dotted..key”).
Numeric values starting with “+” or “-” are converted to integers.
If just a key name is given (no ‘=’), the field is removed.
-
pyrocore.util.metafile.
check_info
(info)[source]¶ Validate info dict.
Raise ValueError if validation fails.
-
pyrocore.util.metafile.
check_meta
(meta)[source]¶ Validate meta dict.
Raise ValueError if validation fails.
-
pyrocore.util.metafile.
checked_open
(filename, log=None, quiet=False)[source]¶ Open and validate the given metafile. Optionally provide diagnostics on the passed logger, for invalid metafiles, which then just cause a warning but no exception. “quiet” can supress that warning.
-
pyrocore.util.metafile.
clean_meta
(meta, including_info=False, logger=None)[source]¶ Clean meta dict. Optionally log changes using the given logger.
@param logger: If given, a callable accepting a string message. @return: Set of keys removed from C{meta}.
-
pyrocore.util.metafile.
console_progress
()[source]¶ Return a progress indicator for consoles if stdout is a tty.
-
pyrocore.util.metafile.
data_size
(metadata)[source]¶ Calculate the size of a torrent based on parsed metadata.
pyrocore.util.osmagic module¶
Platform Specific Incantations.
Copyright (c) 2011 The PyroScope Project <pyroscope.project@gmail.com>
-
pyrocore.util.osmagic.
check_process
(pidfile)[source]¶ Read pid file and check process status. Return (running, pid).
pyrocore.util.pymagic module¶
Python Utility Functions.
Copyright (c) 2009, 2010 The PyroScope Project <pyroscope.project@gmail.com>
-
class
pyrocore.util.pymagic.
JSONEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
Custon JSON encoder.
-
pyrocore.util.pymagic.
get_class_logger
(obj)[source]¶ Get a logger specific for the given object’s class.
-
pyrocore.util.pymagic.
get_lazy_logger
(name)[source]¶ Return a logger proxy that is lazily initialized.
This avoids the problems associated with module-level loggers being created early (on import), before the logging system is properly initialized.
-
pyrocore.util.pymagic.
import_name
(module_spec, name=None)[source]¶ Import identifier C{name} from module C{module_spec}.
If name is omitted, C{module_spec} must contain the name after the module path, delimited by a colon (like a setuptools entry-point).
@param module_spec: Fully qualified module name, e.g. C{x.y.z}. @param name: Name to import from C{module_spec}. @return: Requested object. @rtype: object
pyrocore.util.stats module¶
Statistics data.
Copyright (c) 2014 The PyroScope Project <pyroscope.project@gmail.com>
pyrocore.util.traits module¶
Classification.
Copyright (c) 2010, 2011 The PyroScope Project <pyroscope.project@gmail.com>
-
pyrocore.util.traits.
detect_traits
(name=None, alias=None, filetype=None)[source]¶ Build traits list from passed attributes.
The result is a list of hierarchical classifiers, the top-level consisting of “audio”, “movie”, “tv”, “video”, “document”, etc. It can be used as a part of completion paths to build directory structures.
-
pyrocore.util.traits.
get_filetypes
(filelist, path=None, size=<function <lambda> at 0x38b7b18>)[source]¶ Get a sorted list of file types and their weight in percent from an iterable of file names.
@return: List of weighted file extensions (no ‘.’), sorted in descending order @rtype: list of (weight, filetype)
pyrocore.util.xmlrpc module¶
RTorrent client proxy.
Copyright (c) 2011 The PyroScope Project <pyroscope.project@gmail.com>
-
exception
pyrocore.util.xmlrpc.
HashNotFound
(msg, *args)[source]¶ Bases:
pyrocore.util.xmlrpc.XmlRpcError
Non-existing or disappeared hash.
-
class
pyrocore.util.xmlrpc.
RTorrentMethod
(proxy, method_name)[source]¶ Bases:
object
Collect attribute accesses to build the final method name.
-
NEEDS_FAKE_TARGET
= set(['ui.current_view.set', 'view_filter'])¶
-
-
class
pyrocore.util.xmlrpc.
RTorrentProxy
(url, mapping=None)[source]¶ Bases:
object
Proxy to rTorrent’s XMLRPC interface.
Method calls are built from attribute accesses, i.e. you can do something like C{proxy.system.client_version()}.
-
exception
pyrocore.util.xmlrpc.
XmlRpcError
(msg, *args)[source]¶ Bases:
exceptions.Exception
Base class for XMLRPC protocol errors.