Ejemplo n.º 1
0
def db_auto_detect(django_id, settings_module, local_path):
    def get_deploys(json_str):
        count = 0
        for name, db_settings in json.loads(json_str).items():
            engine = db_settings['ENGINE']
            if 'psycopg2' not in engine:
                # for now only postgresql is supported
                continue

            if db_settings['HOST'] not in ['localhost', '127.0.0.1', '']:
                # only localhost autodetection allowed (everything else doesn't
                # make sense)
                continue
            if db_settings['PORT']:
                # Port settings not yet supported
                continue

            settings = {
                'id': 'auto_dectect_%s_%s' % (django_id, count),
                'database': db_settings['NAME'],
                'user': db_settings['USER'],
                'password': db_settings['PASSWORD']
            }
            yield Package('psycopg2-build-tools'), Deploy(
                'postgresql', settings)
            count += 1

    with warn_only():
        json_str = local('chdir %s; python -c "'
                         'import json; from %s import *;'
                         'print(json.dumps(DATABASES))"' %
                         (local_path, settings_module),
                         capture=True)
        if json_str.failed:
            return ()

    commands = []
    for dependency, deploy_obj in get_deploys(json_str):
        if deploy_obj:
            commands += load_commands(deploy_obj.name, deploy_obj.settings)
            commands.append(dependency)
    return tuple(commands)
Ejemplo n.º 2
0
def db_auto_detect(django_id, settings_module, local_path):
    def get_deploys(json_str):
        count = 0
        for name, db_settings in json.loads(json_str).items():
            engine = db_settings['ENGINE']
            if 'psycopg2' not in engine:
                # for now only postgresql is supported
                continue

            if db_settings['HOST'] not in ['localhost', '127.0.0.1', '']:
                # only localhost autodetection allowed (everything else doesn't
                # make sense)
                continue
            if db_settings['PORT']:
                # Port settings not yet supported
                continue

            settings = {
                'id': 'auto_dectect_%s_%s' % (django_id, count),
                'database': db_settings['NAME'],
                'user': db_settings['USER'],
                'password': db_settings['PASSWORD']
            }
            yield Package('psycopg2-build-tools'), Deploy('postgresql', settings)
            count += 1

    with warn_only():
        json_str = local('chdir %s; python -c "'
                         'import json; from %s import *;'
                         'print(json.dumps(DATABASES))"'
                         % (local_path, settings_module),
                         capture=True)
        if json_str.failed:
            return ()

    commands = []
    for dependency, deploy_obj in get_deploys(json_str):
        if deploy_obj:
            commands += load_commands(deploy_obj.name, deploy_obj.settings)
            commands.append(dependency)
    return tuple(commands)