def quicksetup( ctx, non_interactive, profile, email, first_name, last_name, institution, db_engine, db_backend, db_host, db_port, db_name, db_username, db_password, su_db_name, su_db_username, su_db_password, repository ): """Setup a new profile in a fully automated fashion.""" # pylint: disable=too-many-arguments,too-many-locals from aiida.manage.external.postgres import Postgres, manual_setup_instructions dbinfo_su = { 'host': db_host, 'port': db_port, 'user': su_db_username, 'password': su_db_password, } postgres = Postgres(interactive=not non_interactive, quiet=False, dbinfo=dbinfo_su) if not postgres.is_connected: echo.echo_critical('failed to determine the PostgreSQL setup') try: create = True if not postgres.dbuser_exists(db_username): postgres.create_dbuser(db_username, db_password) else: db_name, create = postgres.check_db_name(db_name) if create: postgres.create_db(db_username, db_name) except Exception as exception: echo.echo_error( '\n'.join([ 'Oops! quicksetup was unable to create the AiiDA database for you.', 'For AiiDA to work, please either create the database yourself as follows:', manual_setup_instructions(dbuser=su_db_username, dbname=su_db_name), '', 'Alternatively, give your (operating system) user permission to create postgresql databases' + 'and run quicksetup again.', '' ]) ) raise exception # The contextual defaults or `verdi setup` are not being called when `invoking`, so we have to explicitly define # them here, even though the `verdi setup` command would populate those when called from the command line. setup_parameters = { 'non_interactive': non_interactive, 'profile': profile, 'email': email, 'first_name': first_name, 'last_name': last_name, 'institution': institution, 'db_engine': db_engine, 'db_backend': db_backend, 'db_name': db_name, # from now on we connect as the AiiDA DB user, which may be forbidden when going via sockets 'db_host': db_host or 'localhost', 'db_port': db_port, 'db_username': db_username, 'db_password': db_password, 'repository': repository, } ctx.invoke(setup, **setup_parameters)
def quicksetup( ctx, non_interactive, profile, email, first_name, last_name, institution, db_engine, db_backend, db_host, db_port, db_name, db_username, db_password, su_db_name, su_db_username, su_db_password, broker_protocol, broker_username, broker_password, broker_host, broker_port, broker_virtual_host, repository ): """Setup a new profile in a fully automated fashion.""" # pylint: disable=too-many-arguments,too-many-locals from aiida.manage.external.postgres import Postgres, manual_setup_instructions dbinfo_su = { 'host': db_host, 'port': db_port, 'user': su_db_username, 'password': su_db_password, } postgres = Postgres(interactive=not non_interactive, quiet=False, dbinfo=dbinfo_su) if not postgres.is_connected: echo.echo_critical('failed to determine the PostgreSQL setup') try: db_username, db_name = postgres.create_dbuser_db_safe(dbname=db_name, dbuser=db_username, dbpass=db_password) except Exception as exception: echo.echo_error( '\n'.join([ 'Oops! quicksetup was unable to create the AiiDA database for you.', 'See `verdi quicksetup -h` for how to specify non-standard parameters for the postgresql connection.\n' 'Alternatively, create the AiiDA database yourself: ', manual_setup_instructions(dbuser=su_db_username, dbname=su_db_name), '', 'and then use `verdi setup` instead', '' ]) ) raise exception # The contextual defaults or `verdi setup` are not being called when `invoking`, so we have to explicitly define # them here, even though the `verdi setup` command would populate those when called from the command line. setup_parameters = { 'non_interactive': non_interactive, 'profile': profile, 'email': email, 'first_name': first_name, 'last_name': last_name, 'institution': institution, 'db_engine': db_engine, 'db_backend': db_backend, 'db_name': db_name, # from now on we connect as the AiiDA DB user, which may be forbidden when going via sockets 'db_host': postgres.host_for_psycopg2, 'db_port': postgres.port_for_psycopg2, 'db_username': db_username, 'db_password': db_password, 'broker_protocol': broker_protocol, 'broker_username': broker_username, 'broker_password': broker_password, 'broker_host': broker_host, 'broker_port': broker_port, 'broker_virtual_host': broker_virtual_host, 'repository': repository, } ctx.invoke(setup, **setup_parameters)