githubcap.utils module

Utilities for githubcap project.

githubcap.utils.command_choice_callback(enum: type, _, param, value) → type[source]

Translate the given value to enum representation.

githubcap.utils.dict2json(dict_: dict, pretty: bool = True) → str[source]

Convert dict to json (string).

Parameters:
  • dict – dictionary to be converted
  • pretty – if True, nice formatting will be used
Returns:

formatted dict in json

githubcap.utils.get_attr_type(class_: type, attr_name: str) → type[source]

Get type of attribute in a attr class.

githubcap.utils.get_option_choices(class_: type, attr_name: str) → typing.List[str][source]

Get all choices for an enum.

githubcap.utils.next_pagination_page(headers: dict) → typing.Union[int, NoneType][source]

Parse next paginated page from HTTP headers.

Parameters:headers – response headers that were returned by GitHub
Returns:next pagination page or None if no other page remains
githubcap.utils.parse_cli_headers(text_headers: str) → typing.Dict[str, str][source]

Parse headers supplied from command line.

Parameters:text_headers (str) – headers supplied as a text
Returns:a dictionary representation of headers
Return type:dict
githubcap.utils.parse_datetime(datetime_string: str) → datetime.datetime[source]

Parse ISO-8601 datetime representation.

githubcap.utils.print_command_result(result: dict, pretty=True) → None[source]

Print results.

Parameters:
  • result – a result to be printed
  • pretty (bool) – print result in a pretty way
githubcap.utils.serialize_datetime(datetime_instance: datetime.datetime) → str[source]

Serialize ISO-8601 datetime representation.

githubcap.utils.setup_logging(verbose: int, no_color: bool) → None[source]

Set up logging facilities.

Parameters:
  • verbose – verbosity level
  • no_color – do not use color in output