gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r123739 - in gump/branches/Dec04MajorCleanup/pygump/python/gump: . actor test util
Date Thu, 30 Dec 2004 22:45:29 GMT
Author: leosimons
Date: Thu Dec 30 14:45:28 2004
New Revision: 123739

URL: http://svn.apache.org/viewcvs?view=rev&rev=123739
Log:
* were just a few bits left to delete
* homogenic license header
Modified:
   gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py
   gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/__init__.py	Thu Dec 30 14:45:28 2004
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,18 +14,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-__copyright__ = "Copyright (c) 2003-2004 Apache Software Foundation"
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
-
-import os
-
-import logging
-import logging.config
-
-_gumphome = os.environ["GUMP_HOME"]
-
-# configure the logger
-logging.config.fileConfig(_gumphome + "/pygump/gump.log.config")
-
-# base gump logger
-log = logging.getLogger("root")

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/__init__.py	Thu Dec 30 14:45:28
2004
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,5 +14,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-__copyright__ = "Copyright (c) 2003-2004 Apache Software Foundation"
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/actor/dynagumper.py	Thu Dec 30 14:45:28
2004
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-__copyright__ = "Copyright (c) 2004 The Apache Software Foundation"
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 import platform

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/test/__init__.py	Thu Dec 30 14:45:28
2004
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 
-#!/usr/bin/env python
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -15,3 +14,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/test/mockobjects.py	Thu Dec 30 14:45:28
2004
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-__copyright__ = "Copyright (c) 2004 The Apache Software Foundation"
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 class MockLog:

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testDynagumper.py	Thu Dec 30 14:45:28
2004
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-__copyright__ = "Copyright (c) 2004 The Apache Software Foundation"
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 import unittest

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/test/testExample.py	Thu Dec 30 14:45:28
2004
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,6 +13,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 """
     This is an example of a testcase. Simply copy and rename this file

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/util/__init__.py	Thu Dec 30 14:45:28
2004
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 
-
-# Copyright 2003-2004 The Apache Software Foundation
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -15,370 +14,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
-"""
-    Helper Stuff
-"""
-
-import logging
-import os
-import sys
-import types, StringIO
-import time
-import urllib
-
-from gump import log
-from gump.core.config import default, setting
-
-def banner():
+def banner(version):
     print "      _____"
     print "     |   __|_ Apache_ ___"
     print "     |  |  | | |     | . |"
     print "     |_____|___|_|_|_|  _|"
-    print "                     |_|     ~ v. " + setting.VERSION + " ~"
+    print "                     |_|     ~ v. " + version + " ~"
     print
-
-def gumpSafeName(name):
-  """returns a file system safe name"""  
-  return urllib.quote_plus(name)
-
-def getModule(modulePath):
-    try:
-        aMod = sys.modules[modulePath]
-        if not isinstance(aMod, types.ModuleType):
-            raise KeyError
-    except KeyError:
-        # The last [''] is very important!
-        aMod = __import__(modulePath, globals(), locals(), [''])
-        sys.modules[modulePath] = aMod
-    return aMod
-    
-def dump(obj,indent="",visited=None):
-    
-    print indent+"Object: ["+str(obj.__class__)+"] "+str(obj)
-    
-    if not visited:
-        visited=[]
-    if obj in visited: return
-    visited.append(obj)
-    
-    if not obj: return
-    if isinstance(obj,types.TypeType): return
-    if isinstance(obj,types.MethodType): return
-    
-      
-    # iterate over the own properties
-    try:
-      for name in obj.__dict__:
-        if name.startswith('__') and name.endswith('__'): continue
-        var=obj.__dict__[name]
-
-        # avoid nulls, metadata, and methods
-        if type(var) == types.NoneType: continue
-        if isinstance(var,types.TypeType): continue
-        if isinstance(var,types.MethodType): continue
-
-        if isinstance(var,list): 
-          print indent+"  List Name:" + str(name) + ' len:' + str(len(var))
-          i=0
-          for v in var:
-             i+=1
-             print indent+"  (" + str(i) + ") " + str(name)
-             dump(v, indent+"  ", visited)
-        elif isinstance(var,dict): 
-          print "  Dictionary Name:" + str(name) + " " + str(var.__class__)
-          for (k,v) in var.iteritems():
-             print indent+"    Key:" + str(k) + " " + str(v.__class__)
-             dump(v,indent+"  ", visited)
-        elif isinstance(var,object) and not isinstance(var,str): 
-          print indent+"  Object Name:" + str(name) + " " + str(var.__class__)
-          if not 'owner' == str(name):
-              dump(var,indent+"  ", visited)
-        else:
-          try:
-            print indent+"  " + str(name) + " :-> " + str(var)
-          except:
-            print indent+"  " + str(name) + " :-> Unprintable (non-ASCII) Characters"
-    except:
-        pass
-   
-def display(obj):
-    print str(obj.__class__)
-    # iterate over the own properties
-    for name in obj.__dict__:
-      if name.startswith('__') and name.endswith('__'): continue
-      var=obj.__dict__[name]
-
-      # avoid nulls, metadata, and methods
-      if not var: continue
-      if isinstance(var,types.TypeType): continue
-      if isinstance(var,types.MethodType): continue
-
-      if isinstance(var,list): 
-        print "  List Name:" + str(name) + " " + str(var.__class__)
-        for v in var:
-            display(v)
-      elif isinstance(var,dict): 
-        print "  Dictionary Name:" + str(name) + " " + str(var.__class__)
-        for (k,v) in var.iteritems():
-            display(v)
-      else:
-        try:
-          print "  " + str(name) + " :-> " + str(var)
-        except:
-          print "  " + str(name) + " :-> Unprintable (non-ASCII) Characters"
-                
-class AlphabeticDictionaryIterator:
-    """ Iterate over a dictionary in alphabetic key order """
-    def __init__(self,dict):
-        self.dict=dict
-        self.keys=dict.keys()
-        self.keys.sort()
-        self.iter=iter(self.keys)
-        
-    def __iter__(self):
-        return self
-        
-    def next(self):
-        key=self.iter.next()
-        return self.dict[key]      
-        
-def createOrderedList(disorderedList,sortfunc=None):
-    # Is there a better way to clone a list?    
-    sorted=list(disorderedList)    
-    # Sort it
-    if sortfunc:
-        sorted.sort(sortfunc)
-    else:
-        sorted.sort()        
-    # Return it sorted
-    return sorted   
-    
-def printSeparator(indent=''):
-    printSeparatorToFile(None,indent)
-    
-def printSeparatorToFile(f=None,indent=''):    
-    if not f: f=sys.stdout
-    f.write( '%s\n' % (indent + ' ---------------------------------------------------- Gump'))
-    
-#
-# Get into ASCII, but make an attempt at coping with
-# non-ASCII
-#
-def getStringFromUnicode(u):
-    try:
-        s = str(u)
-    except UnicodeError:
-        s = ''
-        for uc in u:
-            try:
-                sc = uc.encode('latin-1')            
-            except UnicodeError:
-                sc = '_'
-            # Add character by character
-            s += sc
-            
-    return s
-
-def wrapLine(line,wrapLen=100, eol='\n', marker='[WRAPPED]'):
-    
-    wrappedLine=''       
-    #
-    # Provide some wrapping (at ~ 100)
-    #
-    if len(line) > wrapLen:      
-        startPosn=0
-        endPosn=wrapLen
-        increment=wrapLen
-        totalLen=len(line)                         
-        while increment > 0:
-            #print `startPosn` + " : " + `endPosn` + " : (" + `totalLen` + ') : ' + `increment`
-            
-            # Add the piece
-            wrappedLine+=line[startPosn:endPosn+1]
-            
-            # We have more wrappign to do
-            if (totalLen - endPosn) > wrapLen:
-                increment=wrapLen
-            else:
-                increment=(totalLen - endPosn)
-                
-            # We aren't at end
-            if increment:
-                wrappedLine+=eol+marker
-                
-            startPosn=endPosn+1
-            endPosn+=increment
-            #print `startPosn` + " : " + `endPosn` + " : (" + `totalLen` + ') : ' + `increment`
-    else:
-        wrappedLine=line
-            
-    return wrappedLine
-    
-def getIndent(depth=0):
-    indent=''
-    if depth < 0:
-        raise ValueError, 'Can\'t have a negative indent : ' + `depth`
-    if depth > 0:
-        while depth:
-            indent = indent + '  '
-            depth = depth -1
-    return indent
-                  
-def formatException(ei):
-    import traceback
-    sio = StringIO.StringIO()
-    traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
-    s = sio.getvalue()
-    sio.close()
-    if s[-1] == "\n":
-        s = s[:-1]
-    return s
-
-def getBeanAttributes(bean):
-    attributes={}
-    for name in bean.__class__.__dict__:
-        if name.startswith('__') and name.endswith('__'): continue
-        accessor=getattr(bean,name)            
-        # avoid metadata, non-methods, methods other than (is|get)*
-        if isinstance(accessor,types.TypeType): continue
-        # Ignore non-methods
-        if not isinstance(accessor,types.MethodType): continue        
-        # Ignore non-callable methods (????)
-        if not callable(accessor): continue
-        
-        # Ignore methods not isX or getX
-        # :TODO: Ought check that the X is upper case...
-        if name.startswith('get'):
-            attrName=name[3:]
-        elif name.startswith('is'):
-            attrName=name[2:]
-        else:
-            continue
-            
-        # Get value and stash it
-        attributes[attrName]=accessor()   
-            
-    return attributes
-    
-def logResourceUtilization(message=None): pass
-
-# This doesn't appear fully implemented in Python (2.2/2.3) so
-# is simply a waste of cycles to call/display
-
-#    try:
-        #import resource
-        #
-        #if not message:
-        #    message=''
-        #    
-        #myresources=resource.getrusage(resource.RUSAGE_SELF)
-        #
-        ## Extract the pieces
-        #(my_ru_utime, my_ru_stime, my_ru_maxrss, \
-        #    my_ru_ixrss, my_ru_idrss, my_ru_isrss, 	\
-        #    my_ru_minflt, my_ru_majflt, my_ru_nswap, \
-        #    my_ru_inblock, my_ru_oublock, my_ru_msgsnd, \
-        #    my_ru_msgrcv, my_ru_nsignals, my_ru_nvcsw, 	\
-        #    my_ru_nivcsw)=myresources
-#    
-#        kidresources=resource.getrusage(resource.RUSAGE_CHILDREN)
-#        
-#        # Extract the pieces
-#        (kid_ru_utime, kid_ru_stime, kid_ru_maxrss, \
-#            kid_ru_ixrss, kid_ru_idrss, kid_ru_isrss, 	\
-#            kid_ru_minflt, kid_ru_majflt, kid_ru_nswap, \
-#            kid_ru_inblock, kid_ru_oublock, kid_ru_msgsnd, \
-#            kid_ru_msgrcv, kid_ru_nsignals, kid_ru_nvcsw, 	\
-#            kid_ru_nivcsw)=kidresources
-#            
-#        log.debug('My Memory ' + message + ' ' + `my_ru_maxrss`)
-#        log.debug('My Resources ' + message + ' ' + `myresources`)
-#        log.debug('Child Memory ' + message + ' ' + `kid_ru_maxrss`)
-#        log.debug('Child Resources ' + message + ' ' + `kidresources`)        
-#    
-        #resources=resource.getrusage(resource.RUSAGE_BOTH)
-        #log.debug('All Resources ' + message  + ' ' + `resources`)
-        
-#    except Exception, details:        
-#        if not os.name == 'dos' and not os.name == 'nt':
-#            log.error("Failed get resource utilization." \
-#        
-           
-def initializeGarbageCollection():
-    tracked = 0
-    try:
-        import gc
-        enabled = gc.isenabled()
-        threshold = gc.get_threshold()
-        tracked = len(gc.get_objects())        
-    
-        log.debug('GC: Enabled %s : Tracked %s : Threshold %s' \
-                % (`enabled`, `tracked`,`threshold`))
-                
-        gc.enable()
-        gc.set_threshold(10,10,10)
-                
-        # gc.set_debug(gc.DEBUG_LEAK)
-    except:
-        pass  
-    return tracked    
-           
-def inspectGarbageCollection(marker=''):
-    tracked = 0
-    try:
-        import gc
-        tracked = len(gc.get_objects())
-        #message=''
-        #if marker:
-        #    message=' @ '
-        #    message+=marker
-        #log.debug('Objects Tracked by GC %s : %s' \
-        #        % (message,  `tracked`))
-    except:
-        pass  
-    return tracked
-                    
-def invokeGarbageCollection(marker=''):
-    try:
-        # See what GC thinks
-        inspectGarbageCollection(marker)
-        
-        # Perform GC
-        import gc        
-        unreachable = gc.collect()
-        
-        # Curiousity..
-        if unreachable:
-            message='Objects Unreachable by GC : ' + `unreachable`
-            if marker:
-                message+=' @ '
-                message+=marker
-            log.warn(message)
-                        
-        # See what GC thinks afterwards...
-        # inspectGarbageCollection(marker)
-    except:
-        pass
-   
-def getRefCounts():
-    pass
-    #d = {}
-    #sys.modules
-    ## collect all classes
-    #for m in sys.modules.values():
-    #    for sym in dir(m):
-    #        o = getattr (m, sym)
-    #        if type(o) is types.ClassType:
-    #            d[o] = sys.getrefcount (o)
-    ## sort by refcount
-    #pairs = map (lambda x: (x[1],x[0]), d.items())
-    #pairs.sort()
-    #pairs.reverse()
-    #return pairs
-
-def printTopRefs(count,message=None):
-    pass
-    #if message: print 'References @ ', message
-    #for n, c in getRefCounts()[:count]:
-    #    print '%10d %s - %s' % (n, c.__name__, `c`)

Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py?view=diff&rev=123739&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py&r1=123738&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py&r2=123739
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py	(original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/util/mysql.py	Thu Dec 30 14:45:28 2004
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
-# Copyright 2003-2004 The Apache Software Foundation
+
+# Copyright 2004-2005 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,18 +14,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-"""
-
-    MySQL Statistics gathering/manipulation
-    
-"""
+__copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 import types
 import MySQLdb
 import MySQLdb.cursors
 
-from gump import log
-
 class Database:
     """
     Very simple database abstraction layer, basically adding some utilities
