How to use the dallinger.config.get_config function in dallinger

To help you get started, we’ve selected a few dallinger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dallinger / Dallinger / tests / test_heroku.py View on Github external
def setup(self):
        """Set up the environment by moving to the demos directory."""
        os.chdir("tests/experiment")
        config = get_config()
        config.ready = False
        from dallinger.heroku import clock

        self.clock = clock
github Dallinger / Dallinger / tests / test_config.py View on Github external
def test_remote_base_url(self):
        from dallinger.utils import get_base_url

        config = get_config()
        config.ready = True
        config.set("host", "https://dlgr-bogus.herokuapp.com")
        config.set("num_dynos_web", 1)
        assert get_base_url() == "https://dlgr-bogus.herokuapp.com"
github Dallinger / Dallinger / dallinger / data.py View on Github external
def _s3_resource(dallinger_region=False):
    """A boto3 S3 resource using the AWS keys in the config."""
    config = get_config()
    if not config.ready:
        config.load()

    region = "us-east-1" if dallinger_region else config.get("aws_region")
    return boto3.resource(
        "s3",
        region_name=region,
        aws_access_key_id=config.get("aws_access_key_id"),
        aws_secret_access_key=config.get("aws_secret_access_key"),
    )
github Dallinger / Dallinger / dallinger / heroku / clock.py View on Github external
def launch():
    config = dallinger.config.get_config()
    if not config.ready:
        config.load()
    scheduler.start()
github Dallinger / Dallinger / dallinger / command_line.py View on Github external
def awaken(app, databaseurl):
    """Restore the database from a given url."""
    id = app
    config = get_config()
    config.load()

    subprocess.check_call([
        "heroku",
        "addons:create",
        "heroku-postgresql:{}".format(config.get('database_size')),
        "--app", app_name(id),
    ])

    subprocess.check_call(["heroku", "pg:wait", "--app", app_name(id)])

    bucket = data.user_s3_bucket()
    key = bucket.lookup('{}.dump'.format(id))
    url = key.generate_url(expires_in=300)

    subprocess.check_call([
github Dallinger / Dallinger / dallinger / experiment_server / gunicorn.py View on Github external
def launch():
    config = get_config()
    config.load()
    LOG_LEVELS = [
        logging.DEBUG,
        logging.INFO,
        logging.WARNING,
        logging.ERROR,
        logging.CRITICAL,
    ]
    LOG_LEVEL = LOG_LEVELS[config.get("loglevel")]
    logging.basicConfig(format="%(asctime)s %(message)s", level=LOG_LEVEL)

    # Avoid duplicate logging to stderr
    error_logger = logging.getLogger("gunicorn.error")
    error_logger.propagate = False
    access_logger = logging.getLogger("gunicorn.access")
    access_logger.propagate = False
github Dallinger / Dallinger / demos / dlgr / demos / bartlett1932 / experiment.py View on Github external
def extra_parameters():
    config = get_config()
    config.register("num_participants", int)
github Dallinger / Dallinger / dallinger / command_line.py View on Github external
def deploy(verbose, app):
    """Deploy app using Heroku to MTurk."""
    if app:
        verify_id(None, None, app)

    # Load configuration.
    config = get_config()
    config.load()

    # Set the mode.
    config.extend({
        "mode": u"live",
        "logfile": u"-",
    })

    # Do shared setup.
    deploy_sandbox_shared_setup(verbose=verbose, app=app)
github Dallinger / Dallinger / dallinger / command_line.py View on Github external
def setup_experiment(debug=True, verbose=False, app=None, exp_config=None):
    """Check the app and, if compatible with Dallinger, freeze its state."""
    log(header, chevrons=False)

    # Verify that the Postgres server is running.
    try:
        psycopg2.connect(database="x", user="postgres", password="nada")
    except psycopg2.OperationalError as e:
        if "could not connect to server" in str(e):
            raise RuntimeError("The Postgres server isn't running.")

    # Load configuration.
    config = get_config()
    if not config.ready:
        config.load()

    # Check that the demo-specific requirements are satisfied.
    try:
        with open("requirements.txt", "r") as f:
            dependencies = [r for r in f.readlines() if r[:3] != "-e "]
    except:
        dependencies = []

    pkg_resources.require(dependencies)

    # Generate a unique id for this experiment.
    from dallinger.experiment import Experiment
    generated_uid = public_id = Experiment.make_uuid()
github Dallinger / Dallinger / dallinger / experiment_server / experiment_server.py View on Github external
def _config():
    config = get_config()
    if not config.ready:
        config.load()

    return config