2026-11-13 11:03:09 +01:00
|
|
|
#!/home/lucas/scripts/wallpaper_changer/.venv/bin/python3
|
2026-11-09 20:01:23 +01:00
|
|
|
import sys
|
2026-11-13 11:28:11 +01:00
|
|
|
from pathlib import Path
|
2026-11-09 20:01:23 +01:00
|
|
|
|
|
|
|
|
from serverlibrary import setup_logging
|
|
|
|
|
|
|
|
|
|
from wallpaper_changer.argument_parser import parse_args
|
2026-11-13 11:28:11 +01:00
|
|
|
from wallpaper_changer.config import Config
|
|
|
|
|
from wallpaper_changer.encryption_manager import EncryptionManager
|
2026-11-09 20:01:23 +01:00
|
|
|
from wallpaper_changer.image_repository import ImageRepository
|
2026-11-13 11:28:11 +01:00
|
|
|
from wallpaper_changer.logging_utils import get_logger
|
2026-11-09 20:01:23 +01:00
|
|
|
from wallpaper_changer.monitor_manager import MonitorManager
|
|
|
|
|
from wallpaper_changer.wallpaper_builder import WallpaperBuilder
|
|
|
|
|
from wallpaper_changer.wallpaper_setter import WallpaperSetter
|
|
|
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
2026-11-13 11:03:09 +01:00
|
|
|
def main() -> None:
|
|
|
|
|
args = parse_args()
|
2026-11-09 20:01:23 +01:00
|
|
|
|
2026-11-13 11:03:09 +01:00
|
|
|
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"
|
|
|
|
|
)
|
2026-11-09 20:01:23 +01:00
|
|
|
|
2026-11-13 11:03:09 +01:00
|
|
|
setup_logging(args.log_level, "wallpaper_changer")
|
2026-11-09 20:01:23 +01:00
|
|
|
|
2026-11-13 11:03:09 +01:00
|
|
|
if args.clear:
|
|
|
|
|
args.mode = "default"
|
|
|
|
|
args.folder = None
|
|
|
|
|
args.search = None
|
|
|
|
|
WallpaperSetter().set_ubuntu("~/.wallpaper/Default/default_wallpaper.jpg")
|
2026-11-09 20:01:23 +01:00
|
|
|
|
|
|
|
|
|
2026-11-13 11:03:09 +01:00
|
|
|
cfg = Config.load(args)
|
2026-11-09 20:01:23 +01:00
|
|
|
|
2026-11-13 11:03:09 +01:00
|
|
|
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.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=True)
|
|
|
|
|
|
|
|
|
|
if not args.disable_encryption and (
|
|
|
|
|
args.check_encryption or args.mode != "default" or args.folder is not None
|
|
|
|
|
):
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
imgs = image_repository.scan(
|
2026-11-09 20:01:23 +01:00
|
|
|
cfg.private_key,
|
|
|
|
|
disable_encryption=args.disable_encryption,
|
|
|
|
|
)
|
2026-11-13 11:03:09 +01:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
conf_dir=cfg.conf_dir,
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|