# Path: lcopt/constants.py
# ASSET_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'assets')
# 
# BIOSPHERE_SI = 'biosphere3.pickle'
# 
# FORWAST_SI = 'forwast.pickle'
# 
# ECOINVENT_EXAMPLE = 'ecoinvent_example.lcopt'
# 
# FORWAST_EXAMPLE = 'forwast_example.lcopt'
# 
# DEFAULT_CONFIG = {
#     'ecoinvent':{
#     	'username': None,
#     	'password': None,
#         'version': DEFAULT_ECOINVENT_VERSION,
#         'system_model': DEFAULT_ECOINVENT_SYSTEM_MODEL,
#     },
#     'model_storage': {
#         'location': DEFAULT_SAVE_OPTION,
#         'project': DEFAULT_PROJECT_TYPE,
#         },
#     }
# 
# DEFAULT_SINGLE_PROJECT = "LCOPT_Models"
# 
# DEFAULT_ECOINVENT_VERSION = '3.3'
# 
# DEFAULT_ECOINVENT_SYSTEM_MODEL = 'cutoff'
# 
# DEFAULT_SAVE_OPTION = 'appdir'
# 
# DEFAULT_PROJECT_TYPE = 'unique'


import os
import yaml
import glob
import shutil
import appdirs
from .constants import (ASSET_PATH,
                        BIOSPHERE_SI, 
                        FORWAST_SI, 
                        ECOINVENT_EXAMPLE, 
                        FORWAST_EXAMPLE,
                        DEFAULT_CONFIG,
                        DEFAULT_SINGLE_PROJECT,
                        DEFAULT_ECOINVENT_VERSION,
                        DEFAULT_ECOINVENT_SYSTEM_MODEL,
                        DEFAULT_SAVE_OPTION,
                        DEFAULT_PROJECT_TYPE)
            self.write_default_config()
            config = DEFAULT_CONFIG
        return config

    def refresh(self):
        with open(self.config_file, 'r') as cf:
            self.config = yaml.safe_load(cf)

    def write_default_config(self):
        self.write_config(DEFAULT_CONFIG)

    def write_config(self, config):
         with open(self.config_file, 'w') as cfg:
                yaml.dump(config, cfg, default_flow_style=False)
                self.refresh()


    @property
    def models(self):
        models = glob.glob(os.path.join(self.model_dir, '*.lcopt'))
        return models

    @property
    def search_indices(self):
        search_indices = glob.glob(os.path.join(self.search_index_dir, '*.pickle'))
        return search_indices

    @property
    def project_type(self):
        if 'model_storage' in self.config:

# Path: lcopt/constants.py
# ASSET_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'assets')
# 
# BIOSPHERE_SI = 'biosphere3.pickle'
# 
# FORWAST_SI = 'forwast.pickle'
# 
# ECOINVENT_EXAMPLE = 'ecoinvent_example.lcopt'
# 
# FORWAST_EXAMPLE = 'forwast_example.lcopt'
# 
# DEFAULT_CONFIG = {
#     'ecoinvent':{
#     	'username': None,
#     	'password': None,
#         'version': DEFAULT_ECOINVENT_VERSION,
#         'system_model': DEFAULT_ECOINVENT_SYSTEM_MODEL,
#     },
#     'model_storage': {
#         'location': DEFAULT_SAVE_OPTION,
#         'project': DEFAULT_PROJECT_TYPE,
#         },
#     }
# 
# DEFAULT_SINGLE_PROJECT = "LCOPT_Models"
# 
# DEFAULT_ECOINVENT_VERSION = '3.3'
# 
# DEFAULT_ECOINVENT_SYSTEM_MODEL = 'cutoff'
# 
# DEFAULT_SAVE_OPTION = 'appdir'
# 
# DEFAULT_PROJECT_TYPE = 'unique'


# Path: lcopt/data_store.py
import os
import yaml
import glob
import shutil
import appdirs
from .constants import (ASSET_PATH,
                        BIOSPHERE_SI, 
                        FORWAST_SI, 
                        ECOINVENT_EXAMPLE, 
                        FORWAST_EXAMPLE,
                        DEFAULT_CONFIG,
                        DEFAULT_SINGLE_PROJECT,
                        DEFAULT_ECOINVENT_VERSION,
                        DEFAULT_ECOINVENT_SYSTEM_MODEL,
                        DEFAULT_SAVE_OPTION,
                        DEFAULT_PROJECT_TYPE)

            self.write_default_config()
            config = DEFAULT_CONFIG
        return config

    def refresh(self):
        with open(self.config_file, 'r') as cf:
            self.config = yaml.safe_load(cf)

    def write_default_config(self):
        self.write_config(DEFAULT_CONFIG)

    def write_config(self, config):
         with open(self.config_file, 'w') as cfg:
                yaml.dump(config, cfg, default_flow_style=False)
                self.refresh()


    @property
    def models(self):
        models = glob.glob(os.path.join(self.model_dir, '*.lcopt'))
        return models

    @property
    def search_indices(self):
        search_indices = glob.glob(os.path.join(self.search_index_dir, '*.pickle'))
        return search_indices

    @property
    def project_type(self):
        if 'model_storage' in self.config:

            store_option = self.config['model_storage'].get('project', DEFAULT_PROJECT_TYPE)