Merge branch 'warning-non-flushed-mysql-cache' into test-v3

This commit is contained in:
2016-03-02 17:13:08 +01:00

View File

@@ -31,6 +31,8 @@ try:
except ImportError: except ImportError:
import MySQLdb as mysqldb import MySQLdb as mysqldb
import atexit
from pywikibot import config from pywikibot import config
import jogobot import jogobot
@@ -73,6 +75,9 @@ class MysqlRed:
passwd=type( self ).db_password, passwd=type( self ).db_password,
db=type( self ).db_name ) db=type( self ).db_name )
# Register callback for warnig if exit with cached db write querys
atexit.register( type(self).warn_if_not_flushed )
def __del__( self ): def __del__( self ):
""" """
Before deleting class, close connection to MySQL-DB Before deleting class, close connection to MySQL-DB
@@ -108,6 +113,16 @@ class MysqlRed:
if cls._cached_insert_data or cls._cached_update_data: if cls._cached_insert_data or cls._cached_update_data:
cls.connection.commit() cls.connection.commit()
@classmethod
def warn_if_not_flushed(cls):
"""
Outputs a warning if there are db write querys cached and not flushed
before exiting programm!
"""
if cls._cached_update_data or cls._cached_insert_data:
jogobot.output( "Cached Database write querys not flushed!!! " +
"Data loss is possible!", "WARNING" )
class MysqlRedPage( MysqlRed ): class MysqlRedPage( MysqlRed ):
""" """