question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fabtools.postgres.user_exists() quick fix

See original GitHub issue

For some reasons (gremlins ?) the test (res == "1") does not work even if the psql command returns "1" I found it worked better using ("1" in res), without any str.strip(), etc…

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
matrixisecommented, Sep 25, 2012

I use the root user to connect via SSH.

fab check_user
Executing task 'check_user'
res: 'could not change directory to "/root"\r\n1'
True

Done.

the check_user task is a call to pg_user_exists(username), it’s my modified function of postgres.user_exists(username)

def pg_user_exists(name):
    with settings(hide('running', 'stdout', 'stderr', 'warnings'),
        warn_only=True):
        res = _run_as_pg('''psql -t -A -c "SELECT count(*) FROM pg_user WHERE usename='%(name)s';"''' % locals())

    print "res: %r" % (res,)
    return '1' in res

def check_user():
    print pg_user_exists(DATABASE_OWNER)
0reactions
agammcommented, Jan 20, 2018

Any elegant solution yet?

Read more comments on GitHub >

github_iconTop Results From Across the Web

fabtools Documentation - Read the Docs
fabtools includes useful functions to help you write your Fabric files. fabtools makes it easier to ... Check if a PostgreSQL user exists....
Read more >
fabtools.postgres — fabtools 0.13.0 documentation
Source code for fabtools.postgres. """ PostgreSQL users and databases ... [docs]def user_exists(name): """ Check if a PostgreSQL user exists.
Read more >
Quick fix for PostgreSQL error 42501 - Bobcares
The PostgreSQL error 42501 occurs mainly due to insufficient privileges for database user for running query, wrong server settings, etc.
Read more >
code-docstring-corpus/data_ps.descriptions.valid at master
'Return a fixed frequency datetime index, with day (calendar) as the default ... DCNL import fabtools DCNL fabtools.python_setuptools.install_setuptools()'.
Read more >
Rayn——做今天最好的自己- OSCHINA - 中文开源技术交流社区
官网 pgcli:Postgres 命令行工具,具有自动补全和语法高亮功能。 ... 在大家的潜意识里, Entity 经过 save() 和finish() 后,数据才会保存到数据库中。
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found