From 69298dc369ddfecb0ae3374dea01ca45a2b07ef7 Mon Sep 17 00:00:00 2001 From: bkbilly Date: Sun, 30 Oct 2022 18:49:48 +0200 Subject: [PATCH] create folder structure for config files using relative paths --- README.md | 2 +- lnxlink/__main__.py | 12 +++++++----- lnxlink/config.py | 3 +++ pyproject.toml | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 87b80c7..ac315aa 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ It is inspired by [IOT Link](https://iotlink.gitlab.io/). Install or update: ```shell pip3 install -U lnxlink -lnxlink /absolute/path/to/config.yaml +lnxlink /path/to/config.yaml ``` You can manually update the configuration file `config.yaml` and restart the service with the use of systemctl: ```shell diff --git a/lnxlink/__main__.py b/lnxlink/__main__.py index 0409ead..44c3393 100755 --- a/lnxlink/__main__.py +++ b/lnxlink/__main__.py @@ -1,16 +1,17 @@ #!/usr/bin/env python3 +import os import yaml -import paho.mqtt.client as mqtt import time import signal import threading import json -from . import modules import traceback import importlib.metadata import platform import argparse +import paho.mqtt.client as mqtt +from . import modules from . import config version = importlib.metadata.version(__package__ or __name__) @@ -225,9 +226,10 @@ def main(): required=True) args = parser.parse_args() - config.setup_config(args.config) - config.setup_systemd(args.config) - lnxlink = LNXlink(args.config) + config_file = os.path.abspath(args.config) + config.setup_config(config_file) + config.setup_systemd(config_file) + lnxlink = LNXlink(config_file) lnxlink.monitor_run_thread() killer = GracefulKiller() diff --git a/lnxlink/config.py b/lnxlink/config.py index 1dbdb01..031abd5 100755 --- a/lnxlink/config.py +++ b/lnxlink/config.py @@ -6,6 +6,7 @@ import os import subprocess import shutil +from pathlib import Path github_repository = "bkbilly/lnxlink/master" @@ -17,6 +18,7 @@ def setup_config(config_path): url = f"https://raw.githubusercontent.com/{github_repository}/config_temp.yaml" r = requests.get(url) try: + Path(config_path).parent.mkdir(parents=True, exist_ok=True) with open(config_path, 'wb') as config: config.write(r.content) print(f"Created new template: {config_path}") @@ -135,6 +137,7 @@ def setup_systemd(config_path): sudo, cmd_user, service_url, service_location = get_service_vars(user_service) # Install on SystemD + Path(service_location).mkdir(parents=True, exist_ok=True) r = requests.get(service_url) with open(f"{service_location}/lnxlink.service", 'wb') as config: exec_cmd = f"{shutil.which('lnxlink')} -c {config_path}" diff --git a/pyproject.toml b/pyproject.toml index 5833cbf..aa1b93d 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "lnxlink" -version = "2022.10.2" +version = "2022.10.3" description = "Internet Of Things (IOT) integration with Linux using MQTT" readme = "README.md" keywords = ["lnxlink"]