@@ -96,190 +92,3 @@
                     cursorclass=MySQLdb.cursors.DictCursor)
         
         return self._conn
-
-class DbHelper:
-    """
-    	MySQL Statistics Database Helper
-    """
-
-    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):
-        """
-        Escape and Quote a Value
-        """
-        escaped_encoded = ''
-        
-        if isinstance(value,types.StringTypes):
-            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):
-        """
-        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) 
-        return statement
-        
-    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)
-                log.debug('SQL affected: ' + `affected`)
-            
-                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]
-                        #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)  
             
-                raise
-        finally:
-            if cursor: cursor.close()         
-
-        return 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)
-            
-        return
-            
-    def generateInsert(self,table_name,settings): 
-        """ 
-        Perform an SQL INSERT 
-        """
-        statement = "INSERT INTO %s.%s (" % (self.database, table_name)
-        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): 
-        """       
-        Take a dictionary of settings (column names/types) and 
-        perform an insert.        
-        """
-        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`)                        
-            except Exception, details:
-                if cursor: self.logWarnings(cursor)    
-                log.error('SQL Error on [%s] : %s' % (statement, details), exc_info=1)
-                raise
-        finally:
-            if cursor: cursor.close() 
-        return affected 
-
-    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.        
-        """
-        statement = "UPDATE %s.%s SET " % (self.database, table_name)
-        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): 
-        """   
-        Take a dictionary of settings (column names/types) and 
-        perform an update. Note: The index is a single name.        
-        """
-        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)  
-                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              
-        finally:
-            if cursor: cursor.close() 
-        return affected 
-
-    def generateDelete(self,table_name,column_name,entity_name):       
-        """ 
-        Perform an SQL DELETE 
-        Index is single name
-        """
-        statement = "DELETE FROM %s.%s WHERE %s='%s'" \
-                        % (self.database, table_name, column_name, entity_name)
-        return statement
-
-    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)
-        affected = 0
-        cursor = None
-        try:
-            try:
-                cursor = self.conn.cursor()
-                log.debug('SQL: ' + statement)
-                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                
-        finally:
-            if cursor: cursor.close()     
-        return affected 
-        
-    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