summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: acee0ab)
raw | patch | inline | side by side (parent: acee0ab)
author | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 20 Feb 2009 04:38:34 +0000 (04:38 +0000) | ||
committer | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 20 Feb 2009 04:38:34 +0000 (04:38 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4151 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/backends/back_mysql.py | patch | blob | history | |
roundup/backends/rdbms_common.py | patch | blob | history | |
roundup/roundupdb.py | patch | blob | history |
index ccf7803f990920f22f76b36ee48a1f842cf2b014..bb233ffea862551ad9cf5a79fa2c395222369b98 100644 (file)
-#$Id: back_mysql.py,v 1.75 2008-02-27 08:32:50 richard Exp $
#
# Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <andrey@micro.lt>
#
# stupid MySQL bug requires us to drop all the tables first
for table in tables:
command = 'DROP TABLE `%s`'%table[0]
- if __debug__:
- logging.getLogger('hyperdb').debug(command)
+ self.log_debug(command)
cursor.execute(command)
command = "DROP DATABASE %s"%config.RDBMS_NAME
- logging.getLogger('hyperdb').info(command)
+ self.log_info(command)
cursor.execute(command)
conn.commit()
conn.close()
conn = MySQLdb.connect(**kwargs)
cursor = conn.cursor()
command = "CREATE DATABASE %s"%config.RDBMS_NAME
- logging.getLogger('hyperdb').info(command)
+ self.log_info(command)
cursor.execute(command)
conn.commit()
conn.close()
def sql_open_connection(self):
kwargs = connection_dict(self.config, 'db')
- logging.getLogger('hyperdb').info('open database %r'%(kwargs['db'],))
+ self.log_info('open database %r'%(kwargs['db'],))
try:
conn = MySQLdb.connect(**kwargs)
except MySQLdb.OperationalError, message:
def sql_commit(self, fail_ok=False):
''' Actually commit to the database.
'''
- logging.getLogger('hyperdb').info('commit')
+ self.log_info('commit')
# MySQL commits don't seem to ever fail, the latest update winning.
# makes you wonder why they have transactions...
self.sql("START TRANSACTION")
def sql_close(self):
- logging.getLogger('hyperdb').info('close')
+ self.log_info('close')
try:
self.conn.close()
except MySQLdb.ProgrammingError, message:
index b5ce677cc84fa231476afc6eaa9a59a4c7f450f9..02a5d7e6e6b98399373ff0cc7d8e8e05a3798ade 100644 (file)
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-#$Id: rdbms_common.py,v 1.199 2008-08-18 06:25:47 richard Exp $
""" Relational database (SQL) backend common code.
Basics:
def sql(self, sql, args=None):
""" Execute the sql with the optional args.
"""
- if __debug__:
- logging.getLogger('hyperdb').debug('SQL %r %r'%(sql, args))
+ self.log_debug('SQL %r %r'%(sql, args))
if args:
self.cursor.execute(sql, args)
else:
return 0
if version < 2:
- if __debug__:
- logging.getLogger('hyperdb').info('upgrade to version 2')
+ log_info('upgrade to version 2')
# change the schema structure
self.database_schema = {'tables': self.database_schema}
self.create_version_2_tables()
if version < 3:
- if __debug__:
- logging.getLogger('hyperdb').info('upgrade to version 3')
+ log_info('upgrade to version 3')
self.fix_version_2_tables()
if version < 4:
def addnode(self, classname, nodeid, node):
""" Add the specified node to its class's db.
"""
- if __debug__:
- logging.getLogger('hyperdb').debug('addnode %s%s %r'%(classname,
- nodeid, node))
+ self.log_debug('addnode %s%s %r'%(classname,
+ nodeid, node))
# determine the column definitions and multilink tables
cl = self.classes[classname]
def setnode(self, classname, nodeid, values, multilink_changes={}):
""" Change the specified node.
"""
- if __debug__:
- logging.getLogger('hyperdb').debug('setnode %s%s %r'
- % (classname, nodeid, values))
+ self.log_debug('setnode %s%s %r'
+ % (classname, nodeid, values))
# clear this node out of the cache if it's in there
key = (classname, nodeid)
# create the journal entry
cols = 'nodeid,date,tag,action,params'
- if __debug__:
- logging.getLogger('hyperdb').debug('addjournal %s%s %r %s %s %r'%(classname,
- nodeid, journaldate, journaltag, action, params))
+ self.log_debug('addjournal %s%s %r %s %s %r'%(classname,
+ nodeid, journaldate, journaltag, action, params))
# make the journalled data marshallable
if isinstance(params, type({})):
dc = self.hyperdb_to_sql_value[hyperdb.Date]
for nodeid, journaldate, journaltag, action, params in journal:
- if __debug__:
- logging.getLogger('hyperdb').debug('addjournal %s%s %r %s %s %r'%(
- classname, nodeid, journaldate, journaltag, action,
- params))
+ self.log_debug('addjournal %s%s %r %s %s %r'%(
+ classname, nodeid, journaldate, journaltag, action,
+ params))
# make the journalled data marshallable
if isinstance(params, type({})):
backward-compatibility reasons a single (dir, prop) tuple is
also allowed.
- "search_matches" is a sequence type or None
+ "search_matches" is a container type or None
The filter must match all properties specificed. If the property
value to match is a list:
diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py
index 1ddc30aac7f1f75e63cbe1a18e70524e4391bf36..a12948005cad0795429c3bc985b50d65f64a2a8c 100644 (file)
--- a/roundup/roundupdb.py
+++ b/roundup/roundupdb.py
import re, os, smtplib, socket, time, random
import cStringIO, base64, quopri, mimetypes
import os.path
+import logging
from rfc2822 import encode_header
return userid
+ def log_debug(self, msg, *args, **kwargs):
+ """Log a message with level DEBUG."""
+
+ logger = self.get_logger()
+ logger.debug(msg, *args, **kwargs)
+
+ def log_info(self, msg, *args, **kwargs):
+ """Log a message with level INFO."""
+
+ logger = self.get_logger()
+ logger.info(msg, *args, **kwargs)
+
+ def get_logger(self):
+ """Return the logger for this database."""
+
+ # Because getting a logger requires acquiring a lock, we want
+ # to do it only once.
+ if not hasattr(self, '__logger'):
+ self.__logger = logging.getLogger('hyperdb')
+
+ return self.__logger
+
+
class DetectorError(RuntimeError):
""" Raised by detectors that want to indicate that something's amiss
"""