aiida.manage.external package#
User facing APIs to control AiiDA from the verdi cli, scripts or plugins
Subpackages#
Submodules#
Provides an API for postgres database maintenance tasks.
This API creates and drops postgres users and databases used by the
verdi quicksetup
commandline tool. It allows convenient access to this
functionality from within python without knowing details about how postgres is
installed by default on various systems. If the postgres setup is not the
default installation, additional information needs to be provided.
- class aiida.manage.external.postgres.Postgres(dbinfo=None, **kwargs)[源代码]#
基类:
PGSU
Adds convenience functions to
pgsu.PGSU
.- Provides convenience functions for
creating/dropping users
creating/dropping databases
etc.
Example:
postgres = Postgres() postgres.create_dbuser('username', 'password') if not postgres.db_exists('dbname'): postgres.create_db('username', 'dbname')
- __module__ = 'aiida.manage.external.postgres'#
- can_user_authenticate(dbuser, dbpass)[源代码]#
Check whether the database user credentials are valid.
Checks whether dbuser has access to the template1 postgres database via psycopg2.
- 参数:
dbuser – the database user
dbpass – the database password
- 返回:
True if the credentials are valid, False otherwise
- create_dbuser_db_safe(dbname, dbuser, dbpass)[源代码]#
Create DB and user + grant privileges.
An existing database user is reused, if it is able to authenticate. If not, a new username is generated on the fly.
An existing database is not reused (unsafe), a new database name is generated on the fly.
- db_exists(dbname)[源代码]#
Check wether a postgres database with dbname exists
- 参数:
dbname (str) – Name of the database to check for
- 返回:
(bool), True if database exists, False otherwise
- property dbinfo#
Alias for Postgres.dsn.
- dbuser_exists(dbuser)[源代码]#
Find out if postgres user with name dbuser exists
- 参数:
dbuser (str) – database user to check for
- 返回:
(bool) True if user exists, False otherwise
- drop_dbuser(dbuser)[源代码]#
Drop a database user in postgres
- 参数:
dbuser (str) – Name of the user to be dropped.
- find_new_db(start_from='aiida')[源代码]#
Find database name that does not yet exist.
Generates names of the form “aiida_1”, “aiida_2”, etc. until it finds a name that does not yet exist.
- 参数:
start_from (str) – start from this name
- 返回:
dbname
- find_new_dbuser(start_from='aiida')[源代码]#
Find database user that does not yet exist.
Generates names of the form “aiida_1”, “aiida_2”, etc. until it finds a name that does not yet exist.
- 参数:
start_from (str) – start from this name
- 返回:
dbuser
- classmethod from_profile(profile: Profile, **kwargs)[源代码]#
Create Postgres instance with dbinfo from AiiDA profile data.
- Note: This only uses host and port from the profile, since the others are not going to be relevant for the
database superuser.
- 参数:
profile – AiiDA profile instance
kwargs – keyword arguments forwarded to PGSU constructor
- 返回:
Postgres instance pre-populated with data from AiiDA profile
- property host_for_psycopg2#
Return correct host for psycopg2 connection (as required by regular AiiDA operation).
- property port_for_psycopg2#
Return port for psycopg2 connection (as required by regular AiiDA operation).