#!/home/lucas/scripts/.venv/bin/python3 from pathlib import Path import sys from wallpaper_changer.logging_utils import get_logger from serverlibrary import setup_logging from wallpaper_changer.config import Config from wallpaper_changer.argument_parser import parse_args from wallpaper_changer.image_repository import ImageRepository from wallpaper_changer.monitor_manager import MonitorManager from wallpaper_changer.encryption_manager import EncryptionManager from wallpaper_changer.wallpaper_builder import WallpaperBuilder from wallpaper_changer.wallpaper_setter import WallpaperSetter logger = get_logger(__name__) 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" ) if ( args.check_encryption or args.decode_all or args.decode_argument or args.printNT ) and args.folder == "default": args.folder = "x" setup_logging(args.log_level, "wallpaper_changer") if args.clear: args.folder = "default" args.search = None cfg = Config.load(args) if args.printNT: naming_table = EncryptionManager().load_naming_table( cfg.img_dir / "naming_table.enc", cfg.private_key ) for original_name, encrypted_name in naming_table: if args.grep_nt and args.grep_nt not in original_name: continue print(f"{original_name} -> {encrypted_name}") 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 not args.disable_encryption and (args.check_encryption or args.folder != "default"): new_images_folder = Path("~").expanduser() / "Wallpaper" / "New" image_repository.check_encryption( new_images_folder, cfg.private_key, replace=args.replace ) image_repository.check_encryption( cfg.img_dir, cfg.private_key, replace=args.replace ) if args.decode_all: image_repository.decode_all(cfg.private_key) sys.exit(0) if args.decode_argument: image_repository.decode_images( pattern=args.decode_argument, private_key=cfg.private_key, remove=args.rm, ) sys.exit(0) image_repository.convert_to_jpg() image_repository.check_consecutive_filenames(correct=True) imgs = image_repository.scan( cfg.private_key, disable_encryption=args.disable_encryption, ) monitor_image_dir = cfg.img_dir.parent if cfg.host == "serverhost" else cfg.img_dir monitors = MonitorManager().get_screensize( cfg.host, monitor_image_dir, args.monitor_config, ) if args.times < 1: raise ValueError("--times must be at least 1") wallpaper_builder = WallpaperBuilder() wallpaper_setter = WallpaperSetter() for _ in range(args.times): wallpaper_path = wallpaper_builder.build( imgs, monitors, private_key=cfg.private_key, search_terms=args.search, exclude=args.exclude, decode_and_leave=args.decode_and_leave, disable_encryption=args.disable_encryption, ) wallpaper_setter.set_ubuntu(wallpaper_path) print(wallpaper_path)