You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@gump.apache.org by aj...@apache.org on 2004/06/20 21:36:55 UTC

cvs commit: gump/python/gump/utils owner.py

ajack       2004/06/20 12:36:55

  Modified:    python   Tag: CleanUp .cvsignore
               python/gump/document/xdocs Tag: CleanUp xdoc.py
                        documenter.py
               python/gump/loader Tag: CleanUp loader.py
               python/gump/core Tag: CleanUp gumpenv.py
               python/gump/utils Tag: CleanUp owner.py
  Added:       python/gump/performance Tag: CleanUp __init__.py xdocs.py
                        .cvsignore
  Log:
  Running 'documentation' (to xdocs) in a loop to performance
  tune, leak detect, etc. This is the result, trimmed down &
  hopefully fast(er).
  
   If this doesn't do it, maybe need to go
  out and re-implemented XML generation reverse-SAX-like
  not reverse-DOM-like.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.10.4.3  +1 -1      gump/python/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/gump/python/.cvsignore,v
  retrieving revision 1.10.4.2
  retrieving revision 1.10.4.3
  diff -u -r1.10.4.2 -r1.10.4.3
  --- .cvsignore	14 Jun 2004 21:31:46 -0000	1.10.4.2
  +++ .cvsignore	20 Jun 2004 19:36:54 -0000	1.10.4.3
  @@ -13,7 +13,7 @@
   work
   test
   tmp
  -x.txt
  +x.*
   build
   *.log
   bogus
  
  
  
  No                   revision
  No                   revision
  1.2.2.9   +20 -80    gump/python/gump/document/xdocs/xdoc.py
  
  Index: xdoc.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/document/xdocs/xdoc.py,v
  retrieving revision 1.2.2.8
  retrieving revision 1.2.2.9
  diff -u -r1.2.2.8 -r1.2.2.9
  --- xdoc.py	18 Jun 2004 14:58:16 -0000	1.2.2.8
  +++ xdoc.py	20 Jun 2004 19:36:54 -0000	1.2.2.9
  @@ -33,7 +33,6 @@
   
   from gump import log
   from gump.utils import *
  -from gump.utils.owner import *
   
   #
   # MAP anything outside 32..128 to _
  @@ -54,10 +53,8 @@
   STRING_MAP_TABLE=''.join(MAP)
   UNICODE_MAP_TABLE=unicode('').join(UMAP)
   
  -class XDocContext(Ownable):
  -    def __init__(self,stream=None,pretty=True,depth=0):        
  -        Ownable.__init__(self)
  -        
  +class XDocContext:
  +    def __init__(self,stream=None,pretty=False,depth=0):  
           self.depth=depth
           self.pretty=pretty
           
  @@ -66,11 +63,7 @@
           else:
               log.debug('Create transient stream ['+`self.depth`+']...')
               self.stream=StringIO.StringIO()
  -                    	
  -    def __del__(self):  
  -        Ownable.__del__(self)
  -        self.stream=None  
  -        
  +                
       def createSubContext(self,transient=False):
           if not transient:
               # sub = XDocContext(self.stream,self.pretty,self.depth+1)
  @@ -78,7 +71,6 @@
               sub = self
           else:              
               sub = XDocContext(None,self.pretty,self.depth+1)
  -            sub.setOwner(self)
           return sub
       
       def performIO(self,stuff):
  @@ -86,7 +78,6 @@
               self.stream.write(stuff)
           except Exception, details:
               log.error('Failed to write [' + stuff + '] @ ['+`self.depth`+'] : ' + str(details))
  -            self.displayOwnership()
               raise
               
       def writeIndented(self,xdoc):
  @@ -154,30 +145,15 @@
               return escape(raw.translate(UNICODE_MAP_TABLE))
           return escape(raw.translate(STRING_MAP_TABLE))
           
  -class XDocPiece(Ownable):
  +class XDocPiece:
       def __init__(self,context=None,config=None,style=None):
  -        Ownable.__init__(self)            
  -        if not context:
  -            context=XDocContext()
  -            
  -        # Stream context...
  +        if not context: context=XDocContext()
           self.context=context
  -        
  -        # 
  +        self.config=config
           self.subpieces=None
  -        
           self.style=style
  +        self.keeper=True      
           
  -        self.keeper=True
  -        self.emptyOk=False        
  -        
  -        self.config=config
  -        
  -    def __del__(self):
  -        Ownable.__del__(self)
  -        self.subpieces=None        
  -        self.context=None
  -                
       def __repr__(self):
           return self.__class__.__name__
           
  @@ -197,14 +173,10 @@
               
           self.subpieces.append(piece)
           
  -        # Capture Ownership
  -        piece.setOwner(self)
  -        
           return piece
   
       def serialize(self):
  -        
  -        if self.isKeeper(): 
  +        if self.keeper: 
               self.callStart()        
               self.middle()
               self.callEnd()
  @@ -215,15 +187,14 @@
               piece.start()
               
       def middle(self):
  -        if not self.subpieces and not self.isEmptyOk():
  +        if not self.subpieces:
               log.warn('Empty [' + `self.__class__` + '] probably isn\'t good...')
  -            self.displayOwnership()
               
           for sub in self.subpieces:
               sub.serialize()
               
               # Gather 
  -            if sub.isTransient() and sub.isKeeper():
  +            if sub.isTransient() and sub.keeper:
                   self.context.writeContext(sub.context)
   
       def callEnd(self,piece=None):
  @@ -246,26 +217,6 @@
       def isKeeper(self):
           return self.keeper
           
  -    def setEmptyOk(self, ok):
  -        self.emptyOk=ok
  -        
  -    def isEmptyOk(self):
  -        return self.emptyOk
  -        
  -    def unlink(self):
  -        # Unlink subpieces...
  -        if self.subpieces:
  -            for subpiece in self.subpieces:
  -                subpiece.unlink()
  -        
  -        # Then destroy the list
  -        self.subpieces=None
  -        
  -        self.context=None
  -        
  -        # Unlink oneself
  -        self.setOwner(None)
  -        
       def setStyle(self,style):
           self.style=style
           
  @@ -434,7 +385,7 @@
           XDocPiece.__init__(self,context,config)
           if text:
               self.createText(text)
  -        
  +            
       def start(self):
           self.context.writeIndented('<li>')
           
  @@ -539,10 +490,7 @@
           XDocPiece.__init__(self,context,config)
           if not isinstance(text,NoneType):
               self.createText(str(text))
  -        
  -        # Empty (no data) 'ok'
  -        # self.setEmptyOk(1)
  -        
  +            
       def start(self):
           self.context.writeIndented('<td' + self.getStyleAttribute() + '>')
           
  @@ -575,7 +523,7 @@
           XDocPiece.__init__(self,context,config)
           if text:
               self.createText(text)
  -              
  +            
       def start(self):
           if self.config.isXhtml():    
               self.context.writeLineIndented('<table><tr><td class="WARN"><p>')
  @@ -667,7 +615,7 @@
           self.href=href
           if text: 
               self.createText(text)
  -        
  +            
       def start(self):
           if not self.config.isXhtml():    
               self.context.write('<link href=\'' + escape(self.href) + '\'>')
  @@ -742,15 +690,11 @@
   class XDocText(XDocPiece):
       def __init__(self,context,config,text):
           XDocPiece.__init__(self,context,config)
  -        self.text = text
  +        self.text = text      
           
       def middle(self):
           self.context.writeRaw(self.text)
           
  -    def unlink(self):
  -        XDocPiece.unlink(self)             
  -        self.text=None
  -        
   #       
   # Some raw xdocs (for when too lazy to create classes)
   #
  @@ -765,19 +709,19 @@
   class XDocDocument(XDocPiece):
       
       def __init__(self,title,output=None,config=None,rootpath='.'):
  -        XDocPiece.__init__(self,config=config)  
           if isinstance(output,types.StringTypes):    
               self.xfile=output
  -            log.debug("Documenting to file : [" + self.xfile + "] " + `self.config`)                    
  +            log.debug('Documenting to file : [' + self.xfile + ']')                    
               # Open for writing with a decent sized buffer.
               self.output=open(self.xfile, 'w', 4096)
           else:
               self.output=output        
  -        self.context=XDocContext(self.output)
  +        XDocPiece.__init__(self,XDocContext(self.output),config)  
  +        
           self.title=title
           self.rootpath=rootpath
           # :DEV: if not self.rootpath: raise RuntimeError, 'Bad rootpath'
  -                
  +        
       def start(self):
           
           if self.config.isXhtml():
  @@ -831,12 +775,8 @@
               self.context.writeLine('</html>')            
           self.close()  
           
  -        # Probably ought do this higher up
  -        self.unlink()
  -        
  -        log.debug('Closed Documenting')                    
  +        log.debug('Closed Document.')                    
               
  -
       def createSection(self,title,transient=False):
           return self.storePiece(XDocSection(self.createSubContext(transient),self.config,title))
                   
  
  
  
  1.9.2.18  +4 -3      gump/python/gump/document/xdocs/documenter.py
  
  Index: documenter.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/document/xdocs/documenter.py,v
  retrieving revision 1.9.2.17
  retrieving revision 1.9.2.18
  diff -u -r1.9.2.17 -r1.9.2.18
  --- documenter.py	18 Jun 2004 22:02:21 -0000	1.9.2.17
  +++ documenter.py	20 Jun 2004 19:36:54 -0000	1.9.2.18
  @@ -407,9 +407,10 @@
           javaTable=javaSection.createTable()
           javaTable.createEntry('Java Command', self.run.getEnvironment().javaCommand)
           javaproperties=self.run.getEnvironment().getJavaProperties()
  -        for name in ['java.vendor', 'java.version', 'os.name', 'os.arch', 'os.version']:
  -            if name in javaproperties:
  -                javaTable.createEntry(name, javaproperties[name])	  
  +        if javaproperties:
  +            for name in ['java.vendor', 'java.version', 'os.name', 'os.arch', 'os.version']:
  +                if name in javaproperties:
  +                    javaTable.createEntry(name, javaproperties[name])	  
                               
           self.documentSummary(document,self.workspace.getProjectSummary())        
           self.documentAnnotations(document,self.run)
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +20 -0     gump/python/gump/performance/Attic/__init__.py
  
  
  
  
  1.1.2.1   +68 -0     gump/python/gump/performance/Attic/xdocs.py
  
  
  
  
  1.1.2.1   +1 -0      gump/python/gump/performance/Attic/.cvsignore
  
  
  
  
  No                   revision
  No                   revision
  1.1.2.6   +4 -0      gump/python/gump/loader/Attic/loader.py
  
  Index: loader.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/loader/Attic/loader.py,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- loader.py	14 Jun 2004 21:31:47 -0000	1.1.2.5
  +++ loader.py	20 Jun 2004 19:36:54 -0000	1.1.2.6
  @@ -78,6 +78,10 @@
           # pieces of text (just text as one value)
           dom.normalize()
           
  +        # :TODO:: Hmm, do we want to remove empty text? Might be
  +        # nicer for presentation. Seems (somehow) we get extra <CR>
  +        # with them (when we ask for XML pretty).
  +        
           # Do tag validation (if requested)        
           xtag=dom.documentElement.tagName
           if tag:
  
  
  
  No                   revision
  No                   revision
  1.6.2.4   +5 -2      gump/python/gump/core/gumpenv.py
  
  Index: gumpenv.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/core/gumpenv.py,v
  retrieving revision 1.6.2.3
  retrieving revision 1.6.2.4
  diff -u -r1.6.2.3 -r1.6.2.4
  --- gumpenv.py	16 Jun 2004 17:50:40 -0000	1.6.2.3
  +++ gumpenv.py	20 Jun 2004 19:36:54 -0000	1.6.2.4
  @@ -23,6 +23,7 @@
   
   import os.path
   import sys
  +from types import NoneType
   from fnmatch import fnmatch
   
   from gump import log
  @@ -189,7 +190,7 @@
           self.changeState(STATE_SUCCESS)
       
       def getJavaProperties(self):
  -        if self.javaProperties: return self.javaProperties
  +        if not self.javaProperties is NoneType: return self.javaProperties
   
           self.checkEnvironment()
           
  @@ -221,7 +222,9 @@
           cmd=self.javaCommand + ' -cp ' + dir.tmp + ' sysprop'
           self.javaProperties = \
   	    dict(re.findall('(.*?): (.*)', commands.getoutput(cmd)))
  -        os.unlink(JAVA_SOURCE.replace('.java','.class'))
  +        JAVA_CLASS=JAVA_SOURCE.replace('.java','.class')
  +        if os.path.exists(JAVA_CLASS):
  +            os.unlink(JAVA_CLASS)
   
           for (name,value) in self.javaProperties.items():
               log.debug("Java Property: " + name + " => " + value)
  
  
  
  No                   revision
  No                   revision
  1.4.4.2   +3 -1      gump/python/gump/utils/owner.py
  
  Index: owner.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/utils/owner.py,v
  retrieving revision 1.4.4.1
  retrieving revision 1.4.4.2
  diff -u -r1.4.4.1 -r1.4.4.2
  --- owner.py	8 Jun 2004 21:36:36 -0000	1.4.4.1
  +++ owner.py	20 Jun 2004 19:36:54 -0000	1.4.4.2
  @@ -24,7 +24,9 @@
   class Ownable:
       """Contains ownership """
       def __init__(self,owner=None):
  -        self.setOwner(owner)
  +        if self == owner:
  +            raise RuntimeError, "Can set owner to self on " + `self`
  +        self.owner=owner
       
       def __del__(self):
           self.owner=None
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@gump.apache.org
For additional commands, e-mail: general-help@gump.apache.org