gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r813663 - in /gump/live/python/gump: actor/stats/mysql/statsdb.py util/mysql.py
Date Fri, 11 Sep 2009 04:20:11 GMT
Author: bodewig
Date: Fri Sep 11 04:20:11 2009
New Revision: 813663

URL: http://svn.apache.org/viewvc?rev=813663&view=rev
Log:
This worked on helios, let's see whether it fixes the problems on vmgump

Modified:
    gump/live/python/gump/actor/stats/mysql/statsdb.py
    gump/live/python/gump/util/mysql.py

Modified: gump/live/python/gump/actor/stats/mysql/statsdb.py
URL: http://svn.apache.org/viewvc/gump/live/python/gump/actor/stats/mysql/statsdb.py?rev=813663&r1=813662&r2=813663&view=diff
==============================================================================
--- gump/live/python/gump/actor/stats/mysql/statsdb.py (original)
+++ gump/live/python/gump/actor/stats/mysql/statsdb.py Fri Sep 11 04:20:11 2009
@@ -17,266 +17,302 @@
 """
 
     MySQL Statistics gathering/manipulation
-    
+
 """
 
 import time
 import datetime
 import types
-import os
 import sys
 
 import MySQLdb
 import MySQLdb.cursors
 
 from gump import log
-from gump.core.config import *
-from gump.core.model.project import Project, ProjectStatistics
-from gump.core.model.module import Module, ModuleStatistics
-from gump.core.model.repository import Repository, RepositoryStatistics
-from gump.core.model.workspace import Workspace, WorkspaceStatistics
-from gump.core.model.state import *
+from gump.core.model.project import ProjectStatistics
+from gump.core.model.module import ModuleStatistics
+from gump.core.model.repository import RepositoryStatistics
+from gump.core.model.workspace import WorkspaceStatistics
 
 import gump.util.mysql
-import gump.util.timing
-  
+from gump.util.timing import getLocalNow
+
 class StatisticsDB:
     """
-    	MySQL Statistics Database Interface
+        MySQL Statistics Database Interface
     """
-    
-    FIRST_COLUMN='first'
-    LAST_COLUMN='last'
-    START_OF_STATE_COLUMN='start_of_state'
-    LAST_MODIFIED_COLUMN='last_modified'
-    
-    DATES=[ FIRST_COLUMN, 
-            LAST_COLUMN,
-            START_OF_STATE_COLUMN,
-            LAST_MODIFIED_COLUMN ]
-    
-    ATTR_COLUMN_MAP={
-                        'successes':'successes',
-                        'failures':'failures',
-                        'prereqs':'prereqs',
-                        'first':FIRST_COLUMN,
-                        'last':LAST_COLUMN,
-                        'currentState':'current_state',
-                        'previousState':'previous_state',
-                        'startOfState':START_OF_STATE_COLUMN,
-                        'sequenceInState':'sequence_in_state'
-                    }
-    
-    def __init__(self,dbInfo):
-        self.conn=MySQLdb.Connect(
-                host=dbInfo.getHost(), 
-                user=dbInfo.getUser(),
-                passwd=dbInfo.getPasswd(), 
-                db=dbInfo.getDatabase(),
-                compress=1,
-                cursorclass=MySQLdb.cursors.DictCursor)
-            
+
+    FIRST_COLUMN = 'first'
+    LAST_COLUMN = 'last'
+    START_OF_STATE_COLUMN = 'start_of_state'
+    LAST_MODIFIED_COLUMN = 'last_modified'
+
+    DATES = [ FIRST_COLUMN, 
+              LAST_COLUMN,
+              START_OF_STATE_COLUMN,
+              LAST_MODIFIED_COLUMN ]
+
+    ATTR_COLUMN_MAP = {
+        'successes' : 'successes',
+        'failures' : 'failures',
+        'prereqs' : 'prereqs',
+        'first' : FIRST_COLUMN,
+        'last' : LAST_COLUMN,
+        'currentState' : 'current_state',
+        'previousState' : 'previous_state',
+        'startOfState' : START_OF_STATE_COLUMN,
+        'sequenceInState' : 'sequence_in_state'
+        }
+
+    def __init__(self, dbInfo):
+        self._dbinfo = dbInfo
+        self._helper = None
+
+    def _get_helper(self):
+        """
+        Returns a cached DBHelper or creates and caches a new one
+        """
+        if self._helper:
+            return self._helper
+        conn = MySQLdb.Connect(
+            host = self._dbinfo.getHost(), 
+            user = self._dbinfo.getUser(),
+            passwd = self._dbinfo.getPasswd(), 
+            db = self._dbinfo.getDatabase(),
+            compress = 1,
+            cursorclass = MySQLdb.cursors.DictCursor)
+
         # print 'ThreadSafe : ' + `MySQLdb.threadsafety`
