From 10f64da34bb81089ef74f0784f8589baed35c908 Mon Sep 17 00:00:00 2001 From: Artanicus Date: Sat, 18 Mar 2023 13:57:14 +0200 Subject: [PATCH] Use pathlib instead of glob for loading updater files This allows for recursively loading personal_commands which enables flexibility in distributing them as separate directories, for example loading the ATV command library as as a submodule. --- mapadroid/updater/updater.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mapadroid/updater/updater.py b/mapadroid/updater/updater.py index e440866e2..e533a0af8 100644 --- a/mapadroid/updater/updater.py +++ b/mapadroid/updater/updater.py @@ -1,11 +1,11 @@ import asyncio -import glob import json import os import re import time from asyncio import CancelledError, Task from datetime import datetime, timedelta +from pathlib import Path from typing import AsyncGenerator, Dict, List, Optional, Tuple, Union import asyncio_rlock @@ -98,14 +98,14 @@ async def _load_jobs(self): if os.path.exists('commands.json'): await self._load_jobs_from_file('commands.json') # 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: await self._load_jobs_from_file(command_file) except Exception as e: logger.error('Cannot add job {} - Reason: {}', command_file, e) # Read all .apk files in the upload dir - for apk_file in glob.glob(str(MadGlobals.application_args.upload_path) + "/*.apk"): + for apk_file in Path(MadGlobals.application_args.upload_path).rglob("*.apk"): created: int = int(os.path.getmtime(apk_file)) self._available_jobs[os.path.basename(apk_file)] = [SubJob(TYPE=JobType.INSTALLATION,