def db_user_exists(username):
    """Return True if the DB user already exists.
    """
    qry = u"""SELECT COUNT(*) FROM pg_roles where rolname = \'{username}\';"""
    output = StringIO()
    excute_query(
        qry.format(username=username),
        flags="-Aqt",
        use_sudo=True,
        stdout=output
    )
    # FIXME: is there a way to get fabric to not clutter the output
    # with "[127.0.0.1] out:" on each line?
    lines = output.getvalue().splitlines()
    return lines and lines[0].endswith('out: 1')
def db_user_exists ( username ) : qry = u"""SELECT COUNT(*) FROM pg_roles where rolname = \'{username}\';""" output = StringIO ( ) excute_query ( qry . format ( username = username ) , flags = "-Aqt" , use_sudo = True , stdout = output ) lines = output . getvalue ( ) . splitlines ( ) return lines and lines [ 0 ] . endswith ( 'out: 1' )
Return True if the DB user already exists.