-        
-        self.helper=gump.util.mysql.DbHelper(self.conn,dbInfo.getDatabase())
+
+        self._helper = gump.util.mysql.DbHelper(conn,
+                                                self._dbinfo.getDatabase())
+        return self._helper
  
     # Workspace
-    def getWorkspaceStats(self,workspaceName):
-        stats=WorkspaceStatistics(workspaceName)
+    def getWorkspaceStats(self, workspaceName):
+        stats = WorkspaceStatistics(workspaceName)
         try:
-            self._getStats('gump_workspace_stats','workspace_name',workspaceName,stats)
+            self._getStats('gump_workspace_stats', 'workspace_name',
+                           workspaceName,stats)
         except IndexError:
             pass
         return stats
-        
-    def putWorkspaceStats(self,stats):
-        self._putStats('gump_workspace_stats','workspace_name',stats)
-
-    def delWorkspaceStats(self,stats):
-        self._delStats('gump_workspace_stats','workspace_name',stats)          
-        
-    # Project    
-    def getProjectStats(self,projectName):
-        stats=ProjectStatistics(projectName)         
+
+    def putWorkspaceStats(self, stats):
+        self._putStats('gump_workspace_stats', 'workspace_name', stats)
+
+    def delWorkspaceStats(self, stats):
+        self._delStats('gump_workspace_stats', 'workspace_name', stats)
+
+    # Project
+    def getProjectStats(self, projectName):
+        stats = ProjectStatistics(projectName)
         try:
-            self._getStats('gump_project_stats','project_name',projectName,stats)       
 
+            self._getStats('gump_project_stats', 'project_name', projectName,
+                           stats)
         except IndexError:
             pass
         return stats
-                
-    def putProjectStats(self,stats): 
-        self._putStats('gump_project_stats','project_name',stats)
-        
-    def delProjectStats(self,stats): 
-        self._delStats('gump_project_stats','project_name',stats)
+
+    def putProjectStats(self, stats): 
+        self._putStats('gump_project_stats', 'project_name', stats)
+
+    def delProjectStats(self, stats): 
+        self._delStats('gump_project_stats', 'project_name', stats)
 
     # Repository 
-    def getRepositoryStats(self,repositoryName):
-        stats=RepositoryStatistics(repositoryName)     
-        try:   
-            self._getStats('gump_repository_stats','repository_name',repositoryName,stats)
+    def getRepositoryStats(self, repositoryName):
+        stats = RepositoryStatistics(repositoryName)
+        try:
+            self._getStats('gump_repository_stats', 'repository_name',
+                           repositoryName, stats)
         except IndexError:
-            pass    
+            pass
         return stats
-                
-    def putRepositoryStats(self,stats):
-        self._putStats('gump_repository_stats','repository_name',stats)  
-
-    def delRepositoryStats(self,stats):
-        self._delStats('gump_repository_stats','repository_name',stats)          
-
-    # Module    
-    def getModuleStats(self,moduleName):
-        stats=ModuleStatistics(moduleName)        
+
+    def putRepositoryStats(self, stats):
+        self._putStats('gump_repository_stats', 'repository_name', stats)
+
+    def delRepositoryStats(self, stats):
+        self._delStats('gump_repository_stats', 'repository_name', stats)
+
+    # Module
+    def getModuleStats(self, moduleName):
+        stats = ModuleStatistics(moduleName)
         try:
