mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-08-04 06:52:58 +00:00
chore: try to make a working base
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import logging as log
|
||||
|
||||
import os
|
||||
|
||||
class utilities():
|
||||
@staticmethod
|
||||
def filter_config(config_contents: dict, filter_keyword: str) -> tuple[bool, dict]:
|
||||
'''
|
||||
Helper function to grab a specific part of the config
|
||||
'''
|
||||
|
||||
log.debug(f'searching for section: {filter_keyword}')
|
||||
for section in config_contents:
|
||||
if str(section).lower() == filter_keyword.lower():
|
||||
return True, dict(config_contents[section].items())
|
||||
|
||||
return False, {}
|
||||
|
||||
@staticmethod
|
||||
def ensure_directory(path: str) -> bool:
|
||||
'''
|
||||
Make the directory if it does not exist yet, return only true if the directory was missing and created.
|
||||
'''
|
||||
|
||||
log.debug(f'checking if the directory at: {path} exists')
|
||||
if os.path.exists(path) and os.path.isdir(path):
|
||||
return True
|
||||
|
||||
try:
|
||||
os.mkdir(path)
|
||||
return True
|
||||
|
||||
except Exception as err:
|
||||
log.critical('failed to create directory')
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user