gump-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: jakarta-gump/python gumpcore.py
Date Sat, 26 Apr 2003 08:54:09 GMT
nicolaken    2003/04/26 01:54:09

  Modified:    python   gumpcore.py
  Log:
  Fix line endings -secong pass-
  
  Revision  Changes    Path
  1.9       +112 -62   jakarta-gump/python/gumpcore.py
  
  Index: gumpcore.py
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/python/gumpcore.py,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- gumpcore.py	26 Apr 2003 08:46:19 -0000	1.8
  +++ gumpcore.py	26 Apr 2003 08:54:09 -0000	1.9
  @@ -1,6 +1,17 @@
   #!/usr/bin/python
   """
  -	Gump core functionality. It contains a sax dispatcher tool, a dependency
	walker, and
an object model (GOM) which is built from an xmlfile using
	the sax dispatcher.

    The idea
is that a subclass of GumpBase is used for each of the various
    xml tags which can appear
in a gump profile, with a saxdispatcher
    generating a tree of GumpBase objects from the
profile, dynamically
    merging as it finds href references.

    You can then use the dependencies()
method to get an ordered, flat vector
    of the projects in the profile.
"""
  +	Gump core functionality. It contains a sax dispatcher tool, a dependency
  +	walker, and an object model (GOM) which is built from an xmlfile using
  +	the sax dispatcher.
  +
  +	The idea is that a subclass of GumpBase is used for each of the various
  +	xml tags which can appear in a gump profile, with a saxdispatcher
  +	generating a tree of GumpBase objects from the profile, dynamically
  +	merging as it finds href references.
  +
  +	You can then use the dependencies() method to get an ordered, flat vector
  +	of the projects in the profile.
  +"""
   
   import os.path, os, time, urllib, urlparse, shutil, string, os.path
   from xml.sax import parse
  @@ -11,27 +22,27 @@
   #########################################################################
   #	  SAX Dispatcher Mechanism                                          #
   #########################################################################
  -
  +
   # a stack of active xml elements
   class SAXDispatcher(ContentHandler):
     def __init__(self,file,name,cls):
       self.topOfStack=DocRoot(name,cls)
       self.elementStack=[self.topOfStack]
       parse(file,self)
  -    self.docElement=self.topOfStack.element
  +    self.docElement=self.topOfStack.element
       
     def startElement (self, name, attrs):
       if self.topOfStack: self.topOfStack=self.topOfStack.startElement(name,attrs)
  -    self.elementStack.append(self.topOfStack);
  +    self.elementStack.append(self.topOfStack);
       
     def characters(self, string):
  -    if self.topOfStack: self.topOfStack.characters(string)
  +    if self.topOfStack: self.topOfStack.characters(string)
       
     def endElement (self, name):
       del self.elementStack[-1]
       self.topOfStack=self.elementStack[-1]
   
  -# Run a file through a saxdispatcher, building a GOM in memory from
  +# Run a file through a saxdispatcher, building a GOM in memory from
   # the xml file. Return the generated GOM
   def load(file):
     if not os.path.exists(file):
  @@ -53,21 +64,30 @@
   
   #########################################################################
   #		  Base classes for the Gump object model		#
  -#                                                                       #
# This is actually
where most of the logic and complexity is handled,   #
# allowing the actual model to be rather
simple and compact. All        #
# elements of the GOM should extend GumpBase or a subclass
of GumpBase. #
  +#                                                                       #
  +# This is actually where most of the logic and complexity is handled,   #
  +# allowing the actual model to be rather simple and compact. All        #
  +# elements of the GOM should extend GumpBase or a subclass of GumpBase. #
   #########################################################################
   # Base class for the entire Gump object model.  Attributes become
  -# properties.  Characters become the string value of the element.
#
# An internal attribute
with name '@text' is used for storing all
# the characters (as opposed to xml elements and
xml attributes).
  -class GumpBase(object):
  -  def __init__(self,attrs):
  +# properties.  Characters become the string value of the element.
  +#
  +# An internal attribute with name '@text' is used for storing all
  +# the characters (as opposed to xml elements and xml attributes).
  +class GumpBase(object):
  +  def __init__(self,attrs):
       # parse out '@@DATE@@'
       for (name,value) in attrs.items():
  -      self.__dict__[name]=value.replace('@@DATE@@',default.date)
  -    
  +      self.__dict__[name]=value.replace('@@DATE@@',default.date)
  +      
       # setup internal character field
       if not '@text' in self.__dict__: self.init()
       self.__dict__['@text']=''
  -  
  -  def startElement(self, name, attrs):
    # possibility to customize behaviour based on
   # type of the element
    # TODO: can this difference just go here?
  +  
  +  def startElement(self, name, attrs):
  +    # possibility to customize behaviour based on
  +    # type of the element
  +    # TODO: can this difference just go here?
       try:
         attr=self.__getattribute__(name)
         if isinstance(attr,Single): return attr(attrs)
  @@ -75,33 +95,41 @@
       except:
         # print self.__class__, name
         pass
  -  
  +
  +  
     def characters(self,string):
       self.__dict__['@text']+=string
  -  
  +
  +  
     def __setitem__(self,name,value): 
       self.__dict__[name]=value
  -  
  +
  +  
     def __getitem__(self,name): 
       if name in self.__dict__: return self.__dict__[name]
  -  
  +
  +  
     def __getattr__(self,name): 
       pass
  -  
  +
  +  
     def __str__(self): 
       return self.__dict__['@text'].strip()
  -  
  +
  +  
     def init(self):
       pass
   
   # Document root: workspaces and targets of hrefs
  -class DocRoot(GumpBase):
  +class DocRoot(GumpBase):
  +  
     def __init__(self,name,cls):
       GumpBase.__init__(self,{})
       self.name=name
       self.cls=cls
       self.element=None
  -  
  +
  +  
     def startElement(self, name, attrs):
       if name<>self.name: 
         raise "Incorrect element, expected %s, found %s" % (self.name,name)
  @@ -133,25 +161,29 @@
     def __init__(self,cls=GumpBase):
       self.delegate=None
       self.cls=cls
  -
  +
  +
     def __call__(self,attrs):
       if self.delegate: 
         self.delegate.__dict__.update(dict(attrs))
       else:
         self.delegate=self.cls(attrs)
       return self.delegate
  -
  +
  +
     def __getattr__(self,name):
       if self.delegate: 
         try:
           return self.delegate.__getattribute__(name)
         except:
           return self.delegate[name]
  -
  +
  +
     def __str__(self):
       if self.delegate: return self.delegate.__str__()
       return ''
  -
  +
  +
     def __nonzero__(self):
       return self.delegate
   
  @@ -160,20 +192,22 @@
     def __init__(self,cls=GumpBase):
       list.__init__(self)
       self.cls=cls
  -
  +
  +
     def __call__(self,attrs):
       result=self.cls(attrs)
       self.append(result)
       return result
   
   #########################################################################
  -#			    Gump Object Model				                        #
  -#                                                                       #
  -# All intelligence and functionality is provided in the base classes    #
  +#			    Gump Object Model
  +#
  +#                                                                       #
  +# All intelligence and functionality is provided in the base classes    #
   # above, allowing the actual model to be rather simple and compact.     #
   #########################################################################
   
  -# represents a <workspace/> element
  +# represents a <workspace/> element
   class Workspace(GumpBase):
     def init(self): 
       self.property=Multiple(Property)
  @@ -181,8 +215,8 @@
       self.module=Multiple(Module)
       self.repository=Multiple(Repository)
       self.profile=Multiple(Profile)
  -
  -  # provide default elements when not defined in xml
  +
  +  # provide default elements when not defined in xml
     def complete(self):
       if not self['banner-image']:
         self['banner-image']="http://jakarta.apache.org/images/jakarta-logo.gif"
  @@ -192,58 +226,58 @@
       if not self.pkgdir: self.pkgdir=self.basedir
       if self.deliver:
         if not self.scratchdir: self.scratchdir=self.basedir+"/scratch"
  -
  +
   # represents a <profile/> element
   class Profile(Named):
     list={}
  -
  +
     def init(self): 
       self.project=Multiple(Project)
       self.module=Multiple(Module)
       self.repository=Multiple(Repository)
   
  -# represents a <module/> element
  +# represents a <module/> element
   class Module(Named):
     list={}
  -
  +
     def init(self): 
       self.cvs=Single()
       self.url=Single()
       self.description=Single()
       self.redistributable=Single()
       self.project=Multiple(Project)
  -
  -  # provide default elements when not defined in xml
  +
  +  # provide default elements when not defined in xml
     def complete(self,workspace):
       self.srcdir=os.path.join(str(workspace.basedir),self.srcdir or self.name)
       for project in self.project: 
         if not project.module: project.module=self.name
  -
  +
   # represents a <repository/> element
   class Repository(Named):
     list={}
  -
  +
     def init(self): 
       self['home-page']=Single()
       self.title=Single()
       self.cvsweb=Single()
       self.root=Single(RepositoryRoot)
       self.redistributable=Single()
  -
  +
   # represents a <root/> element within a <repository/> element
   class RepositoryRoot(GumpBase):
  -
  +
     def init(self): 
       self.method=Single()
       self.user=Single()
       self.password=Single()
       self.hostname=Single()
       self.path=Single()
  -
  +
   # represents a <project/> element
   class Project(Named):
     list={}
  -
  +
     def init(self): 
       self.ant=Single(Ant)
       self.script=Single()
  @@ -262,8 +296,9 @@
       self.work=Multiple(Work)
       self.mkdir=Multiple(Mkdir)
       self.redistributable=Single()
  -
  -  # provide default elements when not defined in xml
  def complete(self,workspace):
  +
  +  # provide default elements when not defined in xml
  +  def complete(self,workspace):
   
       # compute home directory
       if self.home and isinstance(self.home,Single):
  @@ -280,40 +315,55 @@
       self.depend=Multiple(Depend)
       self.property=Multiple(Property)
       self.jvmarg=Multiple()
  -
  -  # provide default elements when not defined in xml
  def complete(self,project):
  +
  +  # provide default elements when not defined in xml
  +  def complete(self,project):
       for property in self.property: property.complete(project)
   
  -# represents a <nag/> element
class Nag(GumpBase): 
  +# represents a <nag/> element
  +class Nag(GumpBase): 
     def init(self): 
       self.regexp=Multiple()
   
  -# represents a <javadoc/> element
class Javadoc(GumpBase): 
  +# represents a <javadoc/> element
  +class Javadoc(GumpBase): 
     def init(self): 
       self.description=Multiple()
   
  -# represents a <property/> element
class Property(GumpBase): 
  -
  # provide default elements when not defined in xml
  def complete(self,project):
  +# represents a <property/> element
  +class Property(GumpBase): 
  +
  +  # provide default elements when not defined in xml
  +  def complete(self,project):
       if self.reference=='home':
         self.value=Project.list[self.project].home
       if self.reference=='srcdir':
         module=Project.list[self.project].module
         self.value=Module.list[module].srcdir
  -
  -# TODO: set up the below elements with defaults using complete()
  -# represents a <depend/> element
class Depend(GumpBase): pass
   
  -# represents a <description/> element
class Description(GumpBase): pass
   
  -# represents a <home/> element
class Home(GumpBase): pass
  +# TODO: set up the below elements with defaults using complete()
  +
  +# represents a <depend/> element
  +class Depend(GumpBase): pass
  +
  +# represents a <description/> element
  +class Description(GumpBase): pass
  +
  +# represents a <home/> element
  +class Home(GumpBase): pass
   
  -# represents a <jar/> element
class Jar(GumpBase): pass
  +# represents a <jar/> element
  +class Jar(GumpBase): pass
   
  -# represents a <junitreport/> element
class JunitReport(GumpBase): pass
  +# represents a <junitreport/> element
  +class JunitReport(GumpBase): pass
   
  -# represents a <mkdir/> element
class Mkdir(GumpBase): pass
  +# represents a <mkdir/> element
  +class Mkdir(GumpBase): pass
   
  -# represents a <work/> element
class Work(GumpBase): pass
  +# represents a <work/> element
  +class Work(GumpBase): pass
   
   #########################################################################
   #                     Utility functions                                 #
  
  
  

Mime
View raw message