# Path: nuka/utils.py
# CHANGED = logging.WARNING + 1
# 
# Path: nuka/gpg.py
# class FileSystemLoader(jinja2.FileSystemLoader):
# 
#     def get_source(self, environment, template):
#         pieces = split_template_path(template)
#         for searchpath in self.searchpath:
#             filename = os.path.join(searchpath, *pieces)
#             f = open_if_exists(filename)
#             if f is None:
#                 continue
#             if filename.endswith('.gpg'):
#                 f.close()
#                 _, contents = decrypt(filename, self.encoding)
#             else:
#                 try:
#                     contents = f.read().decode(self.encoding)
#                 finally:
#                     f.close()
# 
#             mtime = os.path.getmtime(filename)
# 
#             def uptodate():
#                 try:
#                     return os.path.getmtime(filename) == mtime
#                 except OSError:
#                     return False
#             return contents, filename, uptodate
#         raise TemplateNotFound(template)


import tempfile
import logging
import os
import jinja2
import yaml
from nuka.utils import CHANGED
from nuka.gpg import FileSystemLoader



asyncio_logger = logging.getLogger('asyncio')


class Config(dict):

    def update_from_file(self, yaml_config):  # pragma: no cover
        for doc in yaml.load_all(yaml_config):
            for k, v in doc.items():
                if isinstance(v, dict):
                    self.setdefault(k, v)
                    self[k].update(v)
                else:
                    self[k] = v

    def finalize(self, args):
        if args.nuka_dir:
            self['nuka_dir'] = args.nuka_dir
        nuka_dir = self['nuka_dir']
        tempdir = args.tempdir or tempfile.mkdtemp(prefix='nuka')
        self['tmp'] = tempdir
        for dirname in (nuka_dir, tempdir):
            if not os.path.isdir(dirname):  # pragma: no cover
                os.makedirs(dirname)

        for name in ('log', 'reports', 'ssh'):
            for key, value in self[name].items():
                if isinstance(value, str):

# Path: nuka/utils.py
# CHANGED = logging.WARNING + 1
# 
# Path: nuka/gpg.py
# class FileSystemLoader(jinja2.FileSystemLoader):
# 
#     def get_source(self, environment, template):
#         pieces = split_template_path(template)
#         for searchpath in self.searchpath:
#             filename = os.path.join(searchpath, *pieces)
#             f = open_if_exists(filename)
#             if f is None:
#                 continue
#             if filename.endswith('.gpg'):
#                 f.close()
#                 _, contents = decrypt(filename, self.encoding)
#             else:
#                 try:
#                     contents = f.read().decode(self.encoding)
#                 finally:
#                     f.close()
# 
#             mtime = os.path.getmtime(filename)
# 
#             def uptodate():
#                 try:
#                     return os.path.getmtime(filename) == mtime
#                 except OSError:
#                     return False
#             return contents, filename, uptodate
#         raise TemplateNotFound(template)


# Path: nuka/configuration.py
import tempfile
import logging
import os
import jinja2
import yaml
from nuka.utils import CHANGED
from nuka.gpg import FileSystemLoader




asyncio_logger = logging.getLogger('asyncio')


class Config(dict):

    def update_from_file(self, yaml_config):  # pragma: no cover
        for doc in yaml.load_all(yaml_config):
            for k, v in doc.items():
                if isinstance(v, dict):
                    self.setdefault(k, v)
                    self[k].update(v)
                else:
                    self[k] = v

    def finalize(self, args):
        if args.nuka_dir:
            self['nuka_dir'] = args.nuka_dir
        nuka_dir = self['nuka_dir']
        tempdir = args.tempdir or tempfile.mkdtemp(prefix='nuka')
        self['tmp'] = tempdir
        for dirname in (nuka_dir, tempdir):
            if not os.path.isdir(dirname):  # pragma: no cover
                os.makedirs(dirname)

        for name in ('log', 'reports', 'ssh'):
            for key, value in self[name].items():
                if isinstance(value, str):

                    value = value.format(nuka_dir=nuka_dir)