:py:mod:`km3pipe.tools` ======================= .. py:module:: km3pipe.tools .. autoapi-nested-parse:: Some unsorted, frequently used logic. .. !! processed by numpydoc !! Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: km3pipe.tools.ifiles km3pipe.tools.iexists km3pipe.tools.isize km3pipe.tools.xrdsize km3pipe.tools.xrootd_path km3pipe.tools.token_urlsafe km3pipe.tools.prettyln km3pipe.tools.irods_path km3pipe.tools.unpack_nfirst km3pipe.tools.split km3pipe.tools.namedtuple_with_defaults km3pipe.tools.remain_file_pointer km3pipe.tools.itervalues km3pipe.tools.iteritems km3pipe.tools.decamelise km3pipe.tools.camelise km3pipe.tools.colored km3pipe.tools.cprint km3pipe.tools.issorted km3pipe.tools.lstrip km3pipe.tools.chunks km3pipe.tools.is_coherent km3pipe.tools.zero_pad km3pipe.tools.istype km3pipe.tools.isnotebook km3pipe.tools.supports_color km3pipe.tools.get_jpp_version km3pipe.tools.timed_cache km3pipe.tools.sendmail Attributes ~~~~~~~~~~ .. autoapisummary:: km3pipe.tools.XROOTD_BASE km3pipe.tools.File km3pipe.tools.ATTRIBUTES km3pipe.tools.ATTRIBUTES_RE km3pipe.tools.HIGHLIGHTS km3pipe.tools.HIGHLIGHTS_RE km3pipe.tools.COLORS km3pipe.tools.COLORS_RE km3pipe.tools.RESET km3pipe.tools.RESET_RE .. py:data:: XROOTD_BASE :value: 'root://ccxroot:1999' .. py:data:: File .. py:function:: ifiles(irods_path) Return a list of File instances for the given iRODS path (recursively). The File instances offer `.path` and `.size` attributes. .. !! processed by numpydoc !! .. py:function:: iexists(irods_path) Returns True of iRODS path exists, otherwise False .. !! processed by numpydoc !! .. py:function:: isize(irods_path) Returns the size in bytes of the most recent version of the file .. !! processed by numpydoc !! .. py:function:: xrdsize(xrootd_path) Returns the size in bytes of the file .. !! processed by numpydoc !! .. py:function:: xrootd_path(det_id, run_id) Return the xrootd path of a data file .. !! processed by numpydoc !! .. py:function:: token_urlsafe(nbytes=32) Return a random URL-safe text string, in Base64 encoding. This is taken and slightly modified from the Python 3.6 stdlib. The string has *nbytes* random bytes. If *nbytes* is ``None`` or not supplied, a reasonable default is used. >>> token_urlsafe(16) #doctest:+SKIP 'Drmhze6EPcv0fN_81Bj-nA' .. !! processed by numpydoc !! .. py:function:: prettyln(text, fill='-', align='^', prefix='[ ', suffix=' ]', length=69) Wrap `text` in a pretty line with maximum length. .. !! processed by numpydoc !! .. py:function:: irods_path(det_id, run_id) Generate the iRODS filepath for given detector (O)ID and run ID .. !! processed by numpydoc !! .. py:function:: unpack_nfirst(seq, nfirst, callback=None) Unpack the nfrist items from the list and return the rest. >>> a, b, c, rest = unpack_nfirst((1, 2, 3, 4, 5), 3) >>> a, b, c (1, 2, 3) >>> rest (4, 5) .. !! processed by numpydoc !! .. py:function:: split(string, callback=None, sep=None) Split the string and execute the callback function on each part. >>> string = "1 2 3 4" >>> parts = split(string, int) >>> parts [1, 2, 3, 4] .. !! processed by numpydoc !! .. py:function:: namedtuple_with_defaults(typename, field_names, default_values=[]) Create a namedtuple with default values .. rubric:: Examples >>> Node = namedtuple_with_defaults('Node', 'val left right') >>> Node() Node(val=None, left=None, right=None) >>> Node = namedtuple_with_defaults('Node', 'val left right', [1, 2, 3]) >>> Node() Node(val=1, left=2, right=3) >>> Node = namedtuple_with_defaults('Node', 'val left right', {'right':7}) >>> Node() Node(val=None, left=None, right=7) >>> Node(4) Node(val=4, left=None, right=7) .. !! processed by numpydoc !! .. py:function:: remain_file_pointer(function) Remain the file pointer position after calling the decorated function This decorator assumes that the last argument is the file handler. .. !! processed by numpydoc !! .. py:function:: itervalues(d) .. py:function:: iteritems(d) .. py:function:: decamelise(text) Convert CamelCase to lower_and_underscore. .. !! processed by numpydoc !! .. py:function:: camelise(text, capital_first=True) Convert lower_underscore to CamelCase. .. !! processed by numpydoc !! .. py:data:: ATTRIBUTES .. py:data:: ATTRIBUTES_RE .. py:data:: HIGHLIGHTS .. py:data:: HIGHLIGHTS_RE .. py:data:: COLORS .. py:data:: COLORS_RE .. py:data:: RESET :value: '\\033[0m' .. py:data:: RESET_RE :value: '\\033\\[0m' .. py:function:: colored(text, color=None, on_color=None, attrs=None, ansi_code=None) Colorize text, while stripping nested ANSI color sequences. Author: Konstantin Lepa / termcolor Available text colors: red, green, yellow, blue, magenta, cyan, white. Available text highlights: on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white. Available attributes: bold, dark, underline, blink, reverse, concealed. Example: colored('Hello, World!', 'red', 'on_grey', ['blue', 'blink']) colored('Hello, World!', 'green') .. !! processed by numpydoc !! .. py:function:: cprint(text, color=None, on_color=None, attrs=None) Print colorize text. Author: Konstantin Lepa / termcolor It accepts arguments of print function. .. !! processed by numpydoc !! .. py:function:: issorted(arr) Check if array is sorted. .. !! processed by numpydoc !! .. py:function:: lstrip(text) Remove leading whitespace from each line of a multiline string. .. !! processed by numpydoc !! .. py:function:: chunks(l, n) Yield successive n-sized chunks from l. .. !! processed by numpydoc !! .. py:function:: is_coherent(seq) Find out if list of subsequent integers is complete. Adapted from https://stackoverflow.com/questions/18131741/python-find-out-whether-a-list-of-integers-is-coherent ``` is_coherent([1, 2, 3, 4, 5]) -> True is_coherent([1, 3, 4, 5]) -> False ``` .. !! processed by numpydoc !! .. py:function:: zero_pad(m, n=1) Pad a matrix with zeros, on all sides. .. !! processed by numpydoc !! .. py:function:: istype(obj, typename) Drop-in replacement for `isinstance` to avoid imports .. !! processed by numpydoc !! .. py:function:: isnotebook() Check if running within a Jupyter notebook .. !! processed by numpydoc !! .. py:function:: supports_color() Checks if the terminal supports color. .. !! processed by numpydoc !! .. py:function:: get_jpp_version(via_command='JPrint -v') Return the Jpp version or None if not available. .. !! processed by numpydoc !! .. py:function:: timed_cache(**timed_cache_kwargs) LRU cache decorator with timeout. :Parameters: **days: int** .. **seconds: int** .. **microseconds: int** .. **milliseconds: int** .. **minutes: int** .. **hours: int** .. **weeks: int** .. **maxsise: int [default: 128]** .. **typed: bool [default: False]** .. .. !! processed by numpydoc !! .. py:function:: sendmail(to, msg) Send an email .. !! processed by numpydoc !!