# Path: web/common.py
# def parse_config():
#     config_dict = {}
#     config = ConfigParser.ConfigParser(allow_no_value=True)
# 
#     # Order of precedence is ~/.volutility.conf, volutility.conf, volutility.conf.sample
# 
#     if os.path.exists(os.path.join(os.path.expanduser("~"), '.volutility.conf')):
#         conf_file = os.path.join(os.path.expanduser("~"), '.volutility.conf')
# 
#     elif os.path.exists('volutility.conf'):
#         conf_file = 'volutility.conf'
# 
#     else:
#         conf_file = 'volutility.conf.sample'
#         logger.warning('Using default config file. Check your volutility.conf file exists')
# 
#     valid = config.read(conf_file)
#     if len(valid) > 0:
#         config_dict['valid'] = True
#         for section in config.sections():
#             section_dict = {}
#             for key, value in config.items(section):
#                 section_dict[key] = value
#             config_dict[section] = section_dict
#     else:
#         config_dict['valid'] = False
#         logger.error('Unable to find a valid volutility.conf file.')
# 
#     logger.info("Loaded configuration from {0}".format(conf_file))
# 
#     return config_dict
# 
# class Extension(object):
# 
#     '''
#     ToDo: Need to load the HTML and put it in the right place
#     extension_inject_point = None
# 
#     Need a single place in the DB so we can always call it out. Or do i?
#     Look at this
# 
#     '''
# 
#     extension_name = None
#     extension_type = None
#     render_type = None
#     render_data = None
#     render_file = None
#     render_javascript = None
#     extra_js = None
# 
#     def __init__(self):
#         pass
# 
#     def set_request(self, request):
#         self.request = request
# 
#     def set_config(self, config):
#         self.config = config
# 
#     def set_plugin_results(self, data):
#         self.plugin_results = data


import os
import pkgutil
import inspect
import logging
    import extensions
from web.common import parse_config, Extension

    extension_list = dict()

    disable_list = config['extensions']['disabled'].split(',')

    # Walk recursively through all modules and packages.
    for loader, extension_name, ispkg in pkgutil.walk_packages(extensions.__path__, extensions.__name__ + '.'):
        # If current item is a package, skip.
        if ispkg:
            continue

        ext_name = extension_name.split('.')[-1]

        if ext_name in disable_list:
            logger.info("Disabled Extension: {0}".format(ext_name))
            continue

        # Try to import the module, otherwise skip.
        try:
            ext = __import__(extension_name, globals(), locals(), ['dummy'], -1)
        except Exception as e:
            logger.error("There was an error importing the extension {0}: {1}".format(extension_name, e))
            continue


        # Walk through all members of currently imported modules.
        for member_name, member_object in inspect.getmembers(ext):
            # Check if current member is a class.
            if inspect.isclass(member_object):
                # Yield the class if it's a subclass of Module.

# Path: web/common.py
# def parse_config():
#     config_dict = {}
#     config = ConfigParser.ConfigParser(allow_no_value=True)
# 
#     # Order of precedence is ~/.volutility.conf, volutility.conf, volutility.conf.sample
# 
#     if os.path.exists(os.path.join(os.path.expanduser("~"), '.volutility.conf')):
#         conf_file = os.path.join(os.path.expanduser("~"), '.volutility.conf')
# 
#     elif os.path.exists('volutility.conf'):
#         conf_file = 'volutility.conf'
# 
#     else:
#         conf_file = 'volutility.conf.sample'
#         logger.warning('Using default config file. Check your volutility.conf file exists')
# 
#     valid = config.read(conf_file)
#     if len(valid) > 0:
#         config_dict['valid'] = True
#         for section in config.sections():
#             section_dict = {}
#             for key, value in config.items(section):
#                 section_dict[key] = value
#             config_dict[section] = section_dict
#     else:
#         config_dict['valid'] = False
#         logger.error('Unable to find a valid volutility.conf file.')
# 
#     logger.info("Loaded configuration from {0}".format(conf_file))
# 
#     return config_dict
# 
# class Extension(object):
# 
#     '''
#     ToDo: Need to load the HTML and put it in the right place
#     extension_inject_point = None
# 
#     Need a single place in the DB so we can always call it out. Or do i?
#     Look at this
# 
#     '''
# 
#     extension_name = None
#     extension_type = None
#     render_type = None
#     render_data = None
#     render_file = None
#     render_javascript = None
#     extra_js = None
# 
#     def __init__(self):
#         pass
# 
#     def set_request(self, request):
#         self.request = request
# 
#     def set_config(self, config):
#         self.config = config
# 
#     def set_plugin_results(self, data):
#         self.plugin_results = data


# Path: web/modules.py
import os
import pkgutil
import inspect
import logging
    import extensions
from web.common import parse_config, Extension


    extension_list = dict()

    disable_list = config['extensions']['disabled'].split(',')

    # Walk recursively through all modules and packages.
    for loader, extension_name, ispkg in pkgutil.walk_packages(extensions.__path__, extensions.__name__ + '.'):
        # If current item is a package, skip.
        if ispkg:
            continue

        ext_name = extension_name.split('.')[-1]

        if ext_name in disable_list:
            logger.info("Disabled Extension: {0}".format(ext_name))
            continue

        # Try to import the module, otherwise skip.
        try:
            ext = __import__(extension_name, globals(), locals(), ['dummy'], -1)
        except Exception as e:
            logger.error("There was an error importing the extension {0}: {1}".format(extension_name, e))
            continue


        # Walk through all members of currently imported modules.
        for member_name, member_object in inspect.getmembers(ext):
            # Check if current member is a class.
            if inspect.isclass(member_object):
                # Yield the class if it's a subclass of Module.

                if issubclass(member_object, Extension) and member_object is not Extension: