Exemplo n.º 1
0
def add_subcommand(subparsers, sub_cmd, cmd_module_path):
    """
    Load the subcommand module and then add the subcommand to the available
    subcommands in the given subparsers collection.

    subparsers has to be the return value of the add_parsers() method on an
    argparse.ArgumentParser.
    """
    m_path, m_name = os.path.split(cmd_module_path)
    module_name = os.path.splitext(m_name)[0]

    cc_bin = os.path.dirname(os.path.realpath(__file__))
    full_module_path = os.path.join(cc_bin, '..', 'lib', 'python3', m_path)

    # Load the module named as the argument.
    cmd_spec = machinery.PathFinder().find_spec(module_name,
                                                [full_module_path])
    command_module = cmd_spec.loader.load_module(module_name)

    # Now that the module is loaded, construct an ArgumentParser for it.
    sc_parser = subparsers.add_parser(
        sub_cmd, **command_module.get_argparser_ctor_args())

    # Run the method which adds the arguments to the subcommand's handler.
    command_module.add_arguments_to_parser(sc_parser)
Exemplo n.º 2
0
    def __init__(self, core):
        self.core = core
        # module name -> module object
        self.modules = {}
        # module name -> plugin object
        self.plugins = {}
        # module name -> dict of commands loaded for the module
        self.commands = {}
        # module name -> list of event_name/handler pairs loaded for the module
        self.event_handlers = {}
        # module name -> dict of tab types; tab type -> commands
        # loaded by the module
        self.tab_commands = {}
        # module name → dict of keys/handlers loaded for the module
        self.keys = {}
        # module name → dict of tab types; tab type → list of keybinds (tuples)
        self.tab_keys = {}
        self.roster_elements = {}

        from importlib import machinery
        self.finder = machinery.PathFinder()

        self.initial_set_plugins_dir()
        self.initial_set_plugins_conf_dir()
        self.fill_load_path()

        self.plugin_api = PluginAPI(core, self)
Exemplo n.º 3
0
def load_modules(directory, module_dir):
    result = {}
    filename = "scraper.py"

    subdirs = refl.get_directories(f"{directory}/{module_dir}")
    for module_name in subdirs:
        path = f"{directory}/{module_dir}/{module_name}/{filename}"
        if not os.path.exists(path):
            continue

        namespace = refl.path_to_namespace(
            f"{module_dir}/{module_name}/{filename}")
        finder = machinery.PathFinder()
        spec = util.find_spec(f"{namespace}")
        module = util.module_from_spec(spec)
        spec.loader.exec_module(module)

        module_class_name, module_class = refl.get_class(module, namespace)
        result[module_name] = module_class()

    return result
Exemplo n.º 4
0
def add_subcommand(subparsers, sub_cmd, cmd_module_path, lib_dir_path):
    """
    Load the subcommand module and then add the subcommand to the available
    subcommands in the given subparsers collection.

    subparsers has to be the return value of the add_parsers() method on an
    argparse.ArgumentParser.
    """
    m_path, m_name = os.path.split(cmd_module_path)

    module_name = os.path.splitext(m_name)[0]
    target = [os.path.join(lib_dir_path, m_path)]

    # Load the module named as the argument.
    cmd_spec = machinery.PathFinder().find_spec(module_name, target)
    command_module = cmd_spec.loader.load_module(module_name)

    # Now that the module is loaded, construct an ArgumentParser for it.
    sc_parser = subparsers.add_parser(
        sub_cmd, **command_module.get_argparser_ctor_args())

    # Run the method which adds the arguments to the subcommand's handler.
    command_module.add_arguments_to_parser(sc_parser)
def get_scrapers(directory, scraper_dir):
    result = {}
    filename = "scraper.py"

    subdirs = refl.get_directories(f"{directory}/{scraper_dir}")
    for subdir in subdirs:
        scraper_name = subdir
        path = f"{directory}/{scraper_dir}/{subdir}/{filename}"
        if not os.path.exists(path):
            continue

        namespace = refl.path_to_namespace(f"{scraper_dir}/{subdir}/{filename}")
        finder = machinery.PathFinder()
        spec = util.find_spec(f"{namespace}")
        #spec = machinery.find_spec(f"{path}")
        module = util.module_from_spec(spec)
#        sys.modules[module_name] = module
        spec.loader.exec_module(module)

#        module = refl.get_module(namespace)
        module_class_name, module_class = refl.get_class(module, namespace)
        result[subdir] = module_class()

    return result
Exemplo n.º 6
0
    from poezio.config import config
except ImportError:
    if __name__ != "__main__":
        raise

import curses
import functools
import os
from typing import Dict, List, Union, Tuple, Optional
from pathlib import Path
from os import path
from poezio import colors, xdg

from importlib import machinery

finder = machinery.PathFinder()


class Theme:
    """
    The theme class, from which all themes should inherit.
    All of the following values can be replaced in subclasses, in
    order to create a new theme.

    Do not edit this file if you want to change the theme to suit your
    needs. Create a new theme and share it if you think it can be useful
    for others.
    """
    @classmethod
    def color_role(cls, role: str):
        role_mapping = {
Exemplo n.º 7
0
def load_geocoder(repo_path: str) -> Any:
    geocoder_path = os.path.join(repo_path, GEOCODER_REPO_PATH)
    geocodes_path = os.path.join(geocoder_path, GEOCODER_DB_FILENAME)
    spec = machinery.PathFinder().find_spec(GEOCODER_MODULE, [geocoder_path])
    geocoder_module = spec.loader.load_module()
    return geocoder_module.CSVGeocoder(geocodes_path, lambda x: None)