<commit_before># Module:	__init__
# Date:		1st February 2009
# Author:	<NAME>, prologic at shortcircuit dot net dot au

"""Circuits Library - Drivers

circuits.lib.drivers contains drivers for other sources of events.
"""

class DriverError(Exception): pass

from pygame_driver import PyGameDriver
<commit_msg>drivers: Added a load function to load all available drivers into the drivers namespace as well as their Component<commit_after># Module:	__init__
# Date:		1st February 2009
# Author:	<NAME>, prologic at shortcircuit dot net dot au

"""Circuits Library - Drivers

circuits.lib.drivers contains drivers for other sources of events.
"""

from os import listdir as _listdir
from os.path import dirname as _dirname
from os.path import splitext as _splitext
from traceback import format_exc as _format_exc
from inspect import getmembers as _getmembers, isclass as _isclass

from circuits.core import Component as _Component

class DriverError(Exception): pass

def modules():
    for filename in _listdir(_dirname(__file__)):
        root, ext = _splitext(filename)
        if not root == "__init__" and ext == ".py":
            yield root

def load():
    drivers = {}
    for driver in modules():
        try:
            module = __import__(driver, globals(), locals(), [__package__])
            p1 = lambda x: _isclass(x) and issubclass(x, _Component)
            p2 = lambda x: x is not _Component
            predicate = lambda x: p1(x) and p2(x)
            for name, component in _getmembers(module, predicate):
                globals()[name] = component
            globals()[driver] = drivers[driver] = module
        except DriverError, e:
            _warn("Cannot load driver '%s': %s" % (driver, e))
        except Exception, e:
            print "Error loadign driver '%s': %s" % (driver, e)
            print _format_exc()
    return drivers

drivers = load()

{'fraction_non_alphanumeric': 0.0875796178343949, 'fraction_numerical': 0.0074309978768577496, 'mean_word_length': 3.170353982300885, 'pattern_counts': {'":': 1, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3375418', 'n_tokens_mistral': 555, 'n_tokens_neox': 530, 'n_words': 210}