# Path: app/__metadata__.py
# APP_NAME = 'LXDUI'
# APP_CLI_CMD = 'lxdui'
# VERSION = '2.2'
# GIT_URL = 'https://github.com/AdaptiveScale/lxdui.git'
# LXD_URL = 'http://localhost:8443'
# LICENSE = 'Apache 2.0'
# AUTHOR = 'AdaptiveScale, Inc.'
# AUTHOR_URL = 'http://www.adaptivescale.com'
# AUTHOR_EMAIL = 'info@adaptivescale.com'
# KEYWORDS = 'lxc lxc-containers lxd'
# IMAGE_HUB = 'http://hub.kuti.io'
# AUTO_LOAD_CONFIG = True
# DEFAULT_CONFIG_FORMAT = 'ini'
# 
# Path: app/lib/conf.py
# class MetaConf(object):
#     def __init__(self):
#         conf = ConfigParser()
#         conf.read_string(meta.__default_config__)
#         self.config = conf
#         self.resolveMacros()
#         self.log_file, self.config_file = self.getConfPaths()
# 
#     def resolveMacros(self):
#         for section in self.config.sections():
#             for k in self.config.options(section):
#                 v = self.config.get(section, k)
#                 if '{{app_root}}' in v:
#                     if 'SNAP_USER_COMMON' in Config.envGet2('SNAP_USER_COMMON'):
#                         v = v.replace('{{app_root}}', self.getSnapPath())
#                     else:
#                         v = v.replace('{{app_root}}', self.getConfRoot())
# 
#                     self.config.set(section, k, v)
# 
#     def getConfRoot(self):
# 
#         module_dir = os.path.dirname(__file__)
#         app_dir = os.path.dirname(module_dir)
#         return os.path.dirname(app_dir)
# 
# 
#     def getSnapPath(self):
#         if not os.path.exists(str(Path.home()) + '/conf'):
#             os.makedirs(str(Path.home()) + '/conf')
#             os.makedirs(str(Path.home()) + '/logs')
#             Path(str(Path.home()) + '/logs/lxdui.log').touch()
#             copy(self.getConfRoot() + '/conf/auth.conf', str(Path.home()) + '/conf')
#             copy(self.getConfRoot() + '/conf/log.conf', str(Path.home()) + '/conf')
# 
#         return str(Path.home())
# 
# 
#     def getConfPaths(self):
#         f = io.StringIO()
#         self.config.write(f)
#         c = ConfigParser(interpolation=ExtendedInterpolation())
#         f.seek(0)
#         c.read_file(f)
#         log_file = c.get(APP, '{}.log.file'.format(APP.lower()))
#         config_file = c.get(APP, '{}.conf.file'.format(APP.lower()))
#         return log_file, config_file
# 
# Path: app/lib/conf.py
# APP = meta.APP_NAME
# class MetaConf(object):
# class Config(object):
#     def __init__(self):
#     def resolveMacros(self):
#     def getConfRoot(self):
#     def getSnapPath(self):
#     def getConfPaths(self):
#     def __init__(self, **kwargs):
#     def load(self, conf_type, *file_path):
#     def get(self, section, key):
#     def set(self, section, key, value):
#     def show(self):
#     def save(self):
#     def envGet():
#     def envGet2(key):
#     def envSet(self, **kwargs):
#     def envShow(self):
#     def getConfig(self, file):
#     def parseConfig(file):


from app import __metadata__ as m
from app.lib.conf import MetaConf
from app.lib import conf
import os
import logging.handlers
import json
import logging
import logging.config

class Log:
    def __init__(self, __name__):
        conf.Config()
        self.configFile = conf.Config().get(m.APP_NAME, '{}.log.conf'.format(m.APP_NAME.lower()))
        self.configure(__name__)

    def configure(self, __name__):
        logging.basicConfig()
        with open(self.configFile, "r") as fd:
            logConf = json.load(fd)

