feat: files.get_subdirectories include and exclude can now be lists

Rafael Uzarowski committed Mar 15, 2025 at 14:22 UTC 274d7993d5f4af69f1ad76f64bc678bd3fd37846
1 file changed +7 -3
python/helpers/files.py
+7 -3
@@ -250,16 +250,20 @@ def get_base_dir():
250 return base_dir
251
252
253 -def get_subdirectories(relative_path: str, include: str = "*", exclude=None):
253 +def get_subdirectories(relative_path: str, include: str | list[str] = "*", exclude: str | list[str] | None = None):
254 abs_path = get_abs_path(relative_path)
255 if not os.path.exists(abs_path):
256 return []
257 + if isinstance(include, str):
258 + include = [include]
259 + if isinstance(exclude, str):
260 + exclude = [exclude]
261 return [
262 subdir
263 for subdir in os.listdir(abs_path)
264 if os.path.isdir(os.path.join(abs_path, subdir))
261 - and fnmatch(subdir, include)
262 - and (exclude is None or not fnmatch(subdir, exclude))
265 + and any(fnmatch(subdir, inc) for inc in include)
266 + and (exclude is None or not any(fnmatch(subdir, exc) for exc in exclude))
267 ]
268
269