Skip to content

Commit

Permalink
Find and read personal commands recursively, allowing dirs
Browse files Browse the repository at this point in the history
This simplifies organization and for example adding multiple upstream
sources of commands as different directories.
  • Loading branch information
jinnatar committed Jul 17, 2022
1 parent 89aebdb commit 8ec61ef
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mapadroid/utils/updater.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import glob
import json
import os
import re
import time
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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8ec61ef

Please sign in to comment.