mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
46 lines
1018 B
Python
46 lines
1018 B
Python
"""Utility fuctions."""
|
|
|
|
|
|
def _logger():
|
|
from loguru import logger as _loguru_logger
|
|
from hyperglass.constants import LOG_HANDLER
|
|
from hyperglass.constants import LOG_LEVELS
|
|
|
|
_loguru_logger.remove()
|
|
_loguru_logger.configure(handlers=[LOG_HANDLER], levels=LOG_LEVELS)
|
|
return _loguru_logger
|
|
|
|
|
|
def cpu_count():
|
|
"""Get server's CPU core count.
|
|
|
|
Used for number of web server workers.
|
|
|
|
Returns:
|
|
{int} -- CPU Cores
|
|
"""
|
|
import multiprocessing
|
|
|
|
return multiprocessing.cpu_count()
|
|
|
|
|
|
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
|
|
|
|
|
|
log = _logger()
|