# Path: app/__metadata__.py
# APP_NAME = 'LXDUI'
# APP_CLI_CMD = 'lxdui'
# VERSION = '2.2'
# GIT_URL = 'https://github.com/AdaptiveScale/lxdui.git'
# LXD_URL = 'http://localhost:8443'
# LICENSE = 'Apache 2.0'
# AUTHOR = 'AdaptiveScale, Inc.'
# AUTHOR_URL = 'http://www.adaptivescale.com'
# AUTHOR_EMAIL = 'info@adaptivescale.com'
# KEYWORDS = 'lxc lxc-containers lxd'
# IMAGE_HUB = 'http://hub.kuti.io'
# AUTO_LOAD_CONFIG = True
# DEFAULT_CONFIG_FORMAT = 'ini'
# 
# Path: app/lib/conf.py
# class MetaConf(object):
#     def __init__(self):
#         conf = ConfigParser()
#         conf.read_string(meta.__default_config__)
#         self.config = conf
#         self.resolveMacros()
#         self.log_file, self.config_file = self.getConfPaths()
# 
#     def resolveMacros(self):
#         for section in self.config.sections():
#             for k in self.config.options(section):
#                 v = self.config.get(section, k)
#                 if '{{app_root}}' in v:
#                     if 'SNAP_USER_COMMON' in Config.envGet2('SNAP_USER_COMMON'):
#                         v = v.replace('{{app_root}}', self.getSnapPath())
#                     else:
#                         v = v.replace('{{app_root}}', self.getConfRoot())
# 
#                     self.config.set(section, k, v)
# 
#     def getConfRoot(self):
# 
#         module_dir = os.path.dirname(__file__)
#         app_dir = os.path.dirname(module_dir)
#         return os.path.dirname(app_dir)
# 
# 
#     def getSnapPath(self):
#         if not os.path.exists(str(Path.home()) + '/conf'):
#             os.makedirs(str(Path.home()) + '/conf')
#             os.makedirs(str(Path.home()) + '/logs')
#             Path(str(Path.home()) + '/logs/lxdui.log').touch()
#             copy(self.getConfRoot() + '/conf/auth.conf', str(Path.home()) + '/conf')
#             copy(self.getConfRoot() + '/conf/log.conf', str(Path.home()) + '/conf')
# 
#         return str(Path.home())
# 
# 
#     def getConfPaths(self):
#         f = io.StringIO()
#         self.config.write(f)
#         c = ConfigParser(interpolation=ExtendedInterpolation())
#         f.seek(0)
#         c.read_file(f)
#         log_file = c.get(APP, '{}.log.file'.format(APP.lower()))
#         config_file = c.get(APP, '{}.conf.file'.format(APP.lower()))
#         return log_file, config_file
# 
# Path: app/lib/conf.py
# APP = meta.APP_NAME
# class MetaConf(object):
# class Config(object):
#     def __init__(self):
#     def resolveMacros(self):
#     def getConfRoot(self):
#     def getSnapPath(self):
#     def getConfPaths(self):
#     def __init__(self, **kwargs):
#     def load(self, conf_type, *file_path):
#     def get(self, section, key):
#     def set(self, section, key, value):
#     def show(self):
#     def save(self):
#     def envGet():
#     def envGet2(key):
#     def envSet(self, **kwargs):
#     def envShow(self):
#     def getConfig(self, file):
#     def parseConfig(file):


# Path: app/lib/log.py
from app import __metadata__ as m
from app.lib.conf import MetaConf
from app.lib import conf
import os
import logging.handlers
import json
import logging
import logging.config


class Log:
    def __init__(self, __name__):
        conf.Config()
        self.configFile = conf.Config().get(m.APP_NAME, '{}.log.conf'.format(m.APP_NAME.lower()))
        self.configure(__name__)

    def configure(self, __name__):
        logging.basicConfig()
        with open(self.configFile, "r") as fd:
            logConf = json.load(fd)

            logConf['handlers']['rollingFileAppender']['filename'] = conf.Config().get(m.APP_NAME, '{}.log.file'.format(m.APP_NAME.lower()))