gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r746892 - in /gump/trunk/python/gump: actor/document/xdocs/documenter.py core/model/module.py core/model/repository.py core/update/scmupdater.py core/update/updater.py test/model.py
Date Mon, 23 Feb 2009 05:47:26 GMT
Author: bodewig
Date: Mon Feb 23 05:47:25 2009
New Revision: 746892

URL: http://svn.apache.org/viewvc?rev=746892&view=rev
Log:
get rid of string constants

Modified:
    gump/trunk/python/gump/actor/document/xdocs/documenter.py
    gump/trunk/python/gump/core/model/module.py
    gump/trunk/python/gump/core/model/repository.py
    gump/trunk/python/gump/core/update/scmupdater.py
    gump/trunk/python/gump/core/update/updater.py
    gump/trunk/python/gump/test/model.py

Modified: gump/trunk/python/gump/actor/document/xdocs/documenter.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/actor/document/xdocs/documenter.py?rev=746892&r1=746891&r2=746892&view=diff
==============================================================================
--- gump/trunk/python/gump/actor/document/xdocs/documenter.py (original)
+++ gump/trunk/python/gump/actor/document/xdocs/documenter.py Mon Feb 23 05:47:25 2009
@@ -39,6 +39,7 @@
 from gump.core.language.path import AnnotatedPath
 from gump.core.model.misc import Resultable
 from gump.core.model.project import Project
+from gump.core.model.repository import SCM_TYPE_CVS, SCM_TYPE_P4
 from gump.core.model.state import REASON_BUILD_FAILED, REASON_PACKAGE, \
     REASON_UNSET, reasonDescription, STATE_COMPLETE, STATE_FAILED, \
     STATE_PREREQ_FAILED, STATE_SUCCESS, STATE_UNSET, stateDescription, stateName
@@ -1476,8 +1477,8 @@
         if repo.hasTitle():
             detailList.createEntry('Title: ', repo.getTitle())
 
-        if repo.hasType():
-            detailList.createEntry('Type: ', repo.getType())
+        if repo.hasScmType():
+            detailList.createEntry('Type: ', repo.getScmType().name)
 
         if repo.hasHomePage():
             detailList.createEntry('Homepage: ') \
@@ -1799,11 +1800,11 @@
 
             scm = module.getScm()
             if scm:
-                scmName = scm.getScmName()
+                scmName = scm.getScmType().displayName
                 if scm.hasDir():
                     repoList.createEntry(scmName + " Directory: ",
                                          scm.getDir())
-                if scm.getScmType() == 'cvs':
+                if scm.getScmType() == SCM_TYPE_CVS:
                     if scm.hasModule():
                         repoList.createEntry(scmName + " Module: ",
                                              scm.getModule())
@@ -1817,7 +1818,7 @@
 
                     repoList.createEntry("CVSROOT: ", scm.getCvsRoot())
 
-                elif scm.getScmType() == 'p4':
+                elif scm.getScmType() == SCM_TYPE_P4:
                     if scm.hasTag():
                         repoList.createEntry(scmName + " Tag: ", scm.getTag())
 

Modified: gump/trunk/python/gump/core/model/module.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/model/module.py?rev=746892&r1=746891&r2=746892&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/module.py (original)
+++ gump/trunk/python/gump/core/model/module.py Mon Feb 23 05:47:25 2009
@@ -25,6 +25,8 @@
 from gump.core.model.misc import Resultable, Positioned, AddressPair
 from gump.core.model.object import NamedModelObject, ModelObject
 from gump.core.model.project import Project, ProjectSummary
+from gump.core.model.repository import SCM_TYPE_ARTIFACTS, SCM_TYPE_CVS, \
+    SCM_TYPE_P4, SUPPORTED_SCMS
 from gump.core.model.state import REASON_CONFIG_FAILED, REASON_PACKAGE, \
     STATE_COMPLETE, STATE_FAILED
 from gump.core.model.stats import Statable, Statistics
@@ -40,11 +42,11 @@
     """
     Factory method for matching ModuleScm subclass of given SCM
     """
-    if scm_type == 'cvs':
+    if scm_type == SCM_TYPE_CVS:
         return ModuleCvs(dom, repo)
-    elif scm_type == 'p4':
+    elif scm_type == SCM_TYPE_P4:
         return ModuleP4(dom, repo)
