Exemple #1
0
def define_command_line_options():
    """Define and parse command line options."""
    from motherbrain.base.conf import get_config

    _opts = {
        'module': {
            'default': 'motherbrain.actions.urlist',
            'help': 'Module to wrap'
        },
        'ports': {
            'default':
            '5555,5556',
            'help':
            '''A comma separated list of port. A process'''
            ''' will be spawned for each port'''
        },
        'cluster': {
            'default':
            '',
            'help':
            '''If specified, only actions belonging to '''
            '''the specified cluster where registered'''
        }
    }

    _cli_args = {'global': ['module', 'ports', 'cluster']}

    opts = get_config({'global': _opts}, _cli_args)

    return opts
Exemple #2
0
def _get_config(*args, **kwargs):
    from motherbrain.base import conf
    import tornado.options

    reload(tornado.options)
    reload(conf)

    return conf.get_config(*args, **kwargs)
Exemple #3
0
def _get_config(*args, **kwargs):
    from motherbrain.base import conf
    import tornado.options

    reload(tornado.options)
    reload(conf)

    return conf.get_config(*args, **kwargs)
Exemple #4
0
def get_settings(extra_options=None):
    if not extra_options:
        extra_options = {}

    _extra_items = list(chain(extra_options.iteritems(),
                              workers_opts.iteritems()))

    opts = dict(resources_opts, **dict(_extra_items))

    return get_config(opts)
Exemple #5
0
def get_settings(extra_options=None):
    if not extra_options:
        extra_options = {}

    _extra_items = list(
        chain(extra_options.iteritems(), workers_opts.iteritems()))

    opts = dict(resources_opts, **dict(_extra_items))

    return get_config(opts)
Exemple #6
0
def define_command_line_options():
    """Define and parse command line options."""
    from motherbrain.base.conf import get_config

    _opts = {'config': {'default': 'motherbrain.cfg',
                        'help': 'Workers configuration file [JSON]'}}

    _cli_args = {'global': ['config']}
    opts = get_config({'global': _opts}, _cli_args)

    workers_opts = [x for x in opts.sections() if x.startswith('_worker')]

    if not len(workers_opts):
        _all_opts = _WORKER_OPTS

        return conf.merge_with_dict(_all_opts, opts)

    return opts
Exemple #7
0
def define_command_line_options():
    """Define and parse command line options."""
    from motherbrain.base.conf import get_config

    _opts = {'module': {'default': 'motherbrain.actions.urlist',
                        'help': 'Module to wrap'},
             'ports':  {'default': '5555,5556',
                        'help': '''A comma separated list of port. A process'''
                                ''' will be spawned for each port'''},
             'cluster': {'default': '',
                        'help': '''If specified, only actions belonging to '''
                                '''the specified cluster where registered'''}}

    _cli_args = {'global': ['module', 'ports', 'cluster']}

    opts = get_config({'global': _opts}, _cli_args)

    return opts
Exemple #8
0
def define_command_line_options():
    """Define and parse command line options."""
    from motherbrain.base.conf import get_config

    _opts = {
        'config': {
            'default': 'motherbrain.cfg',
            'help': 'Workers configuration file [JSON]'
        }
    }

    _cli_args = {'global': ['config']}
    opts = get_config({'global': _opts}, _cli_args)

    workers_opts = [x for x in opts.sections() if x.startswith('_worker')]

    if not len(workers_opts):
        _all_opts = _WORKER_OPTS

        return conf.merge_with_dict(_all_opts, opts)

    return opts
Exemple #9
0
            'default': 'mongo1'
        },
        'dbport': {
            'default': 27017,
            'type': int
        },
        'dbusr': {
            'default': ''
        },
        'dbpwd': {
            'default': ''
        },
    }
}

settings = get_config(_opts)
db = base_db.get_db(settings)


def last_visit(list_hash, current_user_id):
    data = db.visit_tracker.find_one({
        'hash': list_hash,
        'user_id': current_user_id
    })

    if not data:
        return None

    return data.get('last_visit_at')

Exemple #10
0
    'twitter_consumer_key': {'default': 'XXX'},
    'twitter_consumer_secret': {'default': 'XXX'},

    'urlist_salt': {'default': 'XXX'}
}

_db_opts = {
    'dbname':  {'default': 'urlist'},
    'dbhost':  {'default': 'mongo1'},
    'dbport':  {'default': 27017, 'type': int},
    'dbusr':   {'default': ''},
    'dbpwd':   {'default': ''},
}

# Get Tornado default options
_tornado_opts = {k: v.value() for k, v in opt.options.iteritems()}

_options = {'server': _srv_opts,
            'database': _db_opts,
            'tornado': _tornado_opts,
            'oauth': _oauth_opts,
            'motherbrain': _motherbrain_opts}

_cli_args = {'server': ['port', 'debug', 'config'],
             'motherbrain': ['datadir']}

config = get_config(_options, _cli_args)

if SITE_CONF:
    logging.info('CONF::SITE --- Read')
Exemple #11
0
from bson.objectid import ObjectId

from itertools import chain


_opts = {
    'database': {
        'dbname':  {'default': 'urlist'},
        'dbhost':  {'default': 'mongo1'},
        'dbport':  {'default': 27017, 'type': int},
        'dbusr':   {'default': ''},
        'dbpwd':   {'default': ''},
    }
}

settings = get_config(_opts)
db = base_db.get_db(settings)


def last_visit(list_hash, current_user_id):
    data = db.visit_tracker.find_one({'hash': list_hash,
                                      'user_id': current_user_id})

    if not data:
        return None

    return data.get('last_visit_at')

def full_url(list_id=None, base_url=None):
    from urlparse import urljoin
Exemple #12
0
import logging

from motherbrain.base.conf import get_config


default_opts = {
    'database': {
        'dbname':  {'default': 'urlist'},
        'dbhost':  {'default': 'mongo1'},
        'dbport':  {'default': 27017, 'type': int},
        'dbusr':   {'default': ''},
        'dbpwd':   {'default': ''},
    }
}

default_settings = get_config(default_opts)


def connect(options=default_settings):
    dbconn_args = {'port': options.getint('database', 'dbport'),
                   'host': options.get('database', 'dbhost')}

    dbconn = pymongo.Connection(**dbconn_args)

    return dbconn


def get_db(options=default_settings):
    dbconn = connect(options)

    db = getattr(dbconn, options.get('database', 'dbname'))
Exemple #13
0
    },
    'dbport': {
        'default': 27017,
        'type': int
    },
    'dbusr': {
        'default': ''
    },
    'dbpwd': {
        'default': ''
    },
}

# Get Tornado default options
_tornado_opts = {k: v.value() for k, v in opt.options.iteritems()}

_options = {
    'server': _srv_opts,
    'database': _db_opts,
    'tornado': _tornado_opts,
    'oauth': _oauth_opts,
    'motherbrain': _motherbrain_opts
}

_cli_args = {'server': ['port', 'debug', 'config'], 'motherbrain': ['datadir']}

config = get_config(_options, _cli_args)

if SITE_CONF:
    logging.info('CONF::SITE --- Read')