-            settings = self._getStats('gump_module_stats','module_name',moduleName,stats)
-            
+            settings = self._getStats('gump_module_stats', 'module_name',
+                                      moduleName, stats)
+
             # Extract that extra
             if settings.has_key('last_modified') and settings['last_modified']:
-                value=settings['last_modified']
-                if isinstance(value,datetime.datetime):
-                    stats.lastModified=value
+                value = settings['last_modified']
+                if isinstance(value, datetime.datetime):
+                    stats.lastModified = value
                 else:
                     if not value == '0000-00-00 00:00:00':
-                        stats.lastModified=datetime.datetime.fromtimestamp( \
-                                                time.mktime(time.strptime(value,
-                                                                          '%Y-%m-%d %H:%M:%S')))
                
+                        stats.lastModified = datetime.datetime.fromtimestamp( \
+                            time.mktime(time.strptime(value,
+                                                      '%Y-%m-%d %H:%M:%S')))
         except IndexError:
             pass
         return stats
-                
-    def putModuleStats(self,stats):
-        extras=None
+
+    def putModuleStats(self, stats):
+        extras = None
         if stats.lastModified:
-            extras={'last_modified':"'" + stats.lastModified.strftime('%Y-%m-%d %H:%M:%S')
+ "'"}        
-        self._putStats('gump_module_stats','module_name',stats,extras)
+            extras = {'last_modified' : "'" +\
+                          stats.lastModified.strftime('%Y-%m-%d %H:%M:%S') +\
+                          "'"}
+        self._putStats('gump_module_stats', 'module_name', stats, extras)
+
+    def delModuleStats(self, stats):
+        self._delStats('gump_module_stats', 'module_name', stats)
+
 
-    def delModuleStats(self,stats):
-        self._delStats('gump_module_stats','module_name',stats)     
-        
-        
     # Helpers...
-    def _getStats(self,table_name,column_name,entity_name,stats):
-        
+    def _getStats(self, table_name, column_name, entity_name, stats):
+
         # Select the row settings from the database
-        settings=self.helper.select(table_name,column_name,entity_name,
-                                StatisticsDB.ATTR_COLUMN_MAP.values())
-        
+        settings = self._with_reconnect_on_error(\
+            lambda helper:
+                helper.select(table_name, column_name, entity_name,
+                              StatisticsDB.ATTR_COLUMN_MAP.values()))
+
         # Extract columns
-        self._getBaseStats(stats,settings)
-            
+        self._getBaseStats(stats, settings)
+
         return settings
-        
-    def _putStats(self,table_name,column_name,stats,extras=None): 
-    
-        settings = self._putBaseStats(stats,column_name)
-        if extras: 
-            for (key,value) in extras.items(): settings[key] = value
-            
+
+    def _putStats(self, table_name, column_name, stats, extras = None): 
+
+        settings = self._putBaseStats(stats, column_name)
+        if extras:
+            for (key, value) in extras.items():
+                settings[key] = value
+
         # Perform the update (we've ensured a row exists).
-        self.helper.set(table_name,column_name,stats.name,settings)
-    
-    def _delStats(self,table_name,column_name,stats):       
-        """ Perform an SQL DELETE """        
+        self._with_reconnect_on_error(\
+            lambda helper:
+                helper.set(table_name, column_name, stats.name, settings))
+
+    def _delStats(self, table_name, column_name, stats):
+        """ Perform an SQL DELETE """
         # Perform the delete
-        self.helper.delete(table_name,column_name,stats.name)
+        self._with_reconnect_on_error(\
+            lambda helper:
+                helper.delete(table_name, column_name, stats.name))
 
-    def _getBaseStats(self,stats,settings):
+    def _getBaseStats(self, stats, settings):
         """
         Extract values by name from the DB row
-        """      
+        """
         for (attr, column) in StatisticsDB.ATTR_COLUMN_MAP.items():
             if settings.has_key(column) and settings[column]:
-                if hasattr(stats,attr):
-                    value=settings[column]
-                    
+                if hasattr(stats, attr):
+                    value = settings[column]
+
                     # Seems some SQL interfaces do not return datetime objects
                     # but strings, for SQL:datetime.
-                    
-                    
-                    if column in StatisticsDB.DATES:   
-                        #print "GET ATTR : " + `type(getattr(stats,attr))`              
       
-                        if isinstance(value,datetime.datetime):
-                            setattr(stats,attr,value)
+
+                    if column in StatisticsDB.DATES:
+                        #print "GET ATTR : " + `type(getattr(stats,attr))`
+                        if isinstance(value, datetime.datetime):
+                            setattr(stats, attr, value)
                         else:
                             if not value == '0000-00-00 00:00:00':
-                                setattr(stats,attr,
-                                    datetime.datetime.fromtimestamp(time.mktime(time.strptime(value,
-                                                                                '%Y-%m-%d
%H:%M:%S'))))
-                    else:    
-                        setattr(stats,attr,value)
-        
-    def _putBaseStats(self,stats,column_name): 
+                                setattr(stats, attr,
+                                        datetime.datetime\
+                                            .fromtimestamp(\
+                                        time.mktime(time.strptime(value,
+                                                                  '%Y-%m-%d %H:%M:%S'))))
+                    else:
+                        setattr(stats, attr, value)
+
+    def _putBaseStats(self, stats, column_name): 
         """
         Return a dictionary of the named values
         """
-        settings=dict()
-        
+        settings = dict()
+
         settings[column_name] = "'" + stats.name + "'"
-        
+
         for (attr, column) in StatisticsDB.ATTR_COLUMN_MAP.items():
-            if hasattr(stats,attr):
-                value = getattr(stats,attr)
+            if hasattr(stats, attr):
+                value = getattr(stats, attr)
                 if value:
-                    if column in StatisticsDB.DATES:   
+                    if column in StatisticsDB.DATES:
                         #print "SET ATTR : " + `value` 
-                        settings[column] = "'" + value.strftime('%Y-%m-%d %H:%M:%S') + "'"
+                        settings[column] = "'" +\
+                            value.strftime('%Y-%m-%d %H:%M:%S') + "'"
                     elif isinstance(value,types.StringTypes):
                         settings[column] = "'" + str(value) + "'"
                     else:
                         settings[column] = str(value)
-                
+
         return settings
 
-    def sync(self): pass
-    
+    def sync(self):
+        pass
+
+    def _with_reconnect_on_error(self, command):
+        """
+        Executes command (passing in a DbHelper instance) and retries
+        it with a new instance if an OperationalError occurs
+        """
+        try:
+            return command(self._get_helper())
+        except MySQLdb.OperationalError:
+            log.info("Caught an exception from DB, reconnecting")
+            self._helper = None
+            return command(self._get_helper())
+
 if __name__ == '__main__':
     import logging
-    
+
     # init logging
     logging.basicConfig()
 
     #set verbosity to show all messages of severity >= default.logLevel
     log.setLevel(logging.DEBUG)
-    
-    stats=StatisticsDB()
-    
+
+    stats = StatisticsDB()
+
     # Project
-    ps=stats.getProjectStats('test')
-    ps.successes+=1
-    ps.first=getLocalNow()
-    stats.putProjectStats(ps)     
+    ps = stats.getProjectStats('test')
+    ps.successes += 1
+    ps.first = getLocalNow()
+    stats.putProjectStats(ps)
     if len(sys.argv) > 1:
         stats.delProjectStats(ps)
     print "Project"
-    ps.dump()    
-    
+    ps.dump()
+
     sys.exit()
-    
+
     # Workspace
-    ws=stats.getWorkspaceStats('test')
-    ws.successes+=1
-    stats.putWorkspaceStats(ws)     
+    ws = stats.getWorkspaceStats('test')
+    ws.successes += 1
+    stats.putWorkspaceStats(ws)
     if len(sys.argv) > 1:
         stats.delWorkspaceStats(ws)
     print "Workspace"
-    ws.dump()    
-    
+    ws.dump()
+
     # Module
-    ms=stats.getModuleStats('test')
-    ms.successes+=1
-    stats.putModuleStats(ms)     
+    ms = stats.getModuleStats('test')
+    ms.successes += 1
+    stats.putModuleStats(ms)
     if len(sys.argv) > 1:
         stats.delModuleStats(ms)
     print "Module"
     ms.dump()
-          
+
     # Repository
-    rs=stats.getRepositoryStats('test')
-    rs.successes+=1
-    stats.putRepositoryStats(rs)     
+    rs = stats.getRepositoryStats('test')
+    rs.successes += 1
+    stats.putRepositoryStats(rs)
     if len(sys.argv) > 1:
         stats.delRepositoryStats(rs)
     print "Repository"
     rs.dump()
-          
+

Modified: gump/live/python/gump/util/mysql.py
URL: http://svn.apache.org/viewvc/gump/live/python/gump/util/mysql.py?rev=813663&r1=813662&r2=813663&view=diff
==============================================================================
--- gump/live/python/gump/util/mysql.py (original)
+++ gump/live/python/gump/util/mysql.py Fri Sep 11 04:20:11 2009
@@ -17,7 +17,7 @@
 """
 
     MySQL Statistics gathering/manipulation
-    
+
 """
 
 import types
@@ -30,29 +30,29 @@
     """
     Very simple database abstraction layer, basically adding some utilities
     around MySQLdb and ability to parse the gump DatabaseInformation object.
-    
+
     See http://www.python.org/peps/pep-0249.html for more on python and databases.
     This class adheres to the PEP 249 Connection interface.
     """
-    def __init__(self,dbInfo):
-        self._dbInfo=dbInfo
-        self._conn=None
-        
+    def __init__(self, dbInfo):
+        self._dbInfo = dbInfo
+        self._conn = None
+
     def __del__(self):
         self.close()
-    
+
     def commit(self):
         """
         See PEP 249.
         """
         pass
-    
+
     def rollback(self):
         """
         See PEP 249.
         """
         pass
-    
+
     def cursor(self):
         """
         See PEP 249.
@@ -65,191 +65,204 @@
         """
         if self._conn:
             self._conn.close()
-            self._conn=None
+            self._conn = None
 
     def execute(self, statement):
         """
         Simple helper method to execute SQL statements that isolates its users
         from cursor handling.
-        
+
         Pass in any SQL command. Retrieve back the results of having a cursor
         execute that command (normally the number of affected rows).
         """
         cursor = None
         try:
             cursor = self._connection().cursor()
-            result = cursor.execute(cmd)
+            result = cursor.execute(statement)
             return result
         finally:
-            if cursor: cursor.close()
-    
+            if cursor:
+                cursor.close()
+
     def _connection(self):
         """
         Get a connection to the actual database, setting one up if neccessary.
         """
         if not self._conn:
             self._conn = MySQLdb.Connect(
-                    host=self._dbInfo.getHost(), 
-                    user=self._dbInfo.getUser(),
-                    passwd=self._dbInfo.getPasswd(), 
-                    db=self._dbInfo.getDatabase(),
-                    compress=1,
-                    cursorclass=MySQLdb.cursors.DictCursor)
-        
+                    host = self._dbInfo.getHost(), 
+                    user = self._dbInfo.getUser(),
+                    passwd = self._dbInfo.getPasswd(), 
+                    db = self._dbInfo.getDatabase(),
+                    compress = 1,
+                    cursorclass = MySQLdb.cursors.DictCursor)
+
         return self._conn
 
 class DbHelper:
     """
-    	MySQL Statistics Database Helper
+        MySQL Statistics Database Helper
     """
 
-    def __init__(self,conn,database='gump'):
-        self.conn=conn
-        self.database=database
-        
+    def __init__(self, conn, database = 'gump'):
+        self.conn = conn
+        self.database = database
+
     def __del__(self):
         if self.conn:
             self.conn.close()
-            self.conn=None
-            
-    def value(self,value):
+            self.conn = None
+
+    def value(self, value):
         """
         Escape and Quote a Value
         """
         escaped_encoded = ''
-        
-        if isinstance(value,types.StringTypes):
+
+        if isinstance(value, types.StringTypes):
             escaped_encoded = "'" 
-            escaped_encoded += MySQLdb.escape_string(value).replace("\\","\\\\").replace("'","\\'")
-            escaped_encoded += "'"            
+            escaped_encoded += MySQLdb.escape_string(value)\
+                .replace("\\","\\\\").replace("'","\\'")
+            escaped_encoded += "'"
         else:
             escaped_encoded = value
-            
+
         return escaped_encoded
  
-    def generateSelect(self,table_name,column_name,entity_name):
+    def generateSelect(self, table_name, column_name, entity_name):
         """
         Generate a select statement, index is a single name
         """ 
-        statement="SELECT * FROM %s.%s WHERE %s='%s'" % (self.database, table_name, column_name,
entity_name) 
+        statement = "SELECT * FROM %s.%s WHERE %s='%s'" \
+            % (self.database, table_name, column_name, entity_name) 
         return statement
-        
-    def select(self,table_name,column_name,entity_name,columns):
-        statement=self.generateSelect(table_name,column_name,entity_name)
+
+    def select(self, table_name, column_name, entity_name, columns):
+        statement = self.generateSelect(table_name, column_name, entity_name)
         settings = {}
         cursor = None
         try:
             try:
                 cursor = self.conn.cursor()
                 log.debug('SQL: ' + statement)
-                affected=cursor.execute(statement)
+                affected = cursor.execute(statement)
                 log.debug('SQL affected: ' + `affected`)
-            
+
                 if affected > 0: # might be nothing in db yet
                     row = cursor.fetchall()[0] # Ought be only one...
-          
+
                     # Extract values
                     for column in columns:
                         if row.has_key(column) and row[column]:
-                            settings[column]=row[column]
+                            settings[column] = row[column]
                             #print 'Extracted %s -> %s' % ( column, row[column])
-                              
+
             except Exception, details:
-                if cursor: self.logWarnings(cursor)
-                log.error('SQL Error on [%s] : %s' % (statement, details), exc_info=1)  
             
+                if cursor:
+                    self.logWarnings(cursor)
+                log.error('SQL Error on [%s] : %s' % (statement, details),
+                          exc_info = 1)
                 raise
         finally:
-            if cursor: cursor.close()         
+            if cursor:
+                cursor.close()
 
         return settings
 
-    def set(self,table_name,column_name,entity_name,settings):
-        
+    def set(self, table_name, column_name, entity_name, settings):
+
         # Unfortunately affected is returning 0 even when
         # there is a match.
-        
+
         # Attempt an update (and ensure we affected something)
         #updated=(self.update(table_name,column_name,entity_name,settings) > 0)
-            
+
         #if not updated:
         #   # Attempt an insert if not update occured (i.e no match)
         #    self.insert(table_name,settings)
-        
+
         # Gak -- but see above.
-        self.delete(table_name,column_name,entity_name)
-        self.insert(table_name,settings)
-            
+        self.delete(table_name, column_name, entity_name)
+        self.insert(table_name, settings)
+
         return
-            
-    def generateInsert(self,table_name,settings): 
+
+    def generateInsert(self, table_name, settings): 
         """ 
         Perform an SQL INSERT 
         """
         statement = "INSERT INTO %s.%s (" % (self.database, table_name)
-        keys=settings.keys()
+        keys = settings.keys()
         statement += ", ".join(keys)
         statement += ") VALUES ("
         statement += ", ".join([str(settings[key]) for key in keys])
         statement += ")"
         return statement
-        
-    def insert(self,table_name,settings): 
-        """       
+
+    def insert(self, table_name, settings): 
+        """
         Take a dictionary of settings (column names/types) and 
-        perform an insert.        
+        perform an insert.
         """
-        statement=self.generateInsert(table_name,settings)
+        statement = self.generateInsert(table_name, settings)
         affected = 0
         cursor = None
         try:
             try:
                 cursor = self.conn.cursor()
                 log.debug('SQL: ' + statement)
-                affected = cursor.execute(statement)   
-                log.debug('SQL Affected: ' + `affected`)                        
+                affected = cursor.execute(statement)
+                log.debug('SQL Affected: ' + `affected`)
             except Exception, details:
-                if cursor: self.logWarnings(cursor)    
-                log.error('SQL Error on [%s] : %s' % (statement, details), exc_info=1)
+                if cursor:
+                    self.logWarnings(cursor)
+                log.error('SQL Error on [%s] : %s' % (statement, details),
+                          exc_info = 1)
                 raise
         finally:
-            if cursor: cursor.close() 
+            if cursor:
+                cursor.close() 
         return affected 
 
-    def generateUpdate(self,table_name,column_name,entity_name,settings): 
-        """   
+    def generateUpdate(self, table_name, column_name, entity_name, settings): 
+        """
         Take a dictionary of settings (column names/types) and 
-        generate an update statement. Note: The index is a single name.        
+        generate an update statement. Note: The index is a single name.
         """
         statement = "UPDATE %s.%s SET " % (self.database, table_name)
-        keys=settings.keys()
+        keys = settings.keys()
         keys.remove(column_name)
         statement += ", ".join([key + '=' + str(settings[key]) for key in keys])
         statement += " WHERE %s='%s'" % (column_name, entity_name)
         return statement
-            
-    def update(self,table_name,column_name,entity_name,settings): 
-        """   
+
+    def update(self, table_name, column_name, entity_name, settings): 
+        """
         Take a dictionary of settings (column names/types) and 
-        perform an update. Note: The index is a single name.        
+        perform an update. Note: The index is a single name.
         """
-        statement = self.generateUpdate(table_name,column_name,entity_name,settings)
+        statement = self.generateUpdate(table_name, column_name, entity_name,
+                                        settings)
         affected = 0
         cursor = None
         try:
             try:
                 cursor = self.conn.cursor()
                 log.debug('SQL: ' + statement)
-                affected = cursor.execute(statement)  
+                affected = cursor.execute(statement)
                 log.debug('SQL Affected: ' + `affected` + ':' + `result`)
             except Exception, details:
-                if cursor: self.logWarnings(cursor)    
-                log.error('SQL Error on [%s] : %s' % (statement, details), exc_info=1)
-                raise              
+                if cursor:
+                    self.logWarnings(cursor)
+                log.error('SQL Error on [%s] : %s' % (statement, details),
+                          exc_info = 1)
+                raise
         finally:
-            if cursor: cursor.close() 
+            if cursor:
+                cursor.close() 
         return affected 
 
-    def generateDelete(self,table_name,column_name,entity_name):       
+    def generateDelete(self, table_name, column_name, entity_name):
         """ 
         Perform an SQL DELETE 
         Index is single name
@@ -258,30 +271,33 @@
                         % (self.database, table_name, column_name, entity_name)
         return statement
 
-    def delete(self,table_name,column_name,entity_name):       
+    def delete(self, table_name, column_name, entity_name):
         """ 
         Perform an SQL DELETE 
         Index is single name
         """
-        statement = self.generateDelete(table_name,column_name, entity_name)
+        statement = self.generateDelete(table_name, column_name, entity_name)
         affected = 0
         cursor = None
         try:
             try:
                 cursor = self.conn.cursor()
                 log.debug('SQL: ' + statement)
-                affected = cursor.execute(statement)       
-                log.debug('SQL Affected: ' + `affected`)              
+                affected = cursor.execute(statement)
+                log.debug('SQL Affected: ' + `affected`)
             except Exception, details:
-                if cursor: self.logWarnings(cursor)    
-                log.error('SQL Error on [%s] : %s' % (statement, details), exc_info=1)
-                raise                
+                if cursor:
+                    self.logWarnings(cursor)
+                log.error('SQL Error on [%s] : %s' % (statement, details),
+                          exc_info = 1)
+                raise
         finally:
-            if cursor: cursor.close()     
+            if cursor:
+                cursor.close()
         return affected 
-        
-    def logWarnings(self,cursor):
+
+    def logWarnings(self, cursor):
         if cursor.messages:
             for (message, details) in cursor.messages:
                 log.warning('SQL Warning:' + str(message) + ':' + str(details))
-            
+



Mime
View raw message