[V3 Downloader] List all loaded and unloaded cogs (#1019)

* Working without core cogs

* Working with core cogs

* Fix path search logic

* Fix docstring

* Type fix
This commit is contained in:
Will
2017-10-22 21:13:23 -04:00
committed by GitHub
parent 3febc94871
commit d346216fa2
2 changed files with 42 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ from importlib.machinery import ModuleSpec
from pathlib import Path
from typing import Tuple, Union, List
import redbot.cogs
from . import checks
from .config import Config
from .i18n import CogI18n
@@ -45,14 +47,19 @@ class CogManager:
"""
conf_paths = await self.conf.paths()
other_paths = self._paths
core_paths = await self.core_paths()
all_paths = set(list(conf_paths) + list(other_paths))
all_paths = set(list(conf_paths) + list(other_paths) + core_paths)
paths = [Path(p) for p in all_paths]
if self.install_path not in paths:
paths.insert(0, await self.install_path())
return tuple(p.resolve() for p in paths if p.is_dir())
async def core_paths(self) -> List[Path]:
core_paths = [Path(p) for p in redbot.cogs.__path__]
return core_paths
async def install_path(self) -> Path:
"""Get the install path for 3rd party cogs.
@@ -209,6 +216,17 @@ class CogManager:
raise RuntimeError("No module by the name of '{}' was found"
" in any available path.".format(name))
async def available_modules(self) -> List[str]:
"""Finds the names of all available modules to load.
"""
paths = (await self.install_path(), ) + await self.paths()
paths = [str(p) for p in paths]
ret = []
for finder, module_name, _ in pkgutil.iter_modules(paths):
ret.append(module_name)
return ret
@staticmethod
def invalidate_caches():
"""Re-evaluate modules in the py cache.