Beispiel #1
0
def test_lookups_in_extends():
    src = Configuration.from_file(TEST_DIR + '/data/extends/extends.yml')
    print_yaml("Extends using !lookup:", src)
    src.configure()
    from ksgen.yaml_utils import LookupDirective
    LookupDirective.lookup_table = src
    print_yaml("Extends using !lookup:", src)
Beispiel #2
0
def test_lookups_in_extends():
    src = Configuration.from_file(TEST_DIR + '/data/extends/extends.yml')
    print_yaml("Extends using !lookup:", src)
    src.configure()
    from ksgen.yaml_utils import LookupDirective
    LookupDirective.lookup_table = src
    print_yaml("Extends using !lookup:", src)
Beispiel #3
0
def load_configuration(environment, config_name, config_dir):
    """

    :param environment: Environment name
    :type environment: str
    :param config_name: Config file prefix
    :type config_name: str
    :param config_dir: Config directory
    :type config_dir: str
    :return: Configuration
    """
    config_filename = '{}_{}.yaml'.format(config_name, environment)
    config_filename = os.path.join(config_dir, config_filename)

    if not os.path.isfile(config_filename):
        config_filename = '{}.yaml'.format(config_name)
        config_filename = os.path.join(config_dir, config_filename)

    config = Configuration.from_file(config_filename)
    config.configure()

    def to_dict(mapping):
        return {
            k: (to_dict(v) if isinstance(v, Mapping) else v)
            for k, v in mapping.items()
        }

    return to_dict(config)
Beispiel #4
0
    def test_load_from_file(self):
        filename = path.join(path.dirname(__file__), 'examples', 'example.default.conf')
        c = Configuration.from_file(filename)
        c.configure()

        self.assertEqual(c.a, 1)
        self.assertIsInstance(c.b, timedelta)
        self.assertEqual(c.b, timedelta(days=1))
Beispiel #5
0
    def test_load_from_file(self):
        filename = path.join(path.dirname(__file__), 'examples', 'example.default.conf')
        c = Configuration.from_file(filename)
        c.configure()

        self.assertEqual(c.a, 1)
        self.assertIsInstance(c.b, timedelta)
        self.assertEqual(c.b, timedelta(days=1))
Beispiel #6
0
def checkValidRoles(h):
    result = True
    definedRoles = Configuration.from_file('config/roles.yaml').configure()
    for r in h["roles"]:
        if not r in definedRoles:
            print "==> {0} is not a valid role.".format(r)
            result = False
    return result
Beispiel #7
0
def load_variables(file_path, namespace):
    file_path = Template(file_path).render(os.environ)
    variables = dict(
        Configuration.from_file(os.path.abspath(file_path)).configure()
    )
    staticconf.DictConfiguration(
        variables,
        namespace=namespace,
        flatten=False)
def configuration_loader(filename):
    from collections import Mapping
    from configure import Configuration
    config = Configuration.from_file(filename)
    config.configure()

    def to_dict(mapping):
        return {k: (to_dict(v) if isinstance(v, Mapping) else v) for k, v in mapping.items()}

    return to_dict(config)
Beispiel #9
0
def load_yaml(file_path, namespace):
    file_path = Template(file_path).render(os.environ)
    yaml_dict = Configuration.from_file(
            os.path.abspath(file_path),
            configure=False
        )
    staticconf.DictConfiguration(
        yaml_dict,
        namespace=namespace,
        flatten=False)
def validate_configuration(options):
    # must have 3 sections common



if __name__ == '__main__':
    parser = build_argument_parser()
    options = parser.parse_args()
    config = Configuration.from_file(options.config)
    
Beispiel #11
0
def load_configuration(file_path, rel_dir=None):
    """ Return the Configuration for the file_path. Also logs an error if
        there is an error while parsing the file.
        If the optional rel_dir is passed the error message would print
        the file_path relative to rel_dir instead of current directory
    """

    logger.debug('Loading file: %s', file_path)
    try:
        return Configuration.from_file(file_path).configure()
    except ConfigurationError as e:
        rel_dir = rel_dir or os.curdir
        logger.error("Error loading: %s; reason: %s",
                     os.path.relpath(file_path, rel_dir), e)
        raise
    return None
Beispiel #12
0
def load_configuration(file_path, rel_dir=None):
    """ Return the Configuration for the file_path. Also logs an error if
        there is an error while parsing the file.
        If the optional rel_dir is passed the error message would print
        the file_path relative to rel_dir instead of current directory
    """

    logger.debug('Loading file: %s', file_path)
    try:
        return Configuration.from_file(file_path).configure()
    except ConfigurationError as e:
        rel_dir = rel_dir or os.curdir
        logger.error("Error loading: %s; reason: %s",
                     os.path.relpath(file_path, rel_dir), e)
        raise
    return None
