pygacity.util.stringthings module

Utility string functions for pygacity

pygacity.util.stringthings.banner(logf: callable = <built-in function print>)[source]

Logs the pygacity banner message using the provided logging function.

Parameters:

logf (function) – writer; e.g., print, f.write, etc.

pygacity.util.stringthings.chmod_recursive_dirs_files(path: Path, dmode=493, fmode=420)[source]

Recursively changes permissions of a directory and its contents.

Parameters:
  • path (Path) – The root directory to change permissions for.

  • dmode (int, optional) – The mode (permissions) to apply to directories. Default is 0o755

  • fmode (int, optional) – The mode (permissions) to apply to files. Default is 0o644

pygacity.util.stringthings.linesplit(line: str, cchar: str = '!')[source]

Splits the line into to substrings at first occurrence of cchar and returns the two strings as a tuple.

Parameters:
  • line (str) – the string to be split

  • cchar (str, optional) – the character at which to split the string (default is ‘!’)

Returns:

a tuple of two strings: the part before cchar and the part after cchar

Return type:

tuple[str, str]

pygacity.util.stringthings.my_logger(msg: str | list | dict, logf: callable = <built-in function print>, width: int = None, fill: str = '', just: str = '<', frame: str = '', depth: int = 0, **kwargs)[source]

A fancy logger with recursion for lists and dicts.

Parameters:
  • msg (str, list, or dict) – the message to be logged, either as a single string, list, or dict

  • logf (function, optional) – writer; default is print; works with logger.info, f.write, etc.

  • width (int, optional) – linelength in bytes; default is terminal width for print, 67 otherwise

  • fill (str, optional) – single character used to fill blank spaces

  • just (str, optional) – format character for justification: ‘<’ (left), ‘>’ (right), ‘^’ (center). default is ‘<’ (left)

  • frame (str, optional) – single character used to frame the message block

  • depth (int, optional) – indentation depth for nested structures (default is 0)

pygacity.util.stringthings.oxford(a_list: list[str], conjunction: str = 'or')[source]

Returns a comma-delimited string of items in a_list, following the oxford comma rules including a terminal conjuction (default is ‘or’)

Parameters:
  • a_list (list[str]) – list of strings to be joined

  • conjunction (str, optional) – conjunction to use before last item (default is ‘or’)

Returns:

comma-delimited string of items in a_list with oxford comma usage

Return type:

str

pygacity.util.stringthings.striplist(L: list[str]) list[str][source]

Removes all blank bytes from all members of list L and returns a new list.

Parameters:

L (list[str]) – list of strings to be stripped of blank bytes

Returns:

new list of strings with blank bytes removed

Return type:

list[str]