# Path: dizzy/log.py
# def print_dizzy(value, level=NORMAL):
#     if print_level >= level:
#         with print_lock:
#             print(print_colors[level], end='')
#             print(value)
#             if isinstance(value, Exception):
#                 ex_type, ex, tb = exc_info()
#                 print_tb(tb)
#             print(ENDC, end='')
# 
# VERBOSE_1 = 3
# 
# VERBOSE_2 = 4
# 
# DEBUG = 5


from zipimport import zipimporter
from dizzy.log import print_dizzy, VERBOSE_1, VERBOSE_2, DEBUG
import sys
#       OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



class DizzyModule(object):
    def __init__(self, path, config):
        self.path = path
        self.global_config = config
        self.zipimport = zipimporter(path)
        self.config = self.zipimport.load_module("config")

    def load(self):
        inventory = self.zipimport.load_module(self.name).__all__

        if "deps" in inventory:
            depspath = self.path + "/" + self.name + "/deps"
            sys.path.insert(0, depspath)
            print_dizzy("mod:%s/load: added dependency path '%s'" % (self.name, depspath), VERBOSE_1)

        sys.path.insert(0, self.path)
        if "dizz" in inventory:
            dizz = __import__(self.name + ".dizz").dizz
            self.dizz = []
            for i in dizz.__all__:
                name = self.name + "/dizz/" + i
                obj = dizz.__loader__.get_data(name)
                self.dizz.append(name)
                self.global_config["DIZZ"][name] = obj.decode(self.global_config["GLOBALS"]["CODEC"])

            print_dizzy("mod:%s/load: Loaded %d dizz files." % (self.name, len(self.dizz)), VERBOSE_1)

# Path: dizzy/log.py
# def print_dizzy(value, level=NORMAL):
#     if print_level >= level:
#         with print_lock:
#             print(print_colors[level], end='')
#             print(value)
#             if isinstance(value, Exception):
#                 ex_type, ex, tb = exc_info()
#                 print_tb(tb)
#             print(ENDC, end='')
# 
# VERBOSE_1 = 3
# 
# VERBOSE_2 = 4
# 
# DEBUG = 5


# Path: dizzy/module.py
from zipimport import zipimporter
from dizzy.log import print_dizzy, VERBOSE_1, VERBOSE_2, DEBUG
import sys

#       OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



class DizzyModule(object):
    def __init__(self, path, config):
        self.path = path
        self.global_config = config
        self.zipimport = zipimporter(path)
        self.config = self.zipimport.load_module("config")

    def load(self):
        inventory = self.zipimport.load_module(self.name).__all__

        if "deps" in inventory:
            depspath = self.path + "/" + self.name + "/deps"
            sys.path.insert(0, depspath)
            print_dizzy("mod:%s/load: added dependency path '%s'" % (self.name, depspath), VERBOSE_1)

        sys.path.insert(0, self.path)
        if "dizz" in inventory:
            dizz = __import__(self.name + ".dizz").dizz
            self.dizz = []
            for i in dizz.__all__:
                name = self.name + "/dizz/" + i
                obj = dizz.__loader__.get_data(name)
                self.dizz.append(name)
                self.global_config["DIZZ"][name] = obj.decode(self.global_config["GLOBALS"]["CODEC"])

            print_dizzy("mod:%s/load: Loaded %d dizz files." % (self.name, len(self.dizz)), VERBOSE_1)

            print_dizzy("mod:%s/load: %s" % (self.name, self.dizz), DEBUG)