diff --git a/NEWS.rst b/NEWS.rst index 3eff436c52fb2e9e018e93cb3e430616ef0e61e4_TkVXUy5yc3Q=..d0a9893d5e45d5c05ff63f967924cdb091334810_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,11 @@ History ======= +6.0.0 +----- + +Fix --odoo-help in docker_dev_start to avoid requiring a database. + 5.0.0 ----- diff --git a/odoo_scripts/docker_dev_start.py b/odoo_scripts/docker_dev_start.py index 3eff436c52fb2e9e018e93cb3e430616ef0e61e4_b2Rvb19zY3JpcHRzL2RvY2tlcl9kZXZfc3RhcnQucHk=..d0a9893d5e45d5c05ff63f967924cdb091334810_b2Rvb19zY3JpcHRzL2RvY2tlcl9kZXZfc3RhcnQucHk= 100755 --- a/odoo_scripts/docker_dev_start.py +++ b/odoo_scripts/docker_dev_start.py @@ -608,30 +608,6 @@ # TODO: handle the case where the database is still starting up # TODO: (and remove the sleep) _logger.info("Testing database connection on base postgres") - try: - if start_postgresql: - connect( - user=user, - password=password, - database="postgres", - host=socket_path, - port=5432, - ) - elif local_ip: - # TODO test this too - connect( - user=user, - password=password, - database="postgres", - host=local_ip, - port=dbport, - ) - else: - connect(user=user, password=password, database="postgres") - - except OperationalError as exception: - if nmspc.create_user: - _logger.debug("Cannot connect to database with user %s", user) - _logger.debug(exception) - _logger.info("Creating user %s", user) + if not odoo_help: + try: if start_postgresql: @@ -637,6 +613,7 @@ if start_postgresql: - connection = connect( - user="postgres", + connect( + user=user, + password=password, database="postgres", host=socket_path, port=5432, @@ -640,6 +617,14 @@ database="postgres", host=socket_path, port=5432, - password=POSTGRES_PASSWORD, + ) + elif local_ip: + # TODO test this too + connect( + user=user, + password=password, + database="postgres", + host=local_ip, + port=dbport, ) else: @@ -644,13 +629,37 @@ ) else: - loginname = pwd.getpwuid(os.getuid())[0] - # use socket to create user - # TODO test if removing more arguments works - connection = connect(user=loginname, database="postgres") - with connection.cursor() as cursor: - # not injection safe but you are on your own machine - # with already full access to db - cursor.execute( - "CREATE ROLE %s LOGIN CREATEDB PASSWORD %%s" % user, - (password,), + connect(user=user, password=password, database="postgres") + + except OperationalError as exception: + if nmspc.create_user: + _logger.debug("Cannot connect to database with user %s", user) + _logger.debug(exception) + _logger.info("Creating user %s", user) + if start_postgresql: + connection = connect( + user="postgres", + database="postgres", + host=socket_path, + port=5432, + password=POSTGRES_PASSWORD, + ) + else: + loginname = pwd.getpwuid(os.getuid())[0] + # use socket to create user + # TODO test if removing more arguments works + connection = connect(user=loginname, database="postgres") + with connection.cursor() as cursor: + # not injection safe but you are on your own machine + # with already full access to db + cursor.execute( + "CREATE ROLE %s LOGIN CREATEDB PASSWORD %%s" % user, + (password,), + ) + connection.commit() + connection.close() + else: + _logger.fatal("Cannot connect to database with user %s", user) + _logger.fatal(exception) + _logger.info( + "You can add the --create-user argument to create it" ) @@ -656,11 +665,5 @@ ) - connection.commit() - connection.close() - else: - _logger.fatal("Cannot connect to database with user %s", user) - _logger.fatal(exception) - _logger.info("You can add the --create-user argument to create it") - return 16 + return 16 # --- restore --- # TODO find out why odoo_help would stop us from restoring