sfftkrw.core package¶
Parser module¶
parser.py¶
-
sfftkrw.core.parser.
add_args
(parser, the_arg)¶ Convenience function to add
the_arg
to theparser
.This relies on the argument being structured as a dictionary with the keys
args
for positional arguments andkwargs
for the keyword arguments. The value of doing this is that arguments that are reused in several parsers can be referred to by a variable instead of being redefined.Usage:
>>> my_arg = {'arg': ['-x'], 'kwargs': {'help': 'help'}} >>> this_parser = argparse.ArgumentParser() >>> add_args(this_parser, my_arg)
Parameters: - parser (
argparse.ArgumentParser
) – the parser to be modified - the_arg (dict) – the argument specified as a dict with keys
args
andkwargs
Returns: a modified parser object
Return type: - parser (
-
sfftkrw.core.parser.
parse_args
(_args, use_shlex=False)¶ Parse and check command-line arguments.
This function does all the heavy lifting in ensuring that commandline arguments are properly formatted and checked for sanity.
In this way command handlers (defined in
sfftk/sff.py
e.g.handle_convert(...)
) assume correct argument values and can concentrate on functionality.Parameters: Returns: parsed arguments
Return type:
Printing utilities¶
print_tools.py¶
Utilities for printing stuff to the screen.
-
sfftkrw.core.print_tools.
get_printable_ascii_string
(B)¶ Given a bytes string of ASCII and non-ASCII return the maximal printable prefix
Parameters: B (bytes) – the bytes string to search Return ascii_b: the maximal ASCII prefix Return type: bytes
-
sfftkrw.core.print_tools.
print_date
(print_string, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, newline=True, incl_date=True)¶ Print the given string with date on the given stream
Parameters: - print_string (bytes or str or unicode) – the bytes/str to be printed
- stream (
sys.stderr
orsys.stdout
) – the stream/file to write to - newline (bool) – whether (default) or not to add a newline at the end
- incl_date (bool) – whether (default) or not to include the date at the beginning
-
sfftkrw.core.print_tools.
print_static
(print_string, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, incl_date=True)¶ Print the given string with date on the given stream from the first position overwriting any characters.
This is a useful way to display progress without overcrowding the screen.
Parameters: - print_string (bytes or str) – the bytes/str to be printed
- stream (
sys.stderr
orsys.stdout
) – the stream/file to write to - incl_date (bool) – whether (default) or not to include the date at the beginning
Miscellaneous utilities¶
utils.py¶
A collection of helpful utilities
-
sfftkrw.core.utils.
get_path
(D, path)¶ Get a path from a dictionary
Parameters: Returns: the item at the path from the dictionary
-
sfftkrw.core.utils.
get_unique_id
()¶ Return an ID that will be unique over the current segmentation
Returns: unique_id Return type: int
-
sfftkrw.core.utils.
get_version
(fn)¶ Gets the version from the EMDB-SFF file
Parameters: fn (bytes or unicode) – name of EMDB-SFF file Returns: the version Return type: unicode
-
sfftkrw.core.utils.
rgba_to_hex
(rgba, channels=3)¶ Convert RGB(A) iterable to a hex string (e.g. #aabbcc(dd)
Parameters: Returns: a hex string
Return type: