Example #1
0
    def __init__(self, settings=None):
        
        self.settings = settings
        
        log_cfg = Config('')

        log_cfg.from_pyfile( settings['LOGGING_CONFIG'])        
        
        self.log = logging_factory.get_logger(settings['APP_NAME'], settings['LOGGING_PATH'], log_cfg['LOGGING'])
        
        self.dbattr_dict = {'ORA':'ora_db','PG':'pg_db', 'DB':'db'}
        
        self.name_dict = {'ORA':'oracle','PG':'postgresql', 'DB':'oracle'}
        
        #import dbsession after logger initialized
        from mabolab.database import dbfactory
        
        for db_type in settings['DB_TYPE']:       

            if not hasattr(self, self.dbattr_dict[db_type]):
                #self.log.debug("set %s" %(db_type) )
                setattr(self, self.dbattr_dict[db_type], dbfactory.get_db(self.name_dict[db_type], settings) )
        
        if not hasattr(self, 'db'):
            setattr(self, 'db', dbfactory.get_db(self.name_dict['DB'], settings) )
Example #2
0
def cli(ctx):
    '''
    Access and modify data from a PISS server on the command line.
    '''
    current_dir = os.path.dirname(os.path.realpath(__file__))
    config_file = os.path.splitext(os.path.basename(__file__))[0] + ".cfg"

    ctx.obj = {}
    ctx.obj['current_dir'] = current_dir
    ctx.obj['config_file'] = config_file

    if ctx.args[0] != 'register':
        if not os.path.isfile(os.path.join(current_dir, config_file)):
            click.echo('No configuration file found! Use `register <url>`  to\
 create one!')
            ctx.abort()

        try:
            app_config = Config(current_dir)
            app_config.from_pyfile(config_file)
        except Exception as e:
            click.echo('Could not load config from file. Use `register <url>`\
 to create a new one!')
            ctx.abort()

        try:
            ctx.obj['credentials'] = app_config['CREDENTIALS']
            ctx.obj['meta_url'] = app_config['META_URL']
            meta_post = app_config['META_POST']
            ctx.obj['meta_post'] = meta_post
            ctx.obj['url'] = meta_post['server']['urls']['posts_feed']
        except Exception as e:
            click.echo('Parameters missing from configuration file! Use\
 `register <url>` to fix!')
            ctx.abort()
Example #3
0
    def setUp(self):
    
        tmp = '../config/logging_config.py'
        
        
        log_cfg = Config('')

        log_cfg.from_pyfile(tmp)    
       
        self.logging_cfg = log_cfg['LOGGING']        
Example #4
0
def load(config_filename='settings.py'):
    """Create a Flask config that will be used to update the application
    config when it is created."""
    config = Config("pjuu")

    # Load the default settings
    config.from_pyfile(config_filename)

    # Load the setting from the Environment variable
    config.from_envvar('PJUU_SETTINGS', silent=True)

    return config
Example #5
0
    def configs(self):
        if not hasattr(self, '_configs'):
            configs = Config(ROOT)
            resoure = ResourceLoader.get().get_resoure('settings.py')
            config_files = resoure.as_list()
            if config_files:
                for path in config_files:
                    configs.from_pyfile(path)
            else:
                raise Exception('need a configuration file to start app')

            self._configs = configs
        return self._configs
def download_users():
    """
    Download users.xml file.
    """
    import urllib2
    from flask.config import Config
    config = Config(etc())
    config.from_pyfile("deploy.cfg")
    response = urllib2.urlopen(config['USERS_URL'])
    users_xml = os.path.join('runtime', 'data', 'users.xml')
    if response.code == 200:
        with open(users_xml, 'w') as f:
            f.write(response.read())
Example #7
0
def read_config() -> Config:
    config = Config("")
    env_settings_file = os.environ.get('DEBUGPROXY_SETTING_FILE',
                                       './config/default_settings.py')
    config.from_pyfile(env_settings_file)

    # update the config with any values found in the environment
    for key in config.keys():
        env_value = os.environ.get(key)
        if env_value:
            config[key] = env_value

    return config
Example #8
0
    def configs(self):
        if not hasattr(self, '_configs'):
            configs = Config(ROOT)
            resoure = ResourceLoader.get().get_resoure('settings.py')
            config_files = resoure.as_list()
            if config_files:
                for path in config_files:
                    configs.from_pyfile(path)
            else:
                raise Exception('need a configuration file to start app')

            self._configs = configs
        return self._configs
def download_users():
    """
    Download users.xml file.
    """
    import urllib2
    from flask.config import Config
    config = Config(etc())
    config.from_pyfile("deploy.cfg")
    response = urllib2.urlopen(config['USERS_URL'])
    users_xml = os.path.join('runtime', 'data', 'users.xml')
    if response.code == 200:
        with open(users_xml, 'w') as f:
            f.write(response.read())
Example #10
0
def make_config(app=None):
    if app is not None:
        cfg = app.config
    else:
        from flask.config import Config
        root_path = os.path.dirname(__file__).rsplit('/', 1)[0]
        cfg = Config(root_path)

    # customize config here
    cfg.from_object(default_config)
    cfg.from_pyfile('myapp.cfg', silent=True)
    cfg.from_envvar('MYAPP_CONFIG', silent=True)
    cfg['BABEL_DEFAULT_LOCALE'] = cfg['LANG']
    return cfg
Example #11
0
 def __init__(self, debug=False):
     self.valid = True
     # loggerを初期化する
     logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s')
     logger = logging.getLogger(self.service_name)
     logger.setLevel(logging.DEBUG)
     self.logger = logger
     # 設定ファイルからAPIkeyとかを読み込む
     current_dir = os.path.dirname(__file__)
     config = Config('../../')
     if os.path.exists(activate_this):
         config.from_pyfile("wsgi_dev.cfg")
     else:
         config.from_pyfile("dev.cfg")
     #self.logger.debug(config)
     self.validate(self.require_config, config['EXTERNAL_CONFIG'])
     self.config = config['EXTERNAL_CONFIG']
     self.debug = config['POST_DEBUG']
Example #12
0
    def test_settings_abs_path(self):
        """Check if the config obj is updated with default_settings when it is 
        passed as a python file absolute path
        """
        abs_path = getcwd() + '/arachne/tests/test_settings.py'
        test_app = self.create_app(settings=abs_path)

        # load config from pyfile
        flask_app = Flask(__name__)
        flask_app.config.from_object('arachne.default_settings')

        config_cls = Config(__name__)
        config_cls.from_pyfile(abs_path)

        # update config with the arachne default settings
        flask_app.config.update(config_cls)

        # test if config dicts are same
        self.assertEquals(test_app.config, flask_app.config)
Example #13
0
    def test_settings_abs_path(self):
        """Check if the config obj is updated with default_settings when it is 
        passed as a python file absolute path
        """
        abs_path = getcwd() + '/arachne/tests/test_settings.py'
        test_app = self.create_app(settings=abs_path)

        # since the object initialized created is always different
        # we ignore CRAWLER_PROCESS setting for test
        if SCRAPY_VERSION >= (1, 0, 0):
            del test_app.config['CRAWLER_PROCESS']

        # load config from pyfile
        flask_app = Flask(__name__)
        flask_app.config.from_object('arachne.default_settings')

        config_cls = Config(__name__)
        config_cls.from_pyfile(abs_path)

        # update config with the arachne default settings
        flask_app.config.update(config_cls)

        # test if config dicts are same
        self.assertEquals(test_app.config, flask_app.config)
Example #14
0
import imagehash
from jinja2 import Environment, PackageLoader
import luigi
from luigi.contrib import redis_store
import networkx as nx
from PIL import Image
from flask.config import Config
import requests
import twarc

import json2csv


config = Config(os.path.dirname(__file__))
config.from_pyfile('dnflow.cfg')

logging.getLogger().setLevel(logging.WARN)
logging.getLogger('').setLevel(logging.WARN)
logging.getLogger('luigi-interface').setLevel(logging.WARN)