Beispiel #13
0
    def _load_defaults(self, path, value):
        param = '-'.join(path[len(self.config_dir + os.sep):].split('/')[::2])
        if not self.parsed['--' + param]:
            logging.warning(
                "\'--%s\' hasn't been provided, using \'%s\' as default" % (
                    param, value))
            self.defaults.append(''.join(['--', param, '=', str(value)]))
        else:
            value = self.parsed['--' + param]

        file_path = path + os.sep + str(value) + '.yml'
        loaded_file = Configuration.from_file(file_path)

        if loaded_file.get(DEFAULTS_TAG):
            path += os.sep + str(value)
            for sub_key, sub_value in loaded_file[DEFAULTS_TAG].iteritems():
                self._load_defaults(path + os.sep + sub_key, sub_value)
Beispiel #14
0
    def _load_defaults(self, path, value):
        param = '-'.join(path[len(self.config_dir + os.sep):].split('/')[::2])
        if not self.parsed['--' + param]:
            logging.warning(
                "\'--%s\' hasn't been provided, using \'%s\' as default" %
                (param, value))
            self.defaults.append(''.join(['--', param, '=', str(value)]))
        else:
            value = self.parsed['--' + param]

        file_path = path + os.sep + str(value) + '.yml'
        loaded_file = Configuration.from_file(file_path)

        if loaded_file.get(DEFAULTS_TAG):
            path += os.sep + str(value)
            for sub_key, sub_value in loaded_file[DEFAULTS_TAG].iteritems():
                self._load_defaults(path + os.sep + sub_key, sub_value)
Beispiel #15
0
def getVars(self):
    """ Used at setup of test """
    config = Configuration.from_file('./config.yml').configure()

    self.testbrowser  = config['browser']
    self.host = config['sharehost']	
    self.port = config['shareport']		
    self.sharehost = config['sharehost']
    self.shareport = config['shareport']
    self.repohost  = config['repohost']
    self.repoport  = config['repoport']
    self.host	     = config['sharehost']	

    if config['https'] is True:
       uri = 'https'
    else:	
       uri = 'http'

    if self.shareport is None:
       self.url = uri + '://' + self.sharehost 
    else:
       self.url = uri + '://' + self.sharehost + ':' + str(self.shareport)

    if self.repoport is None:
   		 self.repourl = uri + '://' + self.repohost
    else:
       self.repourl = uri + '://' + self.repohost + ':' + str(self.repoport)

    self.username  = config['user']
    self.password  = config['passwd']
    self.loginurl  = self.url + config['loginurl']
    self.photopath = config['photopath']
    self.cmisurl   = config['cmisurl']
    self.cmisatom  = self.repourl + config['cmisatom']
    self.ftpurl    = config['sharehost']
    self.ftpport   = config['ftpport']
    self.imap_host = config['imap_host']
    self.imap_port = config['imap_port']

    return self
# from configure import Include
# Function for programatically representing includes to the configure module
# def represent_Include(dumper, include):
#     return dumper.represent_scalar(u'!include:%s' % include.filename, '')
# yaml.add_representer(Include, represent_Include)

# Load the base configuration YAML
# with open(appfile, 'r') as stream:
#     app = yaml.load(stream)

# Auto load realms and sites directories
# for stem in ['realm', 'site']:
#     plural = stem + 's'
#     # basedir = os.path.join(rootdir, plural)
#     app[plural] = app.get(plural, {}) or {}
#     for dir in os.listdir(os.path.join(appdir, plural)):
#         relative = os.path.join(plural, dir, stem + '.yaml')
#         if os.path.isfile(os.path.join(appdir, relative)):
#             app[plural][dir] = Include(relative)

# config = Configuration.from_string(yaml.dump(app), pwd=os.path.abspath(appdir))

config = Configuration.from_file(appfile)

print config



print Just(1) & Nothing
Either
Maybe
Beispiel #17
0
import subprocess
from subprocess import Popen, PIPE, STDOUT
import os
import boto.cloudformation
import boto.s3.connection
import gzip
import logging
import datetime
import sys
from configure import Configuration


folderlocation = os.path.dirname(os.path.realpath(__file__))

#Load Connection Configuration File
ConnectionConfig = Configuration.from_file(os.path.join(folderlocation, 'ConnectionConfig.yaml')).configure()

# Load SQL Server Queries File
queries = Configuration.from_file(os.path.join(folderlocation, 'SQLServerQueries.yaml')).configure()

#Load Redshift Configuration File
RedshiftConfig = Configuration.from_file(os.path.join(folderlocation, 'RedShiftTablesConfig.yaml')).configure()

#Set the date for logging
processdate = datetime.datetime.today().strftime('%Y%m%d')


#Set the package variables

#Packagename
packagename = sys.argv[1]
Beispiel #18
0
# See the configure documentation for more about
# this library.
# http://configure.readthedocs.io/en/latest/#
from configure import Configuration
from application.config import config
from application.models import getModelFromName
from application.absolutepath import getAbsolutePath
from functools import wraps
from flask import request, redirect, url_for
import os, re

roleConfigFilePath = getAbsolutePath('config/roles.yaml')
roleConfig = Configuration.from_file(roleConfigFilePath).configure()


