Ejemplo n.º 1
0
def repl(url):
    """
    Usage: ./manage.py db repl
    Launch a psql or sqlite3 repl connected to the database
    """
    def build_named_arglist(arg_dict):
        for name, value in arg_dict.iteritems():
            yield "--{}".format(name)
            yield str(value)

    dialect = url.get_dialect()
    if dialect.name == "postgresql":
        env = os.environ.copy()
        env["PGPASSWORD"] = url.password
        proc_args = list(build_named_arglist({
            'host': url.host,
            'port': url.port,
            'username': url.username,
            'dbname': url.database
        }))
        return invoke_process("psql", proc_args, env=env)
    elif dialect.name == "sqlite":
        proc_args = [url.database] if url.database else []
        return invoke_process("sqlite3", proc_args)
    else:
        raise argparse.ArgumentTypeError("Dialect {} is not supported.".format(dialect.name))
Ejemplo n.º 2
0
def repl(url):
    """
    Usage: ./manage.py db repl
    Launch a psql or sqlite3 repl connected to the database
    """
    def build_named_arglist(arg_dict):
        for name, value in arg_dict.iteritems():
            yield "--{}".format(name)
            yield str(value)

    dialect = url.get_dialect()
    if dialect.name == "postgresql":
        env = os.environ.copy()
        env["PGPASSWORD"] = url.password
        proc_args = list(
            build_named_arglist({
                'host': url.host,
                'port': url.port,
                'username': url.username,
                'dbname': url.database
            }))
        return invoke_process("psql", proc_args, env=env)
    elif dialect.name == "sqlite":
        proc_args = [url.database] if url.database else []
        return invoke_process("sqlite3", proc_args)
    else:
        raise argparse.ArgumentTypeError("Dialect {} is not supported.".format(
            dialect.name))