Warning

This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for galaxy.util.submodules

from __future__ import absolute_import

import logging
from os import listdir

log = logging.getLogger(__name__)


[docs]def submodules(module): unsorted_submodule_names = __submodule_names(module) submodule_names = sorted(unsorted_submodule_names, reverse=True) submodules = [] for submodule_name in submodule_names: full_submodule = "%s.%s" % (module.__name__, submodule_name) try: __import__(full_submodule) submodule = getattr(module, submodule_name) submodules.append(submodule) except BaseException: message = "%s dynamic module could not be loaded (traceback follows):" % (full_submodule) log.exception(message) return submodules
def __submodule_names(module): module_dir = module.__path__[0] names = [] for fname in listdir(module_dir): if not(fname.startswith("_")) and fname.endswith(".py"): submodule_name = fname[:-len(".py")] names.append(submodule_name) return names