1import logging 2import os 3 4import common 5 6os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest_lib.frontend.settings') 7 8def _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 15 logging.info('Enabling autocommit for %s(%s)', 16 name, connections[name].settings_dict['HOST']) 17 connections[name].cursor() 18 connections[name].connection.autocommit(True) 19 20 21def enable_autocommit(): 22 """Enable autocommit for default and global connection. 23 """ 24 _enable_autocommit_by_name('default') 25 _enable_autocommit_by_name('global') 26