<commit_before># -*- coding: utf-8 -*-

"""
m2bk.driver
~~~~~~~

Backup driver interface

:copyright: (c) 2015 by <NAME>
:license: MIT, see LICENSE for more details.

"""

import importlib
from .utils import debug
from .const import PKG_NAME
from . import log

# Current driver in use
_driver = None

# List of supported drivers to load
VALID_DRIVERS = [
    'dummy',
    's3'
]


def get_name():
    return _driver.get_name()


def load(*, name="dummy", options={}, dry_run=False, **kwargs):
    """
    Load a backup driver

    :param name(str, optional): name of the backup driver to load
    :param options(dict, optional): A dictionary passed to the driver
    :param dry_run(bool, optional): Whether to activate dry run mode
    :param \*\*kwargs: arbitrary keyword arguments
    :raises ValueError: if specified driver does not exist
    """
    global _driver

    # Try to load specified driver
    if name in VALID_DRIVERS:
        # log the thing first
        log.msg_debug("Attempting to load driver: {d}".format(d=name))

        # Load the driver (which is actually a python
        # module inside the drivers directory)
        _driver = importlib.import_module(".drivers.{name}"
                                          .format(name=name), __package__)
        if _driver:
            _driver.load(dry_run=dry_run, **options)
            log.msg_debug("Backup driver '{driver}'" +
                          " has been loaded successfully!"
                          .format(driver=_driver.get_name()))
    else:
        raise ValueError('Invalid backup driver name')


def backup_file(*, file, host):
    """
    Perform backup action on set driver

    :param file: Name of the file to be used by the driver
    :param host: Corresponding host name associated with file
    """
    if _driver:
        log.msg_debug("[{driver}] Backing up file '{file}'"
                      .format(driver=_driver.get_name(), file=file))
        _driver.backup_file(file=file, host=host)


def dispose():
    """
    Perform cleanup on set driver
    """
    if _driver:
        log.msg_debug("[{driver}] dispose".format(driver=_driver.get_name()))
        _driver.dispose()
<commit_msg>A more explicit exception when an invalid driver is specified<commit_after># -*- coding: utf-8 -*-

"""
m2bk.driver
~~~~~~~

Backup driver interface

:copyright: (c) 2015 by <NAME>
:license: MIT, see LICENSE for more details.

"""

import importlib
from .utils import debug
from .const import PKG_NAME
from . import log

# Current driver in use
_driver = None

# List of supported drivers to load
VALID_DRIVERS = [
    'dummy',
    's3'
]


def get_name():
    return _driver.get_name()


def load(*, name="dummy", options={}, dry_run=False, **kwargs):
    """
    Load a backup driver

    :param name(str, optional): name of the backup driver to load
    :param options(dict, optional): A dictionary passed to the driver
    :param dry_run(bool, optional): Whether to activate dry run mode
    :param \*\*kwargs: arbitrary keyword arguments
    :raises ValueError: if specified driver does not exist
    """
    global _driver

    # Try to load specified driver
    if name in VALID_DRIVERS:
        # log the thing first
        log.msg_debug("Attempting to load driver: {d}".format(d=name))

        # Load the driver (which is actually a python
        # module inside the drivers directory)
        _driver = importlib.import_module(".drivers.{name}"
                                          .format(name=name), __package__)
        if _driver:
            _driver.load(dry_run=dry_run, **options)
            log.msg_debug("Backup driver '{driver}'" +
                          " has been loaded successfully!"
                          .format(driver=_driver.get_name()))
    else:
        raise ValueError("Invalid backup driver name: {driver}"
                         .format(driver=name))


def backup_file(*, file, host):
    """
    Perform backup action on set driver

    :param file: Name of the file to be used by the driver
    :param host: Corresponding host name associated with file
    """
    if _driver:
        log.msg_debug("[{driver}] Backing up file '{file}'"
                      .format(driver=_driver.get_name(), file=file))
        _driver.backup_file(file=file, host=host)


def dispose():
    """
    Perform cleanup on set driver
    """
    if _driver:
        log.msg_debug("[{driver}] dispose".format(driver=_driver.get_name()))
        _driver.dispose()

{'fraction_non_alphanumeric': 0.10979955456570156, 'fraction_numerical': 0.0031180400890868597, 'mean_word_length': 2.553006329113924, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2704007', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1247, 'n_words': 431}