|
| | drop_zeros (v, replace="") |
| |
| | ellipsize (text, limit, ellipsis="..") |
| |
| | ensure_namespace (val, defaults=None, dashify=("WRITE_OPTIONS",), **kwargs) |
| |
| | filter_dict (dct, keys=(), values=(), reverse=False) |
| |
| | find_files (names=(), paths=(), suffixes=(), skip_suffixes=(), recurse=False) |
| |
| | format_bytes (size, precision=2, inter=" ", strip=True) |
| |
| | format_stamp (stamp) |
| |
| | format_timedelta (delta) |
| |
| | get_name (obj) |
| |
| | has_arg (func, name) |
| |
| | import_item (name) |
| |
| | is_iterable (value) |
| |
| | is_stream (value) |
| |
| | makedirs (path) |
| |
| | memoize (func) |
| |
| | merge_dicts (d1, d2) |
| |
| | merge_spans (spans, join_blanks=False) |
| |
| | parse_datetime (text) |
| |
| | parse_number (value, suffixes=None) |
| |
| | path_to_regex (text, sep=".", wildcard="*", end=False, intify=False) |
| |
| | plural (word, items=None, numbers=True, single="1", sep=",", pref="", suf="") |
| |
| | structcopy (value) |
| |
| | unique_path (pathname, empty_ok=False) |
| |
| | verify_io (f, mode) |
| |
| | wildcard_to_regex (text, end=False) |
| |
Common utilities.
------------------------------------------------------------------------------
This file is part of grepros - grep for ROS1 bag files and live topics.
Released under the BSD License.
@author Erki Suurjaak
@created 23.10.2021
@modified 06.05.2024
------------------------------------------------------------------------------
| find_files |
( |
|
names = (), |
|
|
|
paths = (), |
|
|
|
suffixes = (), |
|
|
|
skip_suffixes = (), |
|
|
|
recurse = False |
|
) |
| |
Yields filenames from current directory or given paths.
Seeks only files with given extensions if names not given.
Logs errors for names and paths not found.
@param names list of specific files to return (supports * wildcards)
@param paths list of paths to look under, if not using current directory
@param suffixes list of suffixes to select if no wilcarded names, as (".ext1", ..)
@param skip_suffixes list of suffixes to skip if no wildcarded names, as (".ext1", ..)
@param recurse whether to recurse into subdirectories
Definition at line 907 of file common.py.
| merge_spans |
( |
|
spans, |
|
|
|
join_blanks = False |
|
) |
| |
Returns a sorted list of (start, end) spans with overlapping spans merged.
@param join_blanks whether to merge consecutive zero-length spans,
e.g. [(0, 0), (1, 1)] -> [(0, 1)]
Definition at line 1099 of file common.py.
| plural |
( |
|
word, |
|
|
|
items = None, |
|
|
|
numbers = True, |
|
|
|
single = "1", |
|
|
|
sep = ",", |
|
|
|
pref = "", |
|
|
|
suf = "" |
|
) |
| |
Returns the word as 'count words', or '1 word' if count is 1,
or 'words' if count omitted.
@param items item collection or count,
or None to get just the plural of the word
@param numbers if False, count is omitted from final result
@param single prefix to use for word if count is 1, e.g. "a"
@param sep thousand-separator to use for count
@param pref prefix to prepend to count, e.g. "~150"
@param suf suffix to append to count, e.g. "150+"
Definition at line 1167 of file common.py.
Returns whether stream or file path can be read from and/or written to as binary.
Prints or raises error if not.
Tries to open file in append mode if verifying path writability,
auto-creating missing directories if any, will delete any file or directory created.
@param f file path, or stream
@param mode "r" for readable, "w" for writable, "a" for readable and writable
Definition at line 1233 of file common.py.