Exemple #1
0
def load_plugin_directory(directory_path):
    """
    Loads all python files in a directory and loads any plugins that are found.

    Args:
        directory_path:  Path to a directory containing your python plugin files.

    Examples:
        >>> fls.plugin.load_plugin('plugins/')
    """
    for plugin in os.listdir(filesystem.get_path(directory_path)):
        load_plugin(plugin)
Exemple #2
0
def load_plugin(file_path):
    """
    Loads a plugin from a given file path.

    Args:
        file_path:  Path to a python file with a plugin.

    Examples:
        >>> fls.plugin.load_plugin('plugins/my_plugin.py')
    """
    file_path = filesystem.get_path(file_path).split(os.sep)
    sys.path.append(os.sep.join(file_path[:-1]))
    importlib.import_module(os.sep.join(file_path))
Exemple #3
0
def setup_logfile(file_path):
    """
    Sets up logging to files with a reasonable default logging format.

    The format used is '<level name> - <time> - <name>: <message>'.

    Args:
        file_path:  The file path used for logging.
    """
    root_logger = logging.getLogger()
    log_file_handler = logging.FileHandler(filesystem.get_path(file_path))
    log_formatter = logging.Formatter(_log_format)
    log_file_handler.setFormatter(log_formatter)
    root_logger.addHandler(log_file_handler)
    root_logger.setLevel(logging.INFO)