PyTan tools module.
pytan3.utils.tools.
STORAGE_DIR
= 'pytan3_local'¶str
– Default sub-directory to use for STORAGE_PATH
.
pytan3.utils.tools.
STORAGE_PATH
= '~/pytan3_local'¶str
– Default path to use for get_storage_dir()
if path is None.
Will use OS Environment variable “PYTAN_STORAGE_PATH” if set.
pytan3.utils.tools.
get_env
(key, default)[source]¶Get an environment variables value.
Parameters: | |
---|---|
Returns: |
pytan3.utils.tools.
get_storage_dir
(path=None, path_sub='', mkdir=False)[source]¶Get the directory for PyTan to use for storing local state.
Parameters: |
|
---|---|
Returns: |
pytan3.utils.tools.
str_to_intfloat
(s)[source]¶Convert str to int or float.
Parameters: | s (str ) – String to convert to float if it has a period or int if not. |
---|---|
Returns: | int or float |
pytan3.utils.tools.
secs_ago
(secs)[source]¶Get a datetime object from N seconds ago.
Parameters: | secs (int or float ) – Number of seconds ago to get datetime object of. |
---|---|
Returns: | datetime.datetime |
pytan3.utils.tools.
secs_age
(dt)[source]¶Get the number of seconds ago of a datetime object.
Parameters: | dt (datetime.datetime ) – Datetime object to calculate age in seconds of. |
---|---|
Returns: | int |
pytan3.utils.tools.
b64_encode
(s)[source]¶Encode s as base64 using base64.b64encode()
.
Parameters: | s (str ) – Text to base64 encode. |
---|---|
Returns: | str |
pytan3.utils.tools.
b64_decode
(s)[source]¶Decode text as base64 using base64.b64decode()
.
Parameters: | s (str ) – Text to base64 decode. |
---|---|
Returns: | str |
pytan3.utils.tools.
trim_txt
(txt, limit=10000)[source]¶Trim a str if it is over n characters.
Parameters: | |
---|---|
Returns: |
pytan3.utils.tools.
get_dict_path
(obj, path)[source]¶Traverse a dict using a / seperated string.
Parameters: | |
---|---|
Raises: |
|
Returns: |
pytan3.utils.tools.
human_size
(size)[source]¶Format a byte count as human readable using humanfriendly.format_size()
.
Parameters: | size (int or str ) – Size to format as an int or as a human readable str. |
---|
Notes
Given “13”, “13b”, “13 bytes”, or 13 will return: “13 bytes”.
Returns: | str |
---|
pytan3.utils.tools.
human_delta
(delta, ms=False, short=True)[source]¶Format a delta as human readable using humanfriendly.format_timespan()
.
Parameters: |
---|
Notes
Given 300.1 or “300.1” or datetime.timedelta(seconds=300, microseconds=100000), will return: “5 minutes and 100 milliseconds” or “5m100ms”.
Returns: | str |
---|
pytan3.utils.tools.
Timer
[source]¶Bases: object
Context manager to get a human readable elapsed timespan.
start
= None¶datetime.datetime
– Start of timespan.
end
= None¶datetime.datetime
– End of timespan.
__call__
()[source]¶Return the current time.
Returns: | datetime.datetime |
---|
__enter__
()[source]¶Set the start time.
Returns: | datetime.datetime |
---|
elapsed_delta
¶Get elapsed time since start
.
Returns: | datetime.timedelta |
---|