Files
Server-scripts/wallpaper_changer/main.py
T
Lucas Vivo ba5fbac806 feat(wallpaper_changer): clear -x from wp.conf
add method to config moule to clear -x from general config file
2026-11-20 15:58:04 +01:00

127 lines
4.1 KiB
Python
Executable File

#!/home/lucas/scripts/wallpaper_changer/.venv/bin/python3
import sys
from pathlib import Path
from serverlibrary import setup_logging
from wallpaper_changer.argument_parser import parse_args
from wallpaper_changer.config import Config
from wallpaper_changer.daemon import DaemonRunner
from wallpaper_changer.encryption_manager import EncryptionManager
from wallpaper_changer.image_repository import ImageRepository
from wallpaper_changer.logging_utils import get_logger
from wallpaper_changer.monitor_manager import MonitorManager
from wallpaper_changer.wallpaper_changer import WallpaperChanger
from wallpaper_changer.wallpaper_setter import WallpaperSetter
logger = get_logger(__name__)
def main() -> None:
args = parse_args()
if args.disable_encryption and (
args.check_encryption
or args.decode_all
or args.decode_argument
or args.printNT
or args.encryptNT
or args.decryptNT
):
raise ValueError(
"--disable-encryption cannot be used with encryption check, decode, or naming-table commands"
)
setup_logging(args.log_level, "wallpaper_changer")
if args.clear:
logger.info("Clearing config file")
config_file = Path(args.conf_dir).expanduser().resolve() / "wp.conf"
Config.remove_config_argument(config_file, "-x")
args.mode = "default"
args.folder = None
args.search = None
WallpaperSetter().set_ubuntu("~/.wallpaper/Default/default_wallpaper.jpg")
cfg = Config.load(args)
if args.printNT:
naming_table = EncryptionManager().load_naming_table(
cfg.img_dir / "naming_table.enc", cfg.private_key
)
headers = ("Image file", "Encrypted file", "Image hash")
rows = [
(item.image_name, item.encrypted_file, item.image_hash)
for item in naming_table
if not args.grep_nt or args.grep_nt in item.image_name
]
widths = tuple(
max([len(header), *(len(row[column]) for row in rows)])
for column, header in enumerate(headers)
)
print(" ".join(header.ljust(width) for header, width in zip(headers, widths)))
for row in rows:
print(" ".join(value.ljust(width) for value, width in zip(row, widths)))
sys.exit(0)
image_repository = ImageRepository(cfg.img_dir)
if args.encryptNT:
EncryptionManager().encrypt_naming_table_file(
cfg.img_dir / "naming_table.dec",
cfg.img_dir / "naming_table.enc",
cfg.private_key,
)
sys.exit(0)
if args.decryptNT:
EncryptionManager().decrypt_naming_table_file(
cfg.img_dir / "naming_table.enc",
cfg.img_dir / "naming_table.dec",
cfg.private_key,
)
sys.exit(0)
if args.decode_all:
image_repository.decode_all(cfg.private_key)
sys.exit(0)
if args.times < 1:
raise ValueError("--times must be at least 1")
if args.decode_argument:
image_repository.decode_images(
pattern=args.decode_argument,
private_key=cfg.private_key,
conf_dir=cfg.conf_dir,
remove=args.rm
)
sys.exit(0)
image_repository.convert_to_jpg()
image_repository.check_consecutive_filenames(correct_wrong_numbers=True)
if not cfg.disable_encryption and (
args.check_encryption or args.mode != "default"
):
new_images_folder = Path("~").expanduser() / ".wallpaper" / "New"
image_repository.check_encryption(
cfg.private_key, new_images_folder, replace=args.replace
)
image_repository.check_encryption(
cfg.private_key, replace=args.replace
)
monitors = MonitorManager().get_screensize(
cfg.headless_mode,
cfg.monitor_file,
)
if not args.daemon:
WallpaperChanger().change_wallpaper(cfg, monitors, args.search,args.search_mon,args.exclude)
else:
DaemonRunner().run(cfg, monitors, args.search,args.search_mon,args.exclude)
if __name__ == "__main__":
main()