- all_current_paths = []
- if isinstance(imported_package.__path__, str):
- all_current_paths.append(imported_package.__path__)
- else:
- all_current_paths.extend([x for x in imported_package.__path__])
-
- for pkg_path in all_current_paths:
- if pkg_path not in self.seen_paths:
- self.seen_paths.append(pkg_path)
-
- # Get subdirectories of package
- child_pkgs = [p for p in os.listdir(pkg_path) if os.path.isdir(os.path.join(pkg_path, p))]
-
- # Walk through each subdirectory
- for child_pkg in child_pkgs:
- self.walk_package(package + '.' + child_pkg)
-
-def findall():
- logger.debug("Searching for parsers in {0}".format(parser_dir))
- path.append(os.path.abspath(parser_dir))
- parsers = []
- parser_candidates = os.listdir(parser_dir)
- for parser_name in parser_candidates:
- location = os.path.join(parser_dir, parser_name)
- if not os.path.isdir(location) or not main_module + '.py' in os.listdir(location):
- logger.warning("Rejecting parser {0} due to invalid structure".format(location))
- continue
- info = imp.find_module(main_module, [location])
- parser_obj = Parser(parser_name, location, info)
- parsers.append(parser_obj)
- logger.debug("Added parser {0}".format(parser_obj.name))
- return parsers
-
-def search(name):
- logger.debug("Searching for parser {0}".format(name))
- if name in default_parsers:
- logger.debug("Found parser {0} in default modules".format(name))
- return Parser('.'.join(__name__.split('.')[:-1] + [name]))
- elif name in deprecated_parsers:
- logger.debug("Found parser {0} in deprecated modules".format(name))
- return Parser('.'.join(__name__.split('.')[:-1] + [name]))
- else:
- return None
-
-def load(parser):
- logger.debug("Loading parser {0} from {1}".format(parser.name, parser.path if parser.path != None else "defaults"))
- return importlib.import_module(parser.name)