-    elif scm_type == 'artifacts':
+    elif scm_type == SCM_TYPE_ARTIFACTS:
         return ModuleArtifacts(dom, repo)
     return ModuleScm(dom, repo)
 
@@ -61,7 +63,6 @@
 
         # Extract settings
         self.dir = self.getDomAttributeValue('dir')
-        self.type = self.element.tagName
 
     def getRootUrl(self):
         url = self.repository.getUrl()
@@ -81,10 +82,7 @@
         return self.getRootUrl()
 
     def getScmType(self):
-        return self.type
-
-    def getScmName(self):
-        return self.repository.getType()
+        return self.repository.getScmType()
 
 class ModuleCvs(ModuleScm):
     """
@@ -483,11 +481,9 @@
         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)
+        for s in SUPPORTED_SCMS:
+            if self.hasDomChild(s.name):
+                dom = self.getDomChild(s.name)
                 repoName = getDomAttributeValue(dom, 'repository')
                 if repoName:
                     if self.workspace.hasRepository(repoName):

Modified: gump/trunk/python/gump/core/model/repository.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/model/repository.py?rev=746892&r1=746891&r2=746892&view=diff
==============================================================================
--- gump/trunk/python/gump/core/model/repository.py (original)
+++ gump/trunk/python/gump/core/model/repository.py Mon Feb 23 05:47:25 2009
@@ -22,6 +22,35 @@
 from gump.util import getIndent
 from gump.util.domutils import getDomChildValue
 
+class ScmType:
+    """
+    enum-like class describing all supported SCMs
+    """
+
+    def __init__(self, name, displayName):
+        self.name = name
+        self.displayName = displayName
+
+SCM_TYPE_CVS = ScmType('cvs', 'CVS')
+SCM_TYPE_SVN = ScmType('svn', 'Subversion')
+SCM_TYPE_ARTIFACTS = ScmType('artifacts', 'Artfifacts')
+SCM_TYPE_P4 = ScmType('p4', 'Perforce')
+SCM_TYPE_GIT = ScmType('git', 'Git')
+
+# sorted by priority, the first matching SCM element inside a module wins
+SUPPORTED_SCMS = [SCM_TYPE_CVS, SCM_TYPE_SVN, SCM_TYPE_P4,
+                  SCM_TYPE_GIT,
+                  SCM_TYPE_ARTIFACTS]
+
+def scm_type_for_name(name):
+    """
+    looks up a supported SCM by its name
+    """
+    for s in SUPPORTED_SCMS:
+        if s.name == name:
+            return s
+    return None
+
 class Repository(NamedModelObject, Statable):
     """ 
 
@@ -34,17 +63,12 @@
 
         self.url = None
 
-        typeToLabel = {'cvs':'CVS', 'svn':'Subversion', 'artifact':'Artifact',
-                       'p4':'Perforce', 'git':'Git'}
-
-        type = self.getDomAttributeValue('type')
+        typeAttribute = self.getDomAttributeValue('type')
+        self.scmType = scm_type_for_name(typeAttribute)
+        if not self.scmType:
+            raise RuntimeError, 'Invalid Repository Type:' + str(typeAttribute)
 
-        try:
-            self.type = typeToLabel[type]
-        except:
-            raise RuntimeError, 'Invalid Repository Type:' + str(type)
-
-        if 'cvs' == type:
+        if SCM_TYPE_CVS == self.scmType:
             self.web = self.getDomChildValue('web') or \
                 self.getDomChildValue('cvsweb')
             if self.hasDomChild('root'):
@@ -57,7 +81,7 @@
             else:
                 raise RuntimeError, 'No XML <root on repository: ' \
                     + self.getName()
-        elif 'p4' == type:
+        elif SCM_TYPE_P4 == self.scmType:
             if self.hasDomChild('root'):
                 root = self.getDomChild('root')
                 self.p4port = getDomChildValue(root, 'hostname')
@@ -69,8 +93,8 @@
             if self.hasDomChild('url'):
                 self.url = self.getDomChildValue('url')
             else:
-                raise RuntimeError, 'No URL on ' + self.type + ' repository: ' \
-                    + self.getName()
+                raise RuntimeError, 'No URL on ' + self.scmType.displayName + \
+                    ' repository: ' + self.getName()
             self.web = self.getDomChildValue('web')
             self.user = self.getDomChildValue('user')
             self.password = self.getDomChildValue('password')
@@ -90,13 +114,13 @@
             return True
         return False
 
