km3pipe.tools
¶
Some unsorted, frequently used logic.
Module Contents¶
Functions¶
|
Return a list of File instances for the given iRODS path (recursively). |
|
Returns True of iRODS path exists, otherwise False |
|
Returns the size in bytes of the most recent version of the file |
|
Returns the size in bytes of the file |
|
Return the xrootd path of a data file |
|
Return a random URL-safe text string, in Base64 encoding. |
|
Wrap text in a pretty line with maximum length. |
|
Generate the iRODS filepath for given detector (O)ID and run ID |
|
Unpack the nfrist items from the list and return the rest. |
|
Split the string and execute the callback function on each part. |
|
Create a namedtuple with default values |
|
Remain the file pointer position after calling the decorated function |
|
|
|
|
|
Convert CamelCase to lower_and_underscore. |
|
Convert lower_underscore to CamelCase. |
|
Colorize text, while stripping nested ANSI color sequences. |
|
Print colorize text. |
|
Check if array is sorted. |
|
Remove leading whitespace from each line of a multiline string. |
|
Yield successive n-sized chunks from l. |
|
Find out if list of subsequent integers is complete. |
|
Pad a matrix with zeros, on all sides. |
|
Drop-in replacement for isinstance to avoid imports |
Check if running within a Jupyter notebook |
|
Checks if the terminal supports color. |
|
|
Return the Jpp version or None if not available. |
|
LRU cache decorator with timeout. |
|
Send an email |
Attributes¶
- km3pipe.tools.ifiles(irods_path)[source]¶
Return a list of File instances for the given iRODS path (recursively).
The File instances offer .path and .size attributes.
- km3pipe.tools.isize(irods_path)[source]¶
Returns the size in bytes of the most recent version of the file
- km3pipe.tools.token_urlsafe(nbytes=32)[source]¶
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) 'Drmhze6EPcv0fN_81Bj-nA'
- km3pipe.tools.prettyln(text, fill='-', align='^', prefix='[ ', suffix=' ]', length=69)[source]¶
Wrap text in a pretty line with maximum length.
- km3pipe.tools.irods_path(det_id, run_id)[source]¶
Generate the iRODS filepath for given detector (O)ID and run ID
- km3pipe.tools.unpack_nfirst(seq, nfirst, callback=None)[source]¶
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)
- km3pipe.tools.split(string, callback=None, sep=None)[source]¶
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]
- km3pipe.tools.namedtuple_with_defaults(typename, field_names, default_values=[])[source]¶
Create a namedtuple with default values
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)
- km3pipe.tools.remain_file_pointer(function)[source]¶
Remain the file pointer position after calling the decorated function
This decorator assumes that the last argument is the file handler.
- km3pipe.tools.colored(text, color=None, on_color=None, attrs=None, ansi_code=None)[source]¶
Colorize text, while stripping nested ANSI color sequences.
Author: Konstantin Lepa <konstantin.lepa@gmail.com> / 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’)
- km3pipe.tools.cprint(text, color=None, on_color=None, attrs=None)[source]¶
Print colorize text.
Author: Konstantin Lepa <konstantin.lepa@gmail.com> / termcolor
It accepts arguments of print function.
- km3pipe.tools.is_coherent(seq)[source]¶
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 `
- km3pipe.tools.get_jpp_version(via_command='JPrint -v')[source]¶
Return the Jpp version or None if not available.