Files
Server-scripts/wallpaper_changer/main.py
T
Lucas Vivo d8f9ac5513 feat(wallpaper-changer.py): add modular Python port
Introduce a Python CLI for selecting, processing, and setting
wallpapers,
including encrypted image and naming-table workflows, monitor-aware
image
composition, search and exclusion filters, and migration and usage
notes.

Module guide:
- main.py: validates command combinations and coordinates configuration,
  encryption commands, image processing, monitor detection, wallpaper
  composition, and GNOME wallpaper setting.
- wallpaper_changer/__init__.py: marks the application package.
- wallpaper_changer/argument_parser.py: defines CLI options and merges
  command-line arguments with arguments loaded from the config file.
- wallpaper_changer/config.py: loads host-specific image, wallpaper, and
  private-key settings.
- wallpaper_changer/encryption_manager.py: reads and writes legacy
OpenSSL
  encrypted files and loads, stores, encrypts, or decrypts naming
tables.
- wallpaper_changer/image_repository.py: scans and converts images,
manages
  encrypted images and naming-table entries, and handles image decoding
and  sequential filename correction.
- wallpaper_changer/logging_utils.py: configures and retrieves the
project's custom logger.
- wallpaper_changer/monitor_manager.py: discovers monitor layouts from
DRM data or host configuration files.
- wallpaper_changer/naming_table.py: loads legacy plaintext naming-table
entries.
- wallpaper_changer/wallpaper_builder.py: filters and selects images,
decrypts as needed, and composes a labeled multi-monitor wallpaper.
- wallpaper_changer/wallpaper_setter.py: sets GNOME background settings
using gsettings.
2026-11-09 20:09:12 +01:00

125 lines
3.5 KiB
Python
Executable File

#!/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)