-    def hasType(self):
-        if self.type:
+    def hasScmType(self):
+        if self.scmType:
             return True
         return False
 
-    def getType(self):
-        return self.type
+    def getScmType(self):
+        return self.scmType
 
     def getModules(self):
         return self.modules

Modified: gump/trunk/python/gump/core/update/scmupdater.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/scmupdater.py?rev=746892&r1=746891&r2=746892&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/scmupdater.py (original)
+++ gump/trunk/python/gump/core/update/scmupdater.py Mon Feb 23 05:47:25 2009
@@ -57,7 +57,7 @@
         Performs a fresh check-out or an update of an existing wrokspace.
         """
 
-        log.info('Perform ' + module.getScm().getScmName() + \
+        log.info('Perform ' + module.getScm().getScmType().displayName + \
                      ' Checkout/Update on #[' + `module.getPosition()` + \
                      '] : ' + module.getName())
     
@@ -65,11 +65,12 @@
 
         if cmd:
             if isUpdate:
-                log.debug(module.getScm().getScmName() + " Module Update : " + \
+                log.debug(module.getScm().getScmType().displayName + \
+                              " Module Update : " + \
                               module.getName() + ", Repository Name: " + \
                               module.repository.getName())
             else:
-                log.debug(module.getScm().getScmName() + \
+                log.debug(module.getScm().getScmType().displayName + \
                               " Module Checkout : " + module.getName() + \
                               ", Repository Name: " + \
                               module.repository.getName())

Modified: gump/trunk/python/gump/core/update/updater.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/updater.py?rev=746892&r1=746891&r2=746892&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/updater.py (original)
+++ gump/trunk/python/gump/core/update/updater.py Mon Feb 23 05:47:25 2009
@@ -23,6 +23,8 @@
 import os.path
 
 from gump import log
+from gump.core.model.repository import SCM_TYPE_CVS, SCM_TYPE_GIT, \
+    SCM_TYPE_SVN, SCM_TYPE_P4
 from gump.core.model.workspace import catFileToFileHolder, \
     EXIT_CODE_FAILED, EXIT_CODE_SUCCESS, FILE_TYPE_LOG, \
     gumpSafeName, logResourceUtilization, \
@@ -95,8 +97,12 @@
     def __init__(self, run):
         RunSpecific.__init__(self, run)
         
-        self.updaters = {'cvs' : CvsUpdater(run), 'svn' : SvnUpdater(run),
-                         'p4' : P4Updater(run), 'git' : GitUpdater(run)}
+        self.updaters = {
+            SCM_TYPE_CVS : CvsUpdater(run),
+            SCM_TYPE_SVN : SvnUpdater(run),
+            SCM_TYPE_P4 : P4Updater(run),
+            SCM_TYPE_GIT : GitUpdater(run)
+            }
 
 
     #    ******************************************************************

Modified: gump/trunk/python/gump/test/model.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/test/model.py?rev=746892&r1=746891&r2=746892&view=diff
==============================================================================
--- gump/trunk/python/gump/test/model.py (original)
+++ gump/trunk/python/gump/test/model.py Mon Feb 23 05:47:25 2009
@@ -27,6 +27,7 @@
 
 from gump import log
 import gump.core.config
+from gump.core.model.repository import SCM_TYPE_CVS, SCM_TYPE_SVN
 from gump.core.model.state import *
 from gump.util import *
 from gump.test import getWorkedTestRun
@@ -167,7 +168,7 @@
         module2=self.module2
         
         self.assertTrue('Module has CVS',
-                        module1.getScm().getScmType() == 'cvs')
+                        module1.getScm().getScmType() == SCM_TYPE_CVS)
         self.assertNonZeroString('CVSROOT',module1.cvs.getCvsRoot())
         self.assertNonZeroString('Has Tag',module1.cvs.getTag())
         self.assertNonZeroString('Has Tag',module2.getTag())
@@ -176,7 +177,7 @@
         svnmodule1= self.workspace.getModule('svn_module1')
         
         self.assertTrue('Module has SVN',
-                        module1.getScm().getScmType() == 'svn')
+                        module1.getScm().getScmType() == SCM_TYPE_SVN)
         self.assertNonZeroString('SVN URL',svnmodule1.svn.getRootUrl())
         self.assertTrue('SVN Dir',svnmodule1.svn.hasDir())
     



Mime
View raw message