Refine location
This commit is contained in:
77
dockerfiles/dataExporter/code/awinlib/utilities.py
Normal file
77
dockerfiles/dataExporter/code/awinlib/utilities.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from rich import print as pp
|
||||
|
||||
|
||||
def runCmd(cmdString):
|
||||
result = subprocess.run(cmdString, stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8')
|
||||
return result
|
||||
|
||||
|
||||
def syncRun(coroutine):
|
||||
loop = asyncio.get_event_loop()
|
||||
# coroutine = funcInstace()
|
||||
return loop.run_until_complete(coroutine)
|
||||
|
||||
|
||||
def datetimeNow():
|
||||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
def loadJson(fileanme):
|
||||
try:
|
||||
with open(fileanme, "r") as f:
|
||||
secrets = json.load(f)
|
||||
|
||||
return secrets
|
||||
except FileNotFoundError:
|
||||
log(f"File not found: {fileanme}")
|
||||
return None
|
||||
|
||||
|
||||
def log2(message, *args):
|
||||
frame = inspect.currentframe().f_back
|
||||
class_name = frame.f_locals.get('self', '').__class__.__name__
|
||||
func_name = frame.f_code.co_name
|
||||
line_no = frame.f_lineno
|
||||
caller = f"{class_name}::{func_name},{line_no}"
|
||||
prefix = f"[{datetimeNow()}|{caller}]"
|
||||
pp(f"{prefix} {message}", end='')
|
||||
for arg in args:
|
||||
pp(arg, end='')
|
||||
pp("")
|
||||
|
||||
|
||||
def log(message, *args):
|
||||
log = logging.getLogger()
|
||||
log.info(message)
|
||||
|
||||
|
||||
def logD(message, *args):
|
||||
log = logging.getLogger()
|
||||
log.debug(message)
|
||||
|
||||
|
||||
def logI(message, *args):
|
||||
log = logging.getLogger()
|
||||
log.info(message)
|
||||
|
||||
|
||||
def logW(message, *args):
|
||||
log = logging.getLogger()
|
||||
log.warning(message)
|
||||
|
||||
|
||||
def logE(message, *args):
|
||||
log = logging.getLogger()
|
||||
log.error(message)
|
||||
|
||||
|
||||
def logC(message, *args):
|
||||
log = logging.getLogger()
|
||||
log.critical(message)
|
||||
Reference in New Issue
Block a user