def time_hash(digits=6):
    """Generate an arbitrary hash based on the current time for filenames."""
    hash = hashlib.sha1()
    hash.update(str(time.time()).encode())
    t = time.localtime()
    dt = '%s%02d%02d%02d%02d' % (t.tm_year, t.tm_mon, t.tm_mday,
                                 t.tm_hour, t.tm_min)
    return '%s-%s' % (dt, hash.hexdigest()[:digits])
Example #15
0

from datetime import datetime

from sqlalchemy import String, Integer
from sqlalchemy.sql.expression import text , bindparam, outparam

from mabolab.core.base import Base



from flask.config import Config

settings = Config("" )

settings.from_pyfile( 'C:/MTP/mabotech/maboss1.2/maboss/configuration/central_config.py')

settings['APP_NAME'] = "next_seq"

base = Base( settings)


db = base.get_db("oracle") 


def get_next_seq():
    """ call stored procedure """
    
    sql = """BP_SP_GETNEXTCERTNO (:I_FACILITY, :O_CertNo, :O_Message )"""

    #bind parameters and set out parameters

from flask.config import Config

from mabolab.core.global_obj import Global

CENTRAL_CONFIG = 'C:/MTP/mabotech/maboss1.3.0/maboss/conf/maboss_config.py'

settings = Config("")

settings.from_pyfile(CENTRAL_CONFIG)

settings['APP_NAME'] = "monitor_bli"

g = Global(settings)

db = g.get_db('postgresql')

ora = g.get_db('oracle')

log = g.get_logger()



def dbtest(serialno):
    
    sql = """select status, lastupdateon from cob_t_serial_no_workstation 
where serialno = '%s'  and workstation = '42700' 
order by id desc""" % (serialno)

    rtn = ora.execute(sql)
Example #17
0
import os
import sys
import time
import logging

from flask.config import Config

import boto.sqs
from boto.sqs.message import RawMessage
from boto import exception

LOG = logging.getLogger('alerta.sqs')

config = Config('/')
config.from_pyfile('/etc/alertad.conf', silent=True)
config.from_envvar('ALERTA_SVR_CONF_FILE', silent=True)

DEFAULT_AWS_REGION = 'eu-west-1'
DEFAULT_AWS_SQS_QUEUE = 'alerts'

AWS_REGION = os.environ.get('AWS_REGION') or config.get('AWS_REGION', DEFAULT_AWS_REGION)
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID') or config.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY') or config.get('AWS_SECRET_ACCESS_KEY')
AWS_SQS_QUEUE = os.environ.get('AWS_SQS_QUEUE') or config.get('AWS_SQS_QUEUE', DEFAULT_AWS_SQS_QUEUE)


class Worker(object):

    def __init__(self):
Example #18
0

from flask.config import Config


py = 'config.py'

root_path = ""

setting = Config(root_path)

setting.from_pyfile(py)

print setting['LOGGING']

print setting['PG_URL']

print setting['ORA_URL']
Example #19
0
        ),
        ('/magazine/', _('Magazine')),
        ('http://tieba.baidu.com/f?ie=utf-8&kw=%E4%BD%9F%E5%A4%A7%E4%B8%BA',
            _('Fans')),
        ]

FOOTER_MENU = [
        ('/about', _('About David Tong Studio')),
        ('/contact', _('Contact')),
        ('/jobs', _('Join us'))
        ]




import os
from flask.config import Config

APP_ROOT = os.path.abspath(os.path.join(__path__[0], '../'))

config = Config(APP_ROOT)

# load from environment
if 'DAVID_CONFIG_FILE' in os.environ:
    config.from_pyfile(os.environ['DAVID_CONFIG_FILE'])

# load from local config
config.from_pyfile('local_config.py', silent=True)

globals().update(config)
Example #20
0
 def load_default_config_from_pyfile(self, filename):
     config = Config(root_path=self.root_path)
     config.from_pyfile(filename)
     for key, default_value in config.items():
         self.config.setdefault(key, default_value)
