From 8ec61efc72819fe35a6b7fc27039cb7f3efd7f50 Mon Sep 17 00:00:00 2001 From: Artanicus Date: Wed, 23 Feb 2022 16:28:53 +0200 Subject: [PATCH] Find and read personal commands recursively, allowing dirs This simplifies organization and for example adding multiple upstream sources of commands as different directories. --- mapadroid/utils/updater.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mapadroid/utils/updater.py b/mapadroid/utils/updater.py index b4a77fc69..1c1d89fa9 100644 --- a/mapadroid/utils/updater.py +++ b/mapadroid/utils/updater.py @@ -1,4 +1,3 @@ -import glob import json import os import re @@ -6,6 +5,7 @@ from datetime import datetime, timedelta from enum import Enum from multiprocessing import Event, Queue +from pathlib import Path from queue import Empty from threading import RLock, Thread @@ -91,16 +91,16 @@ def init_jobs(self): # load personal commands - for command_file in glob.glob(os.path.join("personal_commands", "*.json")): + for command_file in Path("personal_commands").rglob("*.json"): try: with open(command_file) as personal_command: - peronal_cmd = json.loads(personal_command.read()) - for command in peronal_cmd: + personal_cmd = json.load(personal_command) + for command in personal_cmd: if command in self._commands: logger.error("Command {} already exist - skipping", command) else: logger.info('Loading personal command: {}', command) - self._commands[command] = peronal_cmd[command] + self._commands[command] = personal_cmd[command] except Exception as e: logger.error('Cannot add job {} - Reason: {}', command_file, e)