# Path: lib/io.py
# def load_python_file(path):
#     return SourceFileLoader("", path).load_module()
# 
# Path: lib/helpers.py
# def mergedicts(a, b, path=None):
#     "merges b into a"
#     if path is None:
#         path = []
# 
#     for key in b:
#         if key in a:
#             if isinstance(a[key], dict) and isinstance(b[key], dict):
#                 mergedicts(a[key], b[key], path + [str(key)])
#             elif a[key] == b[key]:
#                 pass  # same leaf value
#             else:
#                 a[key] = b[key]
#         else:
#             a[key] = b[key]
#     return a


import itertools
import os
import shutil
import zipfile
from .io import load_python_file
from .helpers import mergedicts
            else:
                template_path = "%s/%s" % (sublimious_dir, "templates/.sublimious")
                shutil.copyfile(template_path, config_path)

            print("[sublimious] no config found. Copied template.")

        config_file = load_python_file(config_path)

        # Collect all layers and layer configurations
        for layer in config_file.layers:

            try:
                if self.is_zip:
                    layer_init = __import__("layers.%s.layer" % layer, globals(), locals(), ['Layer'])
                else:
                    layer_init_file = "%s/%s/layer.py" % (sublimious_dir, "layers/%s" % layer)
                    layer_init = load_python_file(layer_init_file)
            except ImportError:
                print("[sublimious] tried to load layer '%s' but couldn't import it. Does it exist?" % layer)
                continue

            self.layers.append(layer_init.Layer())
            self.commands.append("layers.%s.commands" % layer)

            if self.is_zip:
                settings = eval(self.zip_file.read("layers/%s/settings.py" % layer))
            else:
                layer_settings_file = "%s/%s/settings.py" % (sublimious_dir, "layers/%s" % layer)
                settings = eval(open(layer_settings_file, 'r').read())


# Path: lib/io.py
# def load_python_file(path):
#     return SourceFileLoader("", path).load_module()
# 
# Path: lib/helpers.py
# def mergedicts(a, b, path=None):
#     "merges b into a"
#     if path is None:
#         path = []
# 
#     for key in b:
#         if key in a:
#             if isinstance(a[key], dict) and isinstance(b[key], dict):
#                 mergedicts(a[key], b[key], path + [str(key)])
#             elif a[key] == b[key]:
#                 pass  # same leaf value
#             else:
#                 a[key] = b[key]
#         else:
#             a[key] = b[key]
#     return a


# Path: lib/collector.py
import itertools
import os
import shutil
import zipfile
from .io import load_python_file
from .helpers import mergedicts

            else:
                template_path = "%s/%s" % (sublimious_dir, "templates/.sublimious")
                shutil.copyfile(template_path, config_path)

            print("[sublimious] no config found. Copied template.")

        config_file = load_python_file(config_path)

        # Collect all layers and layer configurations
        for layer in config_file.layers:

            try:
                if self.is_zip:
                    layer_init = __import__("layers.%s.layer" % layer, globals(), locals(), ['Layer'])
                else:
                    layer_init_file = "%s/%s/layer.py" % (sublimious_dir, "layers/%s" % layer)
                    layer_init = load_python_file(layer_init_file)
            except ImportError:
                print("[sublimious] tried to load layer '%s' but couldn't import it. Does it exist?" % layer)
                continue

            self.layers.append(layer_init.Layer())
            self.commands.append("layers.%s.commands" % layer)

            if self.is_zip:
                settings = eval(self.zip_file.read("layers/%s/settings.py" % layer))
            else:
                layer_settings_file = "%s/%s/settings.py" % (sublimious_dir, "layers/%s" % layer)
                settings = eval(open(layer_settings_file, 'r').read())


            self.collected_config = mergedicts(self.collected_config, settings)