def getUsernameFromEnv():
    # FIXME: This is wrong.
    return os.getenv("USER")


def getRoles(username):
    roles = []
    for role in roleConfig:
        # print "Checking role '{0}'".format(role)
        if userHasRole(username, role):
            roles.append(role)
    return roles


def doesUserHaveRole(role):
    username = getUsernameFromEnv()
Beispiel #19
0
def load_dict_from_yaml(file_path) -> dict:
    file_path = Template(file_path).render(os.environ)
    return Configuration.from_file(os.path.abspath(file_path),
                                   multi_constructors={'!include': include},
                                   configure=False)
Beispiel #20
0
# See the configure documentation for more about
# this library.
# http://configure.readthedocs.io/en/latest/#
from configure import Configuration
from absolutepath import getAbsolutePath

# The configure library provides a pretty interface to our
# configuration data. This module doesn't do anything other
# than
config_path = getAbsolutePath('config/config.yaml')
config = Configuration.from_file(config_path).configure()

# Added for splitting up Add New Chemical form config from config
chemConfig_path = getAbsolutePath('config/chemicalConfig.yaml')
chemConfig = Configuration.from_file(chemConfig_path).configure()

# Added for add container page
contConfig_path = getAbsolutePath('config/containerConfig.yaml')
contConfig = Configuration.from_file(contConfig_path).configure()

# Added for check in page
checkInConfig_path = getAbsolutePath('config/checkInConfig.yaml')
checkInConfig = Configuration.from_file(checkInConfig_path).configure()

# Added for check out page
checkOutConfig_path = getAbsolutePath('config/OutConfig.yaml')
checkOutConfig = Configuration.from_file(checkOutConfig_path).configure()

#Added for UserAcess page
userConfig_path = getAbsolutePath('config/useraccessConfig.yaml')
userConfig = Configuration.from_file(userConfig_path).configure()
Beispiel #21
0
 def _load_file(self, f):
     logging.debug('Loading file: %s', f)
     cfg = Configuration.from_file(f).configure()
     self._all_settings.update(cfg)
Beispiel #22
0
 def _load_file(self, f):
     logging.debug('Loading file: %s', f)
     cfg = Configuration.from_file(f).configure()
     self._all_settings.update(cfg)
Beispiel #23
0
                touchView(viewFile)
                insertViewName(viewFile, h)

    # Create the top-level import
    impPath = "application/controllers/__init__.py"
    if os.path.exists(impPath):
        os.remove(impPath)
    imp = open(impPath, 'w')
    for d in directories:
        imp.write("from application.controllers.{0} import *\n".format(
            d["name"]))
    imp.close()


if __name__ == "__main__":
    if args.config is None:
        cc = Configuration.from_file('config/controllers.yaml').configure()
    else:
        cc = Configuration.from_file(args.config).configure()

    syntaxOK = checkSyntax(cc)

    if syntaxOK:
        print "Syntax checks."

    if syntaxOK and args.generate:
        print
        print "Generating files."
        print "-----------------"
        generateFiles(cc)
Beispiel #24
0
# -*- coding: utf-8 -*-
import os
import warnings
from configure import Configuration


try:
    environment = os.environ['APPLICATION_ENV']
except:
    warnings.warn('catch error when get os environment APPLICATION_EVN, '
                  'use default prod instead')
    environment = 'prod'

path = os.path.dirname(__file__)
config_file = '{0}/config/config_{1}.yml'.format(path, environment)
settings = Configuration.from_file(config_file).configure()
Beispiel #25
0
# See the configure documentation for more about
# this library.
# http://configure.readthedocs.io/en/latest/#
from configure import Configuration

# The configure library provides a pretty interface to our
# configuration data. This module doesn't do anything other
# than
config = Configuration.from_file('config/config.yaml').configure()
secret = Configuration.from_file('config/secret.yaml').configure()

# Load the controllers (if needed)
# controllers = Configuration.from_file('controllers.yaml').configure()
# config.controllers = controllers

# This adds the application's base directory to the
# configuration object, so that the rest of the application
# can reference it.
import os
config.sys.base_dir = os.path.abspath(os.path.dirname(__file__))
Beispiel #26
0
def load_yaml_config(filename):
    filename = os.path.abspath(filename)
    config = Configuration.from_file(filename).configure()
    return config
Beispiel #27
0
'''Get configuration from a file config.ini'''
import os
import base64
import json

from configure import Configuration


config_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.pardir, 'config.yml'))
config = Configuration.from_file(config_file).configure()

class Env(object):
  def __init__(self, adict):
    self.__dict__.update(adict)

def get_environment(section):
    return getattr(config, section)

def get_task_config(task_name):
    for task in config.tasks:
        if task['name'] == task_name:
            return Env(task['config'])
    raise Exception('NO CONFIG FOUND')

def get_io_config(io_name):
    for io_device in config.io:
        if io_device['name'] == io_name:
            return Env(io_device['config'])
    raise Exception('NO CONFIG FOUND')

def decode_var(var, jsonize=False):