mirror of
https://github.com/kittywitch/konawall-py.git
synced 2026-02-09 04:19:19 -08:00
Change logging system to make it easier to get results from scheduled
task
This commit is contained in:
parent
fa08d92cf7
commit
f3ee0e19ff
7 changed files with 26 additions and 15 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -158,3 +158,6 @@ cython_debug/
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# App logs
|
||||||
|
app.log
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import termcolor
|
import termcolor
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -9,4 +10,5 @@ Print a key-value pair with a key and value coloured differently.
|
||||||
:returns: None
|
:returns: None
|
||||||
"""
|
"""
|
||||||
def kv_print(key: str, value: str, newline: bool = False) -> None:
|
def kv_print(key: str, value: str, newline: bool = False) -> None:
|
||||||
|
logging.info(f"{key}: {value}")
|
||||||
print(termcolor.colored(key, "cyan") + ": " + termcolor.colored(value, "white"), end="\n" if newline else " ")
|
print(termcolor.colored(key, "cyan") + ": " + termcolor.colored(value, "white"), end="\n" if newline else " ")
|
||||||
|
|
@ -43,10 +43,10 @@ def detect_linux_environment():
|
||||||
def detect_environment():
|
def detect_environment():
|
||||||
if sys.platform == "linux":
|
if sys.platform == "linux":
|
||||||
environment = detect_linux_environment()
|
environment = detect_linux_environment()
|
||||||
logging.info(f"Detected environment is {environment} running on Linux")
|
logging.debug(f"Detected environment is {environment} running on Linux")
|
||||||
else:
|
else:
|
||||||
environment = sys.platform
|
environment = sys.platform
|
||||||
logging.info(f"Detected environment is {environment}")
|
logging.debug(f"Detected environment is {environment}")
|
||||||
return environment
|
return environment
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -55,6 +55,6 @@ def detect_environment():
|
||||||
def set_environment_wallpapers(environment: str, files: list, displays: list):
|
def set_environment_wallpapers(environment: str, files: list, displays: list):
|
||||||
if f"{environment}_setter" in environment_handlers:
|
if f"{environment}_setter" in environment_handlers:
|
||||||
environment_handlers[f"{environment}_setter"](files, displays)
|
environment_handlers[f"{environment}_setter"](files, displays)
|
||||||
logging.info("Wallpapers set!")
|
logging.debug("Wallpapers set!")
|
||||||
else:
|
else:
|
||||||
UnsupportedPlatform(f"Environment {environment} is not supported, sorry!")
|
UnsupportedPlatform(f"Environment {environment} is not supported, sorry!")
|
||||||
|
|
@ -10,7 +10,7 @@ Pre-setting on Windows
|
||||||
@add_environment("win32_init")
|
@add_environment("win32_init")
|
||||||
def init():
|
def init():
|
||||||
os.system("color")
|
os.system("color")
|
||||||
logging.info("Initialized for a Windows environment")
|
logging.debug("Initialized for a Windows environment")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This sets wallpapers on Windows.
|
This sets wallpapers on Windows.
|
||||||
|
|
@ -20,9 +20,9 @@ This sets wallpapers on Windows.
|
||||||
@add_environment("win32_setter")
|
@add_environment("win32_setter")
|
||||||
def set_wallpapers(files: list, displays: list):
|
def set_wallpapers(files: list, displays: list):
|
||||||
if len(files) > 1:
|
if len(files) > 1:
|
||||||
logging.info("Several monitors detected, going the hard route")
|
logging.debug("Several monitors detected, going the hard route")
|
||||||
file = combine_to_viewport(displays, files)
|
file = combine_to_viewport(displays, files)
|
||||||
ctypes.windll.user32.SystemParametersInfoW(20, 0, file, 0)
|
ctypes.windll.user32.SystemParametersInfoW(20, 0, file, 0)
|
||||||
else:
|
else:
|
||||||
logging.info("Detected only one monitor, setting wallpaper simply")
|
logging.debug("Detected only one monitor, setting wagilpaper simply")
|
||||||
ctypes.windll.user32.SystemParametersInfoW(20, 0, files[0] , 0)
|
ctypes.windll.user32.SystemParametersInfoW(20, 0, files[0] , 0)
|
||||||
|
|
@ -12,6 +12,6 @@ def combine_to_viewport(displays: list, files: list):
|
||||||
resized_image = open_image.resize((displays[i].width, displays[i].height))
|
resized_image = open_image.resize((displays[i].width, displays[i].height))
|
||||||
combined.paste(resized_image, (displays[i].x, displays[i].y))
|
combined.paste(resized_image, (displays[i].x, displays[i].y))
|
||||||
file = tempfile.NamedTemporaryFile(delete=False)
|
file = tempfile.NamedTemporaryFile(delete=False)
|
||||||
logging.info(f"Created temporary file {file.name} to save combined viewport image into")
|
logging.debug(f"Created temporary file {file.name} to save combined viewport image into")
|
||||||
combined.save(file.name, format="PNG")
|
combined.save(file.name, format="PNG")
|
||||||
return file
|
return file
|
||||||
|
|
|
||||||
16
main.py
16
main.py
|
|
@ -22,16 +22,22 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
log_level = logging.DEBUG
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=logging.WARNING)
|
log_level = logging.INFO
|
||||||
|
logging.basicConfig(
|
||||||
|
level=log_level,
|
||||||
|
filename="app.log",
|
||||||
|
filemode="a",
|
||||||
|
format="%(asctime)s - %(levelname)s - %(message)s"
|
||||||
|
)
|
||||||
|
|
||||||
logging.debug(f"Called with args={args}")
|
logging.debug(f"Called with args={args}")
|
||||||
|
|
||||||
import_dir(os.path.join(os.path.dirname(os.path.abspath( __file__ )), "sources"))
|
import_dir(os.path.join(os.path.dirname(os.path.abspath( __file__ )), "sources"))
|
||||||
logging.info(f"Loaded source handlers: {', '.join(source_handlers)}")
|
logging.debug(f"Loaded source handlers: {', '.join(source_handlers)}")
|
||||||
import_dir(os.path.join(os.path.dirname(os.path.abspath( __file__ )), "environments"))
|
import_dir(os.path.join(os.path.dirname(os.path.abspath( __file__ )), "environments"))
|
||||||
logging.info(f"Loaded environment handlers: {', '.join(environment_handlers)}")
|
logging.debug(f"Loaded environment handlers: {', '.join(environment_handlers)}")
|
||||||
|
|
||||||
environment = detect_environment()
|
environment = detect_environment()
|
||||||
environment_handlers[environment + "_init"]()
|
environment_handlers[environment + "_init"]()
|
||||||
|
|
@ -48,7 +54,7 @@ def main():
|
||||||
set_environment_wallpapers(environment, files, displays)
|
set_environment_wallpapers(environment, files, displays)
|
||||||
else:
|
else:
|
||||||
environment_handlers[f"{args.environment}_setter"](files, displays)
|
environment_handlers[f"{args.environment}_setter"](files, displays)
|
||||||
logging.info("Wallpapers set!")
|
logging.debug("Wallpapers set!")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ def add_environment(environment: str) -> callable:
|
||||||
path = frame[0].f_code.co_filename
|
path = frame[0].f_code.co_filename
|
||||||
def wrapper(function):
|
def wrapper(function):
|
||||||
environment_handlers[environment] = function
|
environment_handlers[environment] = function
|
||||||
logging.info(f"Loaded environment handler {environment} from {path}")
|
logging.debug(f"Loaded environment handler {environment} from {path}")
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,5 +65,5 @@ def add_source(source: str) -> callable:
|
||||||
path = frame[0].f_code.co_filename
|
path = frame[0].f_code.co_filename
|
||||||
def wrapper(function):
|
def wrapper(function):
|
||||||
source_handlers[source] = function
|
source_handlers[source] = function
|
||||||
logging.info(f"Loaded wallpaper source {source} from {path}")
|
logging.debug(f"Loaded wallpaper source {source} from {path}")
|
||||||
return wrapper
|
return wrapper
|
||||||
Loading…
Add table
Add a link
Reference in a new issue