1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

46 lines
1018 B
Python
Raw Normal View History

"""Utility fuctions."""
2019-12-30 01:44:19 -07:00
def _logger():
from loguru import logger as _loguru_logger
from hyperglass.constants import LOG_HANDLER
from hyperglass.constants import LOG_LEVELS
2019-12-30 01:44:19 -07:00
_loguru_logger.remove()
_loguru_logger.configure(handlers=[LOG_HANDLER], levels=LOG_LEVELS)
return _loguru_logger
2019-12-30 09:44:29 -07:00
def cpu_count():
"""Get server's CPU core count.
2019-12-30 09:44:29 -07:00
Used for number of web server workers.
Returns:
2019-12-30 09:44:29 -07:00
{int} -- CPU Cores
"""
2019-12-30 09:44:29 -07:00
import multiprocessing
return multiprocessing.cpu_count()
2019-12-30 01:44:19 -07:00
def check_python():
"""Verify Python Version.
Raises:
RuntimeError: Raised if running Python version is invalid.
Returns:
{str} -- Python version
"""
import sys
from hyperglass.constants import MIN_PYTHON_VERSION
pretty_version = ".".join(tuple(str(v) for v in MIN_PYTHON_VERSION))
if sys.version_info < MIN_PYTHON_VERSION:
raise RuntimeError(f"Python {pretty_version}+ is required.")
return pretty_version
2019-12-30 01:44:19 -07:00
log = _logger()