# Path: config_loader.py
# def chain_load_setting(config_file_option, envvar, default):
#     # Settings file order (last wins)
#     # 1. Default
#     # 2. Settings file
#     # 3. Env var
# 
#     # 1
#     value = default
# 
#     # 2
#     _conf_value = get_option_config_file(config_file_option)
#     if _conf_value is not None:  # valid _conf_value could be Falsey
#         value = _conf_value
# 
#     # 3
#     value = os.getenv(envvar, value)
# 
#     return value


import os
import random
import redis
import string
import tempfile
from easyos import easyos
from config_loader import chain_load_setting
    from version import version
from config_plugins import *


class SETUP:
    version = version


########################################################
# Magic vars

# Be sure not to shadow any of the built-in config values listed here:
# http://flask.pocoo.org/docs/latest/config/#builtin-configuration-values

def return_or_make_secret_key(secret_key_file):
    # If we don't have a secret access key for signing sessions,
    # generate one and put it on disk.

    try:
        with open(secret_key_file, "r") as f:
            return f.read()
    except IOError:

        print("Creating secret_key file")

        l = random.randint(25, 50)
        _rand = "".join(random.choice(string.printable) for i in range(l))
        with open(secret_key_file, "w+") as f:
            f.write(_rand)
            return f.read()

# when it comes time to separate the API completely from the APP, assign a different secret_key to the api and to the app.

# Path: config_loader.py
# def chain_load_setting(config_file_option, envvar, default):
#     # Settings file order (last wins)
#     # 1. Default
#     # 2. Settings file
#     # 3. Env var
# 
#     # 1
#     value = default
# 
#     # 2
#     _conf_value = get_option_config_file(config_file_option)
#     if _conf_value is not None:  # valid _conf_value could be Falsey
#         value = _conf_value
# 
#     # 3
#     value = os.getenv(envvar, value)
# 
#     return value


# Path: config.py
import os
import random
import redis
import string
import tempfile
from easyos import easyos
from config_loader import chain_load_setting
    from version import version
from config_plugins import *



class SETUP:
    version = version


########################################################
# Magic vars

# Be sure not to shadow any of the built-in config values listed here:
# http://flask.pocoo.org/docs/latest/config/#builtin-configuration-values

def return_or_make_secret_key(secret_key_file):
    # If we don't have a secret access key for signing sessions,
    # generate one and put it on disk.

    try:
        with open(secret_key_file, "r") as f:
            return f.read()
    except IOError:

        print("Creating secret_key file")

        l = random.randint(25, 50)
        _rand = "".join(random.choice(string.printable) for i in range(l))
        with open(secret_key_file, "w+") as f:
            f.write(_rand)
            return f.read()

# when it comes time to separate the API completely from the APP, assign a different secret_key to the api and to the app.

SECRET_KEY = return_or_make_secret_key(basedir + "/secret_key")