# Path: py_mina/config.py
# def fetch(key, default_value=None):
#     """
#     Gets and ensures config setting or returns `default_value` if provided
#     """
# 
#     if key in config.keys():
#         return config.get(key)
#     else:
#         if default_value != None:
#             return default_value
#         else:
#             raise Exception('"%s" is not defined' % key)
# 
# def ensure(key):
#     """
#     Ensures presence of config setting. Prevents from running unnecessary commands,
#     before discovering, that config setting is not set
#     """
# 
#     if not key in config.keys():
#         raise Exception('"%s" must be defined' % key)
# 
# def check_config(required_settings=[]):
#     """
#     Ensures required settings in cofig
#     """
# 
#     try:
#         for setting in required_settings:
#             ensure(setting)
#     except EnsureConfigError:
#         msg = 'Bad config!\nRequired settings: {0}\nCurrent config: {1}'
# 
#         raise Exception(msg.format(required_settings, config))  


import timeit
import os
import re
from py_mina.config import fetch, ensure, check_config
from fabric.api import run, sudo, settings, env, cd, hide
from py_mina.echo import *


    def create_files(files, protected=False):
        global shared_path

        for sfile in files:
            directory, filename_ = os.path.split(sfile)

            if directory: 
                create_entity(
                    '/'.join([shared_path, directory]), 
                    entity_type='directory', 
                    protected=protected
                )

            filepath = '/'.join([shared_path, sfile])
            create_entity(filepath, entity_type='file', protected=protected)

            recommendation_tuple = (env.host_string, filepath)
            echo_status('\n=====> Don\'t forget to update shared file:\n[%s] %s\n' % recommendation_tuple, error=True)


    echo_subtask('Creating shared paths')

    # Shared
    create_dirs(fetch('shared_dirs', default_value=[]), protected=False)
    create_files(fetch('shared_files', default_value=[]), protected=False)

    # Protected
    create_dirs(fetch('protected_shared_dirs', default_value=[]), protected=True)

# Path: py_mina/config.py
# def fetch(key, default_value=None):
#     """
#     Gets and ensures config setting or returns `default_value` if provided
#     """
# 
#     if key in config.keys():
#         return config.get(key)
#     else:
#         if default_value != None:
#             return default_value
#         else:
#             raise Exception('"%s" is not defined' % key)
# 
# def ensure(key):
#     """
#     Ensures presence of config setting. Prevents from running unnecessary commands,
#     before discovering, that config setting is not set
#     """
# 
#     if not key in config.keys():
#         raise Exception('"%s" must be defined' % key)
# 
# def check_config(required_settings=[]):
#     """
#     Ensures required settings in cofig
#     """
# 
#     try:
#         for setting in required_settings:
#             ensure(setting)
#     except EnsureConfigError:
#         msg = 'Bad config!\nRequired settings: {0}\nCurrent config: {1}'
# 
#         raise Exception(msg.format(required_settings, config))  


# Path: py_mina/subtasks/setup.py
import timeit
import os
import re
from py_mina.config import fetch, ensure, check_config
from fabric.api import run, sudo, settings, env, cd, hide
from py_mina.echo import *



    def create_files(files, protected=False):
        global shared_path

        for sfile in files:
            directory, filename_ = os.path.split(sfile)

            if directory: 
                create_entity(
                    '/'.join([shared_path, directory]), 
                    entity_type='directory', 
                    protected=protected
                )

            filepath = '/'.join([shared_path, sfile])
            create_entity(filepath, entity_type='file', protected=protected)

            recommendation_tuple = (env.host_string, filepath)
            echo_status('\n=====> Don\'t forget to update shared file:\n[%s] %s\n' % recommendation_tuple, error=True)


    echo_subtask('Creating shared paths')

    # Shared
    create_dirs(fetch('shared_dirs', default_value=[]), protected=False)
    create_files(fetch('shared_files', default_value=[]), protected=False)

    # Protected
    create_dirs(fetch('protected_shared_dirs', default_value=[]), protected=True)

    create_files(fetch('protected_shared_files', default_value=[]), protected=True)