grepros 1.2.2
grep for ROS bag files and live topics
|
Common utilities. More...
Classes | |
class | ArgumentUtil |
Namespace for program argument handling. More... | |
class | ConsolePrinter |
Prints to console, supports color output. More... | |
class | Decompressor |
Decompresses zstandard archives. More... | |
class | LenIterable |
Wrapper for iterable value with specified fixed length. More... | |
class | MatchMarkers |
Highlight markers for matches in message values. More... | |
class | ProgressBar |
A simple ASCII progress bar with a ticker thread. More... | |
class | TextWrapper |
TextWrapper that supports custom substring widths in line width calculation. More... | |
Functions | |
drop_zeros (v, replace="") | |
Drops trailing zeros and empty decimal separator, if any. | |
ellipsize (text, limit, ellipsis="..") | |
Returns text ellipsized if beyond limit. | |
ensure_namespace (val, defaults=None, dashify=("WRITE_OPTIONS",), **kwargs) | |
Returns a copy of value as argparse.Namespace , with all keys uppercase. | |
filter_dict (dct, keys=(), values=(), reverse=False) | |
Filters string dictionary by keys and values, supporting * wildcards. | |
find_files (names=(), paths=(), suffixes=(), skip_suffixes=(), recurse=False) | |
Yields filenames from current directory or given paths. | |
format_bytes (size, precision=2, inter=" ", strip=True) | |
Returns a formatted byte size (like 421.40 MB), trailing zeros optionally removed. | |
format_stamp (stamp) | |
Returns ISO datetime from UNIX timestamp. | |
format_timedelta (delta) | |
Formats the datetime.timedelta as "3d 40h 23min 23.1sec". | |
get_name (obj) | |
Returns the fully namespaced name for a Python module, class, function or object. | |
has_arg (func, name) | |
Returns whether function supports taking specified argument by name. | |
import_item (name) | |
Returns imported module, or identifier from imported namespace; raises on error. | |
is_iterable (value) | |
Returns whether value is iterable. | |
is_stream (value) | |
Returns whether value is a file-like object. | |
makedirs (path) | |
Creates directory structure for path if not already existing. | |
memoize (func) | |
Returns a results-caching wrapper for the function, cache used if arguments hashable. | |
merge_dicts (d1, d2) | |
Merges d2 into d1, recursively for nested dicts, returns d1. | |
merge_spans (spans, join_blanks=False) | |
Returns a sorted list of (start, end) spans with overlapping spans merged. | |
parse_datetime (text) | |
Returns datetime object from ISO datetime string (may be partial). | |
parse_number (value, suffixes=None) | |
Returns an integer parsed from text, raises on error. | |
path_to_regex (text, sep=".", wildcard="*", end=False, intify=False) | |
Returns re.Pattern for matching path strings with optional integer indexes. | |
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. | |
structcopy (value) | |
Returns a deep copy of a standard data structure (dict, list, set, tuple), other object types reused instead of copied. | |
unique_path (pathname, empty_ok=False) | |
Returns a unique version of the path. | |
verify_io (f, mode) | |
Returns whether stream or file path can be read from and/or written to as binary. | |
wildcard_to_regex (text, end=False) | |
Returns plain wildcard like "foo*bar" as re.Pattern("foo.*bar", re.I). | |
Variables | |
tuple | PATH_TYPES = (six.binary_type, six.text_type) |
Python types for filesystem paths. | |
tuple | STRING_TYPES = (six.binary_type, six.text_type) |
Python types for both byte strings and text strings. | |
tuple | TEXT_TYPES = (six.binary_type, six.text_type) if six.PY2 else (six.text_type, ) |
Python types for text strings. | |
Common utilities.
drop_zeros | ( | v, | |
replace = "" |
|||
) |
ellipsize | ( | text, | |
limit, | |||
ellipsis = ".." |
|||
) |
ensure_namespace | ( | val, | |
defaults = None , |
|||
dashify = ("WRITE_OPTIONS", ) , |
|||
** | kwargs | ||
) |
Returns a copy of value as argparse.Namespace
, with all keys uppercase.
Arguments with list/tuple values in defaults are ensured to have list/tuple values.
val | argparse.Namespace or dictionary or None |
defaults | additional arguments to set to namespace if missing |
dashify | names of dictionary arguments where to replace the first underscore in string keys with a dash |
kwargs | any and all argument overrides as keyword overrides |
filter_dict | ( | dct, | |
keys = () , |
|||
values = () , |
|||
reverse = False |
|||
) |
Filters string dictionary by keys and values, supporting * wildcards.
Dictionary values may be additional lists; keys with emptied lists are dropped.
Retains only entries that find a match (supports * wildcards); if reverse, retains only entries that do not find a match.
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.
names | list of specific files to return (supports * wildcards) |
paths | list of paths to look under, if not using current directory |
suffixes | list of suffixes to select if no wilcarded names, as (".ext1", ..) |
skip_suffixes | list of suffixes to skip if no wildcarded names, as (".ext1", ..) |
recurse | whether to recurse into subdirectories |
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_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 |
|||
) |
Returns re.Pattern for matching path strings with optional integer indexes.
text | separated wildcarded path pattern like "foo*.bar" |
sep | path parts separator, optional |
wildcard | simple wildcard to convert to Python wildcard pattern, optional |
end | whether pattern should match until end (terminates with $) |
intify | whether path should match optional integer index between parts, like "foo.bar" as "foo(\.\d+)?\.bar" |
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.
items | item collection or count, or None to get just the plural of the word |
numbers | if False, count is omitted from final result |
single | prefix to use for word if count is 1, e.g. "a" |
sep | thousand-separator to use for count |
pref | prefix to prepend to count, e.g. "~150" |
suf | suffix to append to count, e.g. "150+" |
structcopy | ( | value | ) |
unique_path | ( | pathname, | |
empty_ok = False |
|||
) |
verify_io | ( | f, | |
mode | |||
) |
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.
f | file path, or stream |
mode | "r" for readable, "w" for writable, "a" for readable and writable |
wildcard_to_regex | ( | text, | |
end = False |
|||
) |
tuple PATH_TYPES = (six.binary_type, six.text_type) |
tuple STRING_TYPES = (six.binary_type, six.text_type) |