Mercurial > p > roundup > code
changeset 3156:e1da7b5b04ab maint-0.8
merge from HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 14 Feb 2005 02:55:31 +0000 |
| parents | 62b1a54107e6 |
| children | 124638970f0a |
| files | CHANGES.txt roundup/backends/back_anydbm.py roundup/backends/back_metakit.py roundup/backends/back_mysql.py roundup/backends/back_postgresql.py roundup/backends/back_sqlite.py roundup/backends/rdbms_common.py roundup/configuration.py roundup/mailgw.py roundup/rcsv.py test/db_test_base.py |
| diffstat | 11 files changed, 75 insertions(+), 151 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Mon Feb 14 01:26:14 2005 +0000 +++ b/CHANGES.txt Mon Feb 14 02:55:31 2005 +0000 @@ -20,6 +20,8 @@ - consistent text searching behaviour (AND everywhere) (sf bug 1101036) - fix handling of invalid date input (sf bug 1102165) - retain Boolean selections in edit error handling (sf bug 1101492) +- fix initialisation of logging module from config file (sf bug 1108577) +- removed rlog module (py 2.3 is minimum version now) 2005-01-13 0.8.0b2
--- a/roundup/backends/back_anydbm.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/backends/back_anydbm.py Mon Feb 14 02:55:31 2005 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.179.2.4 2005-02-13 22:40:53 richard Exp $ +#$Id: back_anydbm.py,v 1.179.2.5 2005-02-14 02:55:30 richard Exp $ '''This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several @@ -33,7 +33,7 @@ except AssertionError: print "WARNING: you should upgrade to python 2.1.3" -import whichdb, os, marshal, re, weakref, string, copy, time, shutil +import whichdb, os, marshal, re, weakref, string, copy, time, shutil, logging from roundup import hyperdb, date, password, roundupdb, security from roundup.backends import locking @@ -177,7 +177,7 @@ def clear(self): '''Delete all database contents ''' - self.config.logging.getLogger('hyperdb').info('clear') + logging.getLogger('hyperdb').info('clear') for cn in self.classes.keys(): for dummy in 'nodes', 'journals': path = os.path.join(self.dir, 'journals.%s'%cn) @@ -223,7 +223,7 @@ # new database? let anydbm pick the best dbm if not db_type: if __debug__: - self.config.logging.getLogger('hyperdb').debug("opendb anydbm.open(%r, 'c')"%path) + logging.getLogger('hyperdb').debug("opendb anydbm.open(%r, 'c')"%path) return anydbm.open(path, 'c') # open the database with the correct module @@ -234,7 +234,7 @@ "Couldn't open database - the required module '%s'"\ " is not available"%db_type if __debug__: - self.config.logging.getLogger('hyperdb').debug("opendb %r.open(%r, %r)"%(db_type, path, + logging.getLogger('hyperdb').debug("opendb %r.open(%r, %r)"%(db_type, path, mode)) return dbm.open(path, mode) @@ -295,7 +295,7 @@ ''' perform the saving of data specified by the set/addnode ''' if __debug__: - self.config.logging.getLogger('hyperdb').debug('save %s%s %r'%(classname, nodeid, node)) + logging.getLogger('hyperdb').debug('save %s%s %r'%(classname, nodeid, node)) self.transactions.append((self.doSaveNode, (classname, nodeid, node))) def getnode(self, classname, nodeid, db=None, cache=1): @@ -308,14 +308,14 @@ cache_dict = self.cache.setdefault(classname, {}) if cache_dict.has_key(nodeid): if __debug__: - self.config.logging.getLogger('hyperdb').debug('get %s%s cached'%(classname, nodeid)) + logging.getLogger('hyperdb').debug('get %s%s cached'%(classname, nodeid)) self.stats['cache_hits'] += 1 return cache_dict[nodeid] if __debug__: self.stats['cache_misses'] += 1 start_t = time.time() - self.config.logging.getLogger('hyperdb').debug('get %s%s'%(classname, nodeid)) + logging.getLogger('hyperdb').debug('get %s%s'%(classname, nodeid)) # get from the database and save in the cache if db is None: @@ -347,7 +347,7 @@ '''Remove a node from the database. Called exclusively by the destroy() method on Class. ''' - self.config.logging.getLogger('hyperdb').info('destroy %s%s'%(classname, nodeid)) + logging.getLogger('hyperdb').info('destroy %s%s'%(classname, nodeid)) # remove from cache and newnodes if it's there if (self.cache.has_key(classname) and @@ -473,7 +473,7 @@ the current user. ''' if __debug__: - self.config.logging.getLogger('hyperdb').debug('addjournal %s%s %s %r %s %r'%(classname, + logging.getLogger('hyperdb').debug('addjournal %s%s %s %r %s %r'%(classname, nodeid, action, params, creator, creation)) if creator is None: creator = self.getuid() @@ -483,7 +483,7 @@ def setjournal(self, classname, nodeid, journal): '''Set the journal to the "journal" list.''' if __debug__: - self.config.logging.getLogger('hyperdb').debug('setjournal %s%s %r'%(classname, + logging.getLogger('hyperdb').debug('setjournal %s%s %r'%(classname, nodeid, journal)) self.transactions.append((self.doSetJournal, (classname, nodeid, journal))) @@ -570,7 +570,7 @@ packed += 1 db[key] = marshal.dumps(l) - self.config.logging.getLogger('hyperdb').info('packed %d %s items'%(packed, + logging.getLogger('hyperdb').info('packed %d %s items'%(packed, classname)) if db_type == 'gdbm': @@ -584,7 +584,7 @@ def commit(self): ''' Commit the current transactions. ''' - self.config.logging.getLogger('hyperdb').info('commit %s transactions'%( + logging.getLogger('hyperdb').info('commit %s transactions'%( len(self.transactions))) # keep a handle to all the database files opened @@ -705,7 +705,7 @@ def rollback(self): ''' Reverse all actions from the current transaction. ''' - self.config.logging.getLogger('hyperdb').info('rollback %s transactions'%( + logging.getLogger('hyperdb').info('rollback %s transactions'%( len(self.transactions))) for method, args in self.transactions:
--- a/roundup/backends/back_metakit.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/backends/back_metakit.py Mon Feb 14 02:55:31 2005 +0000 @@ -1,4 +1,4 @@ -# $Id: back_metakit.py,v 1.88.2.2 2005-02-14 01:26:14 richard Exp $ +# $Id: back_metakit.py,v 1.88.2.3 2005-02-14 02:55:31 richard Exp $ '''Metakit backend for Roundup, originally by Gordon McMillan. Known Current Bugs: @@ -42,6 +42,7 @@ BACKWARDS_COMPATIBLE = 1 from roundup import hyperdb, date, password, roundupdb, security +import logging import metakit from sessions_dbm import Sessions, OneTimeKeys import re, marshal, os, sys, time, calendar, shutil @@ -259,7 +260,7 @@ try: params = marshal.loads(row.params) except ValueError: - self.config.logging.getLogger("hyperdb").error( + logging.getLogger("hyperdb").error( "history couldn't unmarshal %r" % row.params) params = {} #usernm = userclass.get(str(row.user), 'username') @@ -1374,14 +1375,14 @@ try: prop = getattr(v, propname) except AttributeError: - self.config.logging.getLogger("hyperdb").error( + logging.getLogger("hyperdb").error( "MK has no property %s" % propname) continue propclass = self.ruprops.get(propname, None) if propclass is None: propclass = self.privateprops.get(propname, None) if propclass is None: - self.config.logging.getLogger("hyperdb").error( + logging.getLogger("hyperdb").error( "Schema has no property %s" % propname) continue if isinstance(propclass, hyperdb.Link):
--- a/roundup/backends/back_mysql.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/backends/back_mysql.py Mon Feb 14 02:55:31 2005 +0000 @@ -38,6 +38,7 @@ import MySQLdb import os, shutil from MySQLdb.constants import ER +import logging def connection_dict(config, dbnamestr=None): d = rdbms_common.connection_dict(config, dbnamestr) @@ -66,10 +67,10 @@ for table in tables: command = 'DROP TABLE %s'%table[0] if __debug__: - config.logging.getLogger('hyperdb').debug(command) + logging.getLogger('hyperdb').debug(command) cursor.execute(command) command = "DROP DATABASE %s"%config.RDBMS_NAME - config.logging.getLogger('hyperdb').info(command) + logging.getLogger('hyperdb').info(command) cursor.execute(command) conn.commit() conn.close() @@ -83,7 +84,7 @@ conn = MySQLdb.connect(**kwargs) cursor = conn.cursor() command = "CREATE DATABASE %s"%config.RDBMS_NAME - config.logging.getLogger('hyperdb').info(command) + logging.getLogger('hyperdb').info(command) cursor.execute(command) conn.commit() conn.close() @@ -138,8 +139,7 @@ def sql_open_connection(self): kwargs = connection_dict(self.config, 'db') - self.config.logging.getLogger('hyperdb').info('open database %r'%( - kwargs['db'],)) + logging.getLogger('hyperdb').info('open database %r'%(kwargs['db'],)) try: conn = MySQLdb.connect(**kwargs) except MySQLdb.OperationalError, message: @@ -474,7 +474,7 @@ def sql_commit(self): ''' Actually commit to the database. ''' - self.config.logging.getLogger('hyperdb').info('commit') + logging.getLogger('hyperdb').info('commit') self.conn.commit() # open a new cursor for subsequent work
--- a/roundup/backends/back_postgresql.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/backends/back_postgresql.py Mon Feb 14 02:55:31 2005 +0000 @@ -10,6 +10,7 @@ import os, shutil, popen2, time import psycopg +import logging from roundup import hyperdb, date from roundup.backends import rdbms_common @@ -26,13 +27,13 @@ def db_create(config): """Clear all database contents and drop database itself""" command = 'CREATE DATABASE %s'%config.RDBMS_NAME - config.logging.getLogger('hyperdb').info(command) + logging.getLogger('hyperdb').info(command) db_command(config, command) def db_nuke(config, fail_ok=0): """Clear all database contents and drop database itself""" command = 'DROP DATABASE %s'% config.RDBMS_NAME - config.logging.getLogger('hyperdb').info(command) + logging.getLogger('hyperdb').info(command) db_command(config, command) if os.path.exists(config.DATABASE): @@ -95,8 +96,7 @@ def sql_open_connection(self): db = connection_dict(self.config, 'database') - self.config.logging.getLogger('hyperdb').info('open database %r'%( - db['database'],)) + logging.getLogger('hyperdb').info('open database %r'%db['database']) try: conn = psycopg.connect(**db) except psycopg.OperationalError, message:
--- a/roundup/backends/back_sqlite.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/backends/back_sqlite.py Mon Feb 14 02:55:31 2005 +0000 @@ -1,4 +1,4 @@ -# $Id: back_sqlite.py,v 1.36.2.2 2005-01-04 01:33:03 richard Exp $ +# $Id: back_sqlite.py,v 1.36.2.3 2005-02-14 02:55:31 richard Exp $ '''Implements a backend for SQLite. See https://pysqlite.sourceforge.net/ for pysqlite info @@ -9,7 +9,7 @@ ''' __docformat__ = 'restructuredtext' -import os, base64, marshal, shutil, time +import os, base64, marshal, shutil, time, logging from roundup import hyperdb, date, password from roundup.backends import locking @@ -85,7 +85,7 @@ os.makedirs(self.config.DATABASE) db = os.path.join(self.config.DATABASE, 'db') - self.config.logging.getLogger('hyperdb').info('open database %r'%db) + logging.getLogger('hyperdb').info('open database %r'%db) conn = sqlite.connect(db=db) # set a 30 second timeout (extraordinarily generous) for handling # locked database @@ -159,7 +159,7 @@ # no changes return 0 - self.config.logging.getLogger('hyperdb').info('update_class %s'%spec.classname) + logging.getLogger('hyperdb').info('update_class %s'%spec.classname) # detect multilinks that have been removed, and drop their table old_has = {}
--- a/roundup/backends/rdbms_common.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/backends/rdbms_common.py Mon Feb 14 02:55:31 2005 +0000 @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.142.2.4 2005-02-13 22:40:53 richard Exp $ +# $Id: rdbms_common.py,v 1.142.2.5 2005-02-14 02:55:31 richard Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -29,7 +29,7 @@ __docformat__ = 'restructuredtext' # standard python modules -import sys, os, time, re, errno, weakref, copy +import sys, os, time, re, errno, weakref, copy, logging # roundup modules from roundup import hyperdb, date, password, roundupdb, security @@ -128,7 +128,7 @@ ''' Execute the sql with the optional args. ''' if __debug__: - self.config.logging.getLogger('hyperdb').debug('SQL %r %r'%(sql, args)) + logging.getLogger('hyperdb').debug('SQL %r %r'%(sql, args)) if args: self.cursor.execute(sql, args) else: @@ -225,7 +225,7 @@ if version < 2: if __debug__: - self.config.logging.getLogger('hyperdb').info('upgrade to version 2') + logging.getLogger('hyperdb').info('upgrade to version 2') # change the schema structure self.database_schema = {'tables': self.database_schema} @@ -239,7 +239,7 @@ if version < 3: if __debug__: - self.config.logging.getLogger('hyperdb').info('upgrade to version 3') + logging.getLogger('hyperdb').info('upgrade to version 3') self.fix_version_2_tables() if version < 4: @@ -380,7 +380,7 @@ # no changes return 0 - logger = self.config.logging.getLogger('hyperdb') + logger = logging.getLogger('hyperdb') logger.info('update_class %s'%spec.classname) logger.debug('old_spec %r'%(old_spec,)) @@ -668,7 +668,7 @@ Note: I don't commit here, which is different behaviour to the "nuke from orbit" behaviour in the dbs. ''' - self.config.logging.getLogger('hyperdb').info('clear') + logging.getLogger('hyperdb').info('clear') for cn in self.classes.keys(): sql = 'delete from _%s'%cn self.sql(sql) @@ -693,7 +693,7 @@ ''' Add the specified node to its class's db. ''' if __debug__: - self.config.logging.getLogger('hyperdb').debug('addnode %s%s %r'%(classname, + logging.getLogger('hyperdb').debug('addnode %s%s %r'%(classname, nodeid, node)) # determine the column definitions and multilink tables @@ -768,7 +768,7 @@ ''' Change the specified node. ''' if __debug__: - self.config.logging.getLogger('hyperdb').debug('setnode %s%s %r' + logging.getLogger('hyperdb').debug('setnode %s%s %r' % (classname, nodeid, values)) # clear this node out of the cache if it's in there @@ -953,7 +953,7 @@ '''Remove a node from the database. Called exclusively by the destroy() method on Class. ''' - self.config.logging.getLogger('hyperdb').info('destroynode %s%s'%(classname, nodeid)) + logging.getLogger('hyperdb').info('destroynode %s%s'%(classname, nodeid)) # make sure the node exists if not self.hasnode(classname, nodeid): @@ -1022,7 +1022,7 @@ cols = 'nodeid,date,tag,action,params' if __debug__: - self.config.logging.getLogger('hyperdb').debug('addjournal %s%s %r %s %s %r'%(classname, + logging.getLogger('hyperdb').debug('addjournal %s%s %r %s %s %r'%(classname, nodeid, journaldate, journaltag, action, params)) # make the journalled data marshallable @@ -1049,7 +1049,7 @@ dc = self.hyperdb_to_sql_value[hyperdb.Date] for nodeid, journaldate, journaltag, action, params in journal: if __debug__: - self.config.logging.getLogger('hyperdb').debug('addjournal %s%s %r %s %s %r'%( + logging.getLogger('hyperdb').debug('addjournal %s%s %r %s %s %r'%( classname, nodeid, journaldate, journaltag, action, params)) @@ -1151,7 +1151,7 @@ def sql_commit(self): ''' Actually commit to the database. ''' - self.config.logging.getLogger('hyperdb').info('commit') + logging.getLogger('hyperdb').info('commit') self.conn.commit() # open a new cursor for subsequent work @@ -1185,7 +1185,7 @@ Undo all the changes made since the database was opened or the last commit() or rollback() was performed. ''' - self.config.logging.getLogger('hyperdb').info('rollback') + logging.getLogger('hyperdb').info('rollback') self.sql_rollback() @@ -1200,7 +1200,7 @@ self.clearCache() def sql_close(self): - self.config.logging.getLogger('hyperdb').info('close') + logging.getLogger('hyperdb').info('close') self.conn.close() def close(self):
--- a/roundup/configuration.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/configuration.py Mon Feb 14 02:55:31 2005 +0000 @@ -1,6 +1,6 @@ # Roundup Issue Tracker configuration support # -# $Id: configuration.py,v 1.23.2.1 2005-01-13 05:05:11 richard Exp $ +# $Id: configuration.py,v 1.23.2.2 2005-02-14 02:55:30 richard Exp $ # __docformat__ = "restructuredtext" @@ -9,8 +9,9 @@ import os import time import ConfigParser +import logging, logging.config +import sys -from roundup import rlog # XXX i don't think this module needs string translation, does it? ### Exceptions @@ -1028,15 +1029,12 @@ # module name for old style configuration PYCONFIG = "config" - # placeholder so we can assign later - logging = None # user configs ext = None detectors = None def __init__(self, home_dir=None): Config.__init__(self, home_dir, SETTINGS) - self.logging = rlog.BasicLogging() # load the config if home_dir given if home_dir is None: self.init_logging() @@ -1066,21 +1064,22 @@ def init_logging(self): _file = self["LOGGING_CONFIG"] if _file and os.path.isfile(_file): - try: - import logging - _logging = logging - except ImportError, _err: - _option = self._get_option("LOGGING_CONFIG") - raise OptionValueError(_option, _file, - "Python logging module is not available: %s" % _err) - _logging.fileConfig(_file) + logging.config.fileConfig(_file) + return + + _file = self["LOGGING_FILENAME"] + # set file & level on the root logger + logger = logging.getLogger() + if _file: + hdlr = logging.FileHandler(_file) else: - _logging = rlog.BasicLogging() - _file = self["LOGGING_FILENAME"] - if _file: - _logging.setFile(_file) - _logging.setLevel(self["LOGGING_LEVEL"] or "ERROR") - self.logging = _logging + hdlr = logging.StreamHandler(sys.stdout) + formatter = logging.Formatter( + '%(asctime)s %(levelname)s %(message)s') + hdlr.setFormatter(formatter) + # no logging API to remove all existing handlers!?! + logger.handlers = [hdlr] + logger.setLevel(logging._levelNames[self["LOGGING_LEVEL"] or "ERROR"]) def load(self, home_dir): """Load configuration from path designated by home_dir argument"""
--- a/roundup/mailgw.py Mon Feb 14 01:26:14 2005 +0000 +++ b/roundup/mailgw.py Mon Feb 14 02:55:31 2005 +0000 @@ -72,12 +72,12 @@ an exception, the original message is bounced back to the sender with the explanatory message given in the exception. -$Id: mailgw.py,v 1.159.2.1 2005-01-03 02:53:41 richard Exp $ +$Id: mailgw.py,v 1.159.2.2 2005-02-14 02:55:30 richard Exp $ """ __docformat__ = 'restructuredtext' import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri -import time, random, sys +import time, random, sys, logging import traceback, MimeWriter, rfc822 from roundup import hyperdb, date, password, rfc2822, exceptions @@ -319,7 +319,7 @@ self.default_class = value.strip() self.mailer = Mailer(instance.config) - self.logger = instance.config.logging.getLogger('mailgw') + self.logger = getLogger('mailgw') # should we trap exceptions (normal usage) or pass them through # (for testing)
--- a/roundup/rcsv.py Mon Feb 14 01:26:14 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -"""Supplies a Python-2.3 Object Craft csv module work-alike to the extent -needed by Roundup using the Python 2.3 csv module. -""" -__docformat__ = 'restructuredtext' - -from roundup.i18n import _ -from cStringIO import StringIO -error = """ -Sorry, you need a csv module. Either upgrade your Python to 2.3 or later, -or get and install the csv module from: -http://www.object-craft.com.au/projects/csv/ -""" -try: - import csv - try: - _reader = csv.reader - writer = csv.writer - excel = csv.excel - error = '' - except AttributeError: - # fake it all up using the Object-Craft CSV module - class excel: - delimiter = ':' - if hasattr(csv, 'parser'): - error = '' - def _reader(fileobj, dialect=excel): - # note real readers take an iterable but 2.1 doesn't - # support iterable access to file objects. - result = [] - p = csv.parser(field_sep=dialect.delimiter) - - while 1: - line = fileobj.readline() - if not line: break - - # parse lines until we get a complete entry - while 1: - fields = p.parse(line) - if fields: break - line = fileobj.readline() - if not line: - raise ValueError, "Unexpected EOF during CSV parse" - result.append(fields) - return result - class writer: - def __init__(self, fileobj, dialect=excel): - self.fileobj = fileobj - self.p = csv.parser(field_sep = dialect.delimiter) - def writerow(self, fields): - print >>self.fileobj, self.p.join(fields) - def writerows(self, rows): - for fields in rows: - print >>self.fileobj, self.p.join(fields) - -except ImportError: - class excel: - delimiter = ':' - -class colon_separated(excel): - delimiter = ':' -class comma_separated(excel): - delimiter = ',' - -def reader(fileobject, dialect=excel): - csv_lines = [line for line in fileobject.readlines() if line.strip()] - return _reader(StringIO(''.join(csv_lines)), dialect) - -if __name__ == "__main__": - f=open('testme.txt', 'r') - r = reader(f, colon_separated) - remember = [] - for record in r: - print record - remember.append(record) - f.close() - import sys - w = writer(sys.stdout, colon_separated) - w.writerows(remember) -
--- a/test/db_test_base.py Mon Feb 14 01:26:14 2005 +0000 +++ b/test/db_test_base.py Mon Feb 14 02:55:31 2005 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: db_test_base.py,v 1.55.2.3 2005-02-13 22:40:53 richard Exp $ +# $Id: db_test_base.py,v 1.55.2.4 2005-02-14 02:55:31 richard Exp $ import unittest, os, shutil, errno, imp, sys, time, pprint @@ -38,8 +38,9 @@ # uncomment the following to have excessive debug output from test cases # FIXME: tracker logging level should be increased by -v arguments # to 'run_tests.py' script -#config.LOGGING_LEVEL = "DEBUG" -#config.init_logging() +config.LOGGING_FILENAME = "/tmp/logfile" +config.LOGGING_LEVEL = "DEBUG" +config.init_logging() def setupTracker(dirname, backend="anydbm"): """Install and initialize new tracker in dirname; return tracker instance.