Example #21
0
 def load_config(self):
     config = Config(current_app.root_path)
     config.from_pyfile(path.join(path.dirname(current_app.root_path),
                                  'config.py'))
     for option, value in config.items():
         setattr(self, option, value)
Example #22
0
def config_to_dict(root_path, config_file):
    config = FlaskConfig(root_path)
    config.from_pyfile(config_file)
    return dict((k, v) for k, v in config.iteritems())
Example #23
0
import logging.config
#import profile
import time
from time import strftime, localtime

from Cheetah.Template import Template

from mabolab.core.base import Base

from flask.config import Config

from schedule import Schedule

settings = Config("" )

settings.from_pyfile( 'C:/MTP/mabotech/maboss1.3.0/maboss/conf/tools_config.py')

settings['APP_NAME'] = "mabozen"

base = Base( settings)

db_type = 'postgresql'

db = base.get_db(db_type) 


def render(template_file, name_space):
    """
    template file render
    """
    tpt = Template(file=template_file, searchList=[name_space])
Example #24
0
def PISS(instance_path):
    # Create a configuration object and read the configuration file
    app_config = Config(instance_path)
    app_config.from_pyfile('piss.cfg')

    # If `EVE_SETTINGS` exists and points to valid file, use that instead of
    # the default `settings.py`
    alt_settings = app_config.get('EVE_SETTINGS', None)
    if alt_settings and os.path.isfile(alt_settings):
        settings_file = alt_settings
    else:
        settings_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'settings.py')

    # Create the app instance
    app = Eve(settings=settings_file, 
              json_encoder=NewBase60Encoder, 
              validator=NewBase60Validator,
              auth=HawkAuth,
              instance_path=instance_path,
              static_folder=None)

    # Update the app's config object with our settings
    app.config.update(**dict(app_config))

    # Add event hooks
    app.on_insert_posts += before_insert_posts
    app.on_update_posts += before_update_posts
    app.on_fetched_item_posts += after_fetched_item_posts
    app.on_pre_GET_posts += before_GET_posts
    app.on_pre_POST_posts += before_POST_posts
    app.on_post_POST_posts += after_POST_posts

    # Make sure necessary settings exist
    missing_settings = []
    for setting in ('META_POST', 'ROOT_CREDENTIALS', 'SECRET_KEY', 'MENU_ITEMS', 'SERVER_NAME'):
        if not app.config.get(setting, None):
            missing_settings.append(setting)
    if missing_settings:
        raise SystemExit('Missing configuration settings! (%s)' % (','.join(missing_settings),))

    # Check that a `meta.json` file exists in `types` and that you can read from it
    meta_schema = ''
    meta_schema_file = os.path.join(os.path.dirname(instance_path), 'types/meta.json')
    try:
        with open(meta_schema_file, 'r') as f:
            meta_schema = f.read()
    except IOError as e:
        raise SystemExit('Could not find `meta` post schema file at %s!' % (meta_schema_file,))
    if not meta_schema:
        raise SystemExit('No data in `meta` post schema at %s!' % (meta_schema_file,))

    # Validate the data in `META_POST` against the `meta` post schema
    v = Validator(json.loads(meta_schema))
    if not v.validate(app.config['META_POST']):
        raise SystemExit('Invalid `META_POST` configuration! \
            Validator returned the following errors: \n%s' % (str(v.errors),))

    # Make sure necessary directories exist
    if not os.path.isdir(os.path.join(instance_path, 'attachments')):
        os.makedirs(os.path.join(instance_path, 'attachments'))
    if not os.path.isdir(os.path.join(instance_path, 'tmp')):
        os.makedirs(os.path.join(instance_path, 'tmp'))

    # Add some additional services besides the REST API
    app.register_blueprint(attachments)
    app.register_blueprint(server_info)
    app.register_blueprint(syndication)

    # Override some of Eve's default methods in order to handle HTML requests
    eve_override(app)

    # Override Jinja defaults, filters, and template loaders
    jinja_override(app)

    return app