Source code for libka.utils.python_debian_warnings
#!/usr/bin/python3
# pylint: disable=line-too-long
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4
# pylint: enable=line-too-long
############################################################################
# Copyright © 2024 José Manuel Santamaría Lema <panfaust@gmail.com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
############################################################################
"""This module just provides functions to silence python-debian warnings"""
import warnings
import logging
[docs]
def ignore_python_debian_warnings():
"""
Calling this function will prevent the stdout printing of warnings
by python-debian library.
"""
#For older versions of python-debian
warnings.simplefilter('ignore', UserWarning)
#For newer versions of python-debian
logger = logging.getLogger('debian.deb822')
logger.setLevel(logging.ERROR)
[docs]
def reset_python_debian_warnings():
"""
Calling this function will reset the stdout printing of warnings
by python-debian library. This function is meant to be used after
calling `ignore_python_debian_warnings()` like this:
```
ignore_python_debian_warnings()
<code_that_is_going_to_produce_warnings_printed_on_stdout>
reset_python_debian_warnings()
```
"""
#For older versions of python-debian
warnings.simplefilter('default', UserWarning)
#For newer versions of python-debian
logger = logging.getLogger('debian.deb822')
logger.setLevel(logging.WARNING)