gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r744462 - /gump/trunk/python/gump/core/model/module.py
Date Sat, 14 Feb 2009 10:20:06 GMT
Author: bodewig
Date: Sat Feb 14 10:20:05 2009
New Revision: 744462

URL: http://svn.apache.org/viewvc?rev=744462&view=rev
Log:
unify scm subelement parsing in module

Modified:
    gump/trunk/python/gump/core/model/module.py

Modified: gump/trunk/python/gump/core/model/module.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/model/module.py?rev=744462&r1=744461&r2=744462&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/module.py (original)
+++ gump/trunk/python/gump/core/model/module.py Sat Feb 14 10:20:05 2009
@@ -208,7 +208,7 @@
         self.notifys=[]
         
         self.repository=None
-        self.scms = {}
+        self.scm = None
         
         self.packaged           =       False 
         self.redistributable=   False
@@ -396,85 +396,8 @@
                          os.path.join(    workspace.getSourceControlStagingDirectory(), 
                                             self.getName() + '.lock'))
                                
-        # :TODO: Consolidate this code, less cut-n-paste but also
-        # check the 'type' of the repository is appropriate for the
-        # use (eg. type='cvs' if referenced by CVS).
         if not packaged:
-            # We have a CVS entry, expand it...
-            if self.hasDomChild('cvs'):
-                cvs=self.getDomChild('cvs')
-                repoName=getDomAttributeValue(cvs,'repository')
-                if repoName:
-                    if workspace.hasRepository(repoName):
-                        # It references this repository...
-                        repo=workspace.getRepository(repoName)
-                        self.repository=repo
-                        repo.addModule(self)
-                        self.scms['cvs'] = ModuleCvs(cvs,repo)
-                    else:
-                        self.changeState(STATE_FAILED,REASON_CONFIG_FAILED)             
 
-                        self.addError('No such repository ['+ str(repoName) +'] in workspace
on [' \
-                                + self.getName() + ']')
-                            
-            elif self.hasDomChild('svn'):
-                rdom=self.getDomChild('svn')
-                repoName=getDomAttributeValue(rdom,'repository')
-                if repoName:
-                    if workspace.hasRepository(repoName):
-                        # It references this repository...
-                        repo=workspace.getRepository(repoName)
-                        self.repository=repo
-                        repo.addModule(self)
-                        self.scms['svn'] = ModuleScm(rdom,repo)
-                    else:
-                        self.changeState(STATE_FAILED,REASON_CONFIG_FAILED)             
 
-                        self.addError('No such repository ['+ str(repoName) +'] in workspace
on [' \
-                                + self.getName() + ']')                 
-                                                
-            elif self.hasDomChild('p4'):
-                p4dom=self.getDomChild('p4')
-                repoName=getDomAttributeValue(p4dom,'repository')
-                if repoName:
-                    if workspace.hasRepository(repoName):
-                        # It references this repository
-                        repo=workspace.getRepository(repoName)
-                        self.repository=repo
-                        repo.addModule(self)
-                        self.scms['p4'] = ModuleP4(p4dom,repo)
-                    else:
-                        self.changeState(STATE_FAILED,REASON_CONFIG_FAILED)
-                        self.addError('No such repository ['+ str(repoName) + '] in workspace
on [' \
-                                + self.getName() + ']')
-
-            elif self.hasDomChild('artifacts'):
-                adom=self.getDomChild('artifacts')
-                repoName=getDomAttributeValue(adom,'repository')
-                if repoName:
-                    if workspace.hasRepository(repoName):
-                        # It references this repository...
-                        repo=workspace.getRepository(repoName)  
-                        self.repository=repo    
-                        repo.addModule(self)
-                        self.scms['artifacts'] = ModuleArtifacts(adom,repo)
-                    else:
-                        self.changeState(STATE_FAILED,REASON_CONFIG_FAILED)             
 
-                        self.addError('No such repository ['+ str(repoName) +'] in workspace
on [' \
-                                + self.getName() + ']')                 
-            elif self.hasDomChild('git'):
-                rdom=self.getDomChild('git')
-                repoName=getDomAttributeValue(rdom,'repository')
-                if repoName:
-                    if workspace.hasRepository(repoName):
-                        # It references this repository...
-                        repo=workspace.getRepository(repoName)
-                        self.repository=repo
-                        repo.addModule(self)
-                        self.scms['git'] = ModuleScm(rdom,repo)
-                    else:
-                        self.changeState(STATE_FAILED,REASON_CONFIG_FAILED)             
 
-                        self.addError('No such repository ['+ str(repoName) +'] in workspace
on [' \
-                                + self.getName() + ']')                 
-                                                
+            self.parseScm()
 
         # Grab all notifications
         for notifyEntry in self.getDomChildIterator('nag'):
@@ -509,6 +432,44 @@
                 
         self.setComplete(True)            
         
+    def parseScm(self):
+        """
+        Parses the child element that holds SCM information
+        """
+
+        # sorted by priority, the first matching SCM element wins
+        supportedScms = ['cvs', 'svn', 'p4', 'git', 'artifacts']
+        for s in supportedScms:
+            if self.hasDomChild(s):
+                dom = self.getDomChild(s)
+                repoName = getDomAttributeValue(dom, 'repository')
+                if repoName:
+                    if self.workspace.hasRepository(repoName):
+                        # It references this repository...
+                        repo = self.workspace.getRepository(repoName)
+                        self.repository = repo
+                        repo.addModule(self)
+                        self.scm = self.createScmInstance(s, dom, repo)
+                    else:
+                        self.changeState(STATE_FAILED,REASON_CONFIG_FAILED)
+                        self.addError('No such repository ['+ str(repoName) \
+                                          +'] in workspace on [' \
+                                          + self.getName() + ']')
+                return
+
+
+    def createScmInstance(self, type, dom, repo):
+        """
+        Factory method for matching ModuleScm subclass of given SCM
+        """
+        if type == 'cvs':
+            return ModuleCvs(dom, repo)
+        elif type == 'p4':
+            return ModuleP4(dom, repo)
+        elif type == 'artifacts':
+            return ModuleArtifacts(dom, repo)
+        return ModuleScm(dom, repo)
+
     def hasNotifys(self):
         if self.notifys: return True
         return False
@@ -718,7 +679,8 @@
             return 'http://svn.apache.org/repos/asf/gump/metadata/' + location
         
     def isUpdatable(self):
-        return len(self.scms) > 0
+        if self.scm: return True
+        return False
                 
     # Where the contents (at the repository) Modified?
     def isModified(self):
@@ -746,19 +708,7 @@
             return scm.getViewUrl()
 
     def getScm(self):
-        # this is the priority order originally present
-        # CVS over svn over P4 over GIT and artifacts last
-
-        # will be swapped against a list based version later
-        if 'cvs' in self.scms:
-            return self.scms['cvs']
-        if 'svn' in self.scms:
-            return self.scms['svn']
-        if 'p4' in self.scms:
-            return self.scms['p4']
-        if 'git' in self.scms:
-            return self.scms['git']
-        return self.scms.get('artifacts')
+        return self.scm
 
 class ModuleStatistics(Statistics):
     """ 



Mime
View raw message