<commit_before>"""Helper functions used in views"""
import os
import tempfile
import logging
import yaml

from pyramid.response import Response

from libcloud.compute.types import Provider
from libcloud.compute.types import NodeState
from libcloud.compute.providers import get_driver
from libcloud.compute.base import Node
from libcloud.compute.types import Provider

from fabric.api import env
from fabric.api import run

from mist.io.config import EC2_PROVIDERS


log = logging.getLogger('mist.io')


def load_settings(settings):
    """Get settings from settings.yaml local file.

    The settings argument gets updated. It is the global_config of pyramid. If
    no file is there it sets some sensible defaults.
    """
    try:
        config_file = open('settings.yaml', 'r')
    except IOError:
        log.warn('settings.yaml does not exist.')
        config_file = open('settings.yaml', 'w')
        config_file.close()
        config_file = open('settings.yaml', 'r')

    try:
        user_config = yaml.load(config_file) or {}
        config_file.close()
    except:
        log.error('Error parsing settings.yaml')
        config_file.close()
        raise

    settings['keypairs'] = user_config.get('keypairs', {})
    settings['backends'] = user_config.get('backends', [])
    settings['core_uri'] = user_config.get('core_uri', 'https://mist.io')
    settings['js_build'] = user_config.get('js_build', False)
    settings['js_log_level'] = user_config.get('js_log_level', 3)


def save_settings(settings):
    """
    """
    class literal_unicode(unicode): pass<commit_msg>check if core_uri already set<commit_after>"""Helper functions used in views"""
import os
import tempfile
import logging
import yaml

from pyramid.response import Response

from libcloud.compute.types import Provider
from libcloud.compute.types import NodeState
from libcloud.compute.providers import get_driver
from libcloud.compute.base import Node
from libcloud.compute.types import Provider

from fabric.api import env
from fabric.api import run

from mist.io.config import EC2_PROVIDERS


log = logging.getLogger('mist.io')


def load_settings(settings):
    """Get settings from settings.yaml local file.

    The settings argument gets updated. It is the global_config of pyramid. If
    no file is there it sets some sensible defaults.
    """
    try:
        config_file = open('settings.yaml', 'r')
    except IOError:
        log.warn('settings.yaml does not exist.')
        config_file = open('settings.yaml', 'w')
        config_file.close()
        config_file = open('settings.yaml', 'r')

    try:
        user_config = yaml.load(config_file) or {}
        config_file.close()
    except:
        log.error('Error parsing settings.yaml')
        config_file.close()
        raise

    settings['keypairs'] = user_config.get('keypairs', {})
    settings['backends'] = user_config.get('backends', [])
    settings['js_build'] = user_config.get('js_build', False)
    settings['js_log_level'] = user_config.get('js_log_level', 3)
    if not settings.has_key('core_uri'):
        settings['core_uri'] = user_config.get('core_uri', 'https://mist.io')

def save_settings(settings):
    """
    """
    class literal_unicode(unicode): pass
{'fraction_non_alphanumeric': 0.11358024691358025, 'fraction_numerical': 0.0012345679012345679, 'mean_word_length': 3.656609195402299, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6575808', 'n_tokens_mistral': 972, 'n_tokens_neox': 934, 'n_words': 258}