Don Garrett | 7844a1b | 2018-05-03 13:58:46 -0700 | [diff] [blame] | 1 | import logging |
Alex Miller | 47d6128 | 2013-04-17 13:53:58 -0700 | [diff] [blame] | 2 | import os |
showard | 364fe86 | 2008-10-17 02:01:16 +0000 | [diff] [blame] | 3 | |
Alex Miller | 47d6128 | 2013-04-17 13:53:58 -0700 | [diff] [blame] | 4 | import common |
| 5 | |
| 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest_lib.frontend.settings') |
showard | fa8629c | 2008-11-04 16:51:23 +0000 | [diff] [blame] | 7 | |
Jakob Juelich | 8a764d1 | 2014-10-14 19:24:21 -0700 | [diff] [blame] | 8 | def _enable_autocommit_by_name(name): |
| 9 | """Enable autocommit for the connection with matching name. |
| 10 | |
| 11 | @param name: Name of the connection. |
| 12 | """ |
| 13 | from django.db import connections |
| 14 | # ensure a connection is open |
Don Garrett | 7844a1b | 2018-05-03 13:58:46 -0700 | [diff] [blame] | 15 | logging.info('Enabling autocommit for %s(%s)', |
| 16 | name, connections[name].settings_dict['HOST']) |
Jakob Juelich | 8a764d1 | 2014-10-14 19:24:21 -0700 | [diff] [blame] | 17 | connections[name].cursor() |
| 18 | connections[name].connection.autocommit(True) |
| 19 | |
| 20 | |
showard | fa8629c | 2008-11-04 16:51:23 +0000 | [diff] [blame] | 21 | def enable_autocommit(): |
Jakob Juelich | 8a764d1 | 2014-10-14 19:24:21 -0700 | [diff] [blame] | 22 | """Enable autocommit for default and global connection. |
| 23 | """ |
| 24 | _enable_autocommit_by_name('default') |
| 25 | _enable_autocommit_by_name('global') |