From 2e7732529eee2c479a15046b38df8ff271d87c48 Mon Sep 17 00:00:00 2001 From: Nathan Denny Date: Tue, 3 Sep 2024 21:23:18 -0400 Subject: [PATCH] moved the 'as_' functions into common --- lib/Bastion/Common.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Bastion/Common.py b/lib/Bastion/Common.py index 76f95da..b72e034 100644 --- a/lib/Bastion/Common.py +++ b/lib/Bastion/Common.py @@ -10,6 +10,7 @@ import operator import random import pathlib +import logging import yaml @@ -295,3 +296,16 @@ def Boggle(*args): #-- If somehow I got here without, then nothing matched the invocation. #-- This is an error. raise ValueError + +def asLogLevel(x): + if isinstance(x, int): + return x + elif isinstance(x, str): + x = x.upper() + if x in ['DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']: + return getattr(logging, x) + raise ValueError("asLogLevel - cannot interpret '{}' as a log level.".format(x)) + + +def asPath(x): + return pathlib.Path(x)