feat(wallpaper_changer): ignore hostname in config, set conf dir from argument, move to src
extra parameters for wallpaper_dir, conf_dir and private key move file to new src dir
This commit is contained in:
1 parent
de6dcd6c08
commit
ecb7ae032e
2 files changed
+67
-44
No files matched your search
@@ -0,0 +1,67 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
import socket
|
||||
|
||||
from wallpaper_changer.logging_utils import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
host: str
|
||||
img_dir: Path
|
||||
img_folder: str
|
||||
wallpaper_dir: Path
|
||||
conf_dir: Path
|
||||
private_key: Path
|
||||
|
||||
@staticmethod
|
||||
def argument_config_file(config_file , hostname: str | None = None) -> Path:
|
||||
config_file = Path(config_file).expanduser().resolve()
|
||||
logger.debug("fUsing Config file {config_file}")
|
||||
if not config_file.exists():
|
||||
config_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
config_file.write_text(
|
||||
f"# Wallpaper Changer Configuration File\n"
|
||||
)
|
||||
return config_file
|
||||
|
||||
@classmethod
|
||||
def load(cls, args):
|
||||
hostname = socket.gethostname()
|
||||
default_dir = Path().home() / "Nextcloud" / "Stuff" / "Wallpaper"
|
||||
mode_folders = {
|
||||
"default": "Desktop1920x1080/",
|
||||
"x": "corrupt",
|
||||
"i": "insta",
|
||||
}
|
||||
|
||||
if (
|
||||
args.check_encryption or args.decode_all or args.decode_argument or args.printNT or args.decryptNT or args.encryptNT
|
||||
) and args.mode == "default" and args.folder is None:
|
||||
args.mode = "x"
|
||||
|
||||
|
||||
img_folder = args.folder if args.folder is not None and args.mode != "i" else mode_folders[args.mode]
|
||||
img_path = Path(img_folder)
|
||||
if img_path.is_absolute():
|
||||
img_dir = img_path
|
||||
else:
|
||||
img_dir = default_dir / img_path
|
||||
if args.folder is not None:
|
||||
logger.warning(
|
||||
f"Assign relative folder arg to default directory: {img_dir}"
|
||||
)
|
||||
|
||||
conf_dir = Path(args.conf_dir).expanduser().resolve()
|
||||
|
||||
wallpaper_dir = conf_dir / "wallpaper"
|
||||
if args.temp_dir:
|
||||
wallpaper_dir = Path(args.temp_dir).expanduser().resolve() / "wallpaper"
|
||||
|
||||
if args.private_key:
|
||||
private_key = Path(args.private_key)
|
||||
else:
|
||||
private_key = conf_dir / "IMG_privateKey.pem"
|
||||
|
||||
return cls(hostname, img_dir, img_folder, wallpaper_dir, conf_dir, private_key)
|
||||
@@ -1,44 +0,0 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
import socket
|
||||
|
||||
from wallpaper_changer.logging_utils import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
host: str
|
||||
img_dir: Path
|
||||
img_folder: str
|
||||
wallpaper_dir: Path
|
||||
private_key: str
|
||||
|
||||
@staticmethod
|
||||
def argument_config_file(hostname: str | None = None) -> Path:
|
||||
config_file = Path.home() / "Wallpaper" / "wp.conf"
|
||||
if not config_file.exists():
|
||||
config_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
config_file.write_text(
|
||||
f"# Wallpaper Changer Configuration File\n"
|
||||
)
|
||||
return config_file
|
||||
|
||||
@classmethod
|
||||
def load(cls, args):
|
||||
hostname = socket.gethostname()
|
||||
if hostname == "vivohost":
|
||||
wallpaper_dir = Path("/tmp/wallpaper")
|
||||
img_folder = "Desktop1920x1080/"
|
||||
|
||||
if args.folder == "x":
|
||||
img_folder = "corrupt"
|
||||
elif args.folder == "insta":
|
||||
img_folder = "insta"
|
||||
|
||||
img_dir = Path("/home/lucas/Nextcloud/Stuff/Wallpaper/") / img_folder
|
||||
|
||||
private_key = Path(
|
||||
"file:/home/lucas/Nextcloud/Dokumente/Projekte/Server/quiethost/IMG_privateKey.pem"
|
||||
)
|
||||
return cls(hostname, img_dir, img_folder, wallpaper_dir, private_key)
|
||||
Reference in new issue
Block a user