gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r812817 - /gump/trunk/python/gump/actor/stats/mysql/statsdb.py
Date Wed, 09 Sep 2009 08:25:13 GMT
Author: bodewig
Date: Wed Sep  9 08:25:12 2009
New Revision: 812817

URL: http://svn.apache.org/viewvc?rev=812817&view=rev
Log:
pylint

Modified:
    gump/trunk/python/gump/actor/stats/mysql/statsdb.py

Modified: gump/trunk/python/gump/actor/stats/mysql/statsdb.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/actor/stats/mysql/statsdb.py?rev=812817&r1=812816&r2=812817&view=diff
==============================================================================
--- gump/trunk/python/gump/actor/stats/mysql/statsdb.py (original)
+++ gump/trunk/python/gump/actor/stats/mysql/statsdb.py Wed Sep  9 08:25:12 2009
@@ -17,266 +17,273 @@
 """
 
     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.conn = MySQLdb.Connect(
+            host = dbInfo.getHost(), 
+            user = dbInfo.getUser(),
+            passwd = dbInfo.getPasswd(), 
+            db = 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(self.conn, dbInfo.getDatabase())
  
     # 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.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.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.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
+
 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()
-          
+



Mime
View raw message