blob: 0387ea258984ae308b26eb16870fddec374f5ba4 [file] [log] [blame]
Don Garrett7844a1b2018-05-03 13:58:46 -07001import logging
Alex Miller47d61282013-04-17 13:53:58 -07002import os
showard364fe862008-10-17 02:01:16 +00003
Alex Miller47d61282013-04-17 13:53:58 -07004import common
5
6os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest_lib.frontend.settings')
showardfa8629c2008-11-04 16:51:23 +00007
Jakob Juelich8a764d12014-10-14 19:24:21 -07008def _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 Garrett7844a1b2018-05-03 13:58:46 -070015 logging.info('Enabling autocommit for %s(%s)',
16 name, connections[name].settings_dict['HOST'])
Jakob Juelich8a764d12014-10-14 19:24:21 -070017 connections[name].cursor()
18 connections[name].connection.autocommit(True)
19
20
showardfa8629c2008-11-04 16:51:23 +000021def enable_autocommit():
Jakob Juelich8a764d12014-10-14 19:24:21 -070022 """Enable autocommit for default and global connection.
23 """
24 _enable_autocommit_by_name('default')
25 _enable_autocommit_by_name('global')