You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by le...@apache.org on 2005/04/16 17:02:51 UTC

svn commit: r161577 - in gump/branches/Gump3: metadata/giraffe.xml pygump/python/gump/config.py pygump/python/gump/plugins/dirbuilder.py pygump/python/gump/plugins/mkdirbuilder.py pygump/python/gump/test/testPluginDirBuilder.py pygump/python/gump/test/testPluginMkdirBuilder.py

Author: leosimons
Date: Sat Apr 16 08:02:50 2005
New Revision: 161577

URL: http://svn.apache.org/viewcvs?view=rev&rev=161577
Log:
Implement a rmdir plugin.


* moved pygump/python/gump/plugins/mkdirbuilder.py to pygump/python/gump/plugins/dirbuilder.py.

* moved pygump/python/gump/test/testPluginMkdirBuilder.py to pygump/python/gump/test/testPluginDirBuilder.py.

* pygump/python/gump/plugins/dirbuilder.py, pygump/python/gump/test/testPluginDirBuilder.py: clone the mkdir plugin and its testcase to create a rmdir plugin. There is of course some potential for cleanup here :-D

* pygump/python/gump/config.py: add the rmdir plugin into the processing plugin list.

* metadata/giraffe.xml: add a rmdir command to the integration testing.

Added:
    gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py
      - copied, changed from r161573, gump/branches/Gump3/pygump/python/gump/plugins/mkdirbuilder.py
    gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py
      - copied, changed from r161573, gump/branches/Gump3/pygump/python/gump/test/testPluginMkdirBuilder.py
Removed:
    gump/branches/Gump3/pygump/python/gump/plugins/mkdirbuilder.py
    gump/branches/Gump3/pygump/python/gump/test/testPluginMkdirBuilder.py
Modified:
    gump/branches/Gump3/metadata/giraffe.xml
    gump/branches/Gump3/pygump/python/gump/config.py

Modified: gump/branches/Gump3/metadata/giraffe.xml
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/metadata/giraffe.xml?view=diff&r1=161576&r2=161577
==============================================================================
--- gump/branches/Gump3/metadata/giraffe.xml (original)
+++ gump/branches/Gump3/metadata/giraffe.xml Sat Apr 16 08:02:50 2005
@@ -50,9 +50,11 @@
       <module name="ant"/>
     </project>
     
-    <project name="test-attempt-mkdirs">
+    <project name="test-attempt-dir-management">
       <module name="ant"/>
       
+      <!-- commands -->
+      <rmdir dir="some"/>
       <mkdir dir="some/directory"/>
     </project>
     

Modified: gump/branches/Gump3/pygump/python/gump/config.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/config.py?view=diff&r1=161576&r2=161577
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Sat Apr 16 08:02:50 2005
@@ -91,7 +91,10 @@
     The config argument provided is an instance of the _Config class that is
     returned from the get_config method below.
     """
-    
+    #
+    # Note that in general, the ordering of these plugins is vital to ensuring
+    # correct functionality!
+    #
     pre_process_plugins = []
     # TODO: append more plugins here...
     
@@ -109,7 +112,10 @@
     from gump.plugins import LoggingPlugin
     log = get_logger(config, "plugin")
 
-    from gump.plugins.mkdirbuilder import MkdirBuilderPlugin
+    # by contract, rmdir always needs to go before mkdir!
+    from gump.plugins.dirbuilder import RmdirBuilderPlugin
+    plugins.append(RmdirBuilderPlugin(config.paths_work))
+    from gump.plugins.dirbuilder import MkdirBuilderPlugin
     plugins.append(MkdirBuilderPlugin(config.paths_work))
     
     post_process_plugins = []

Copied: gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py (from r161573, gump/branches/Gump3/pygump/python/gump/plugins/mkdirbuilder.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py?view=diff&rev=161577&p1=gump/branches/Gump3/pygump/python/gump/plugins/mkdirbuilder.py&r1=161573&p2=gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py&r2=161577
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/plugins/mkdirbuilder.py (original)
+++ gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py Sat Apr 16 08:02:50 2005
@@ -18,11 +18,13 @@
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 from gump.model import Mkdir
+from gump.model import Rmdir
 from gump.model import Error
 from gump.model.util import get_project_directory
 from gump.plugins import AbstractPlugin
 
 import os
+import shutil
 
 class MkdirBuilderPlugin(AbstractPlugin):
     """Execute all "mkdir" commands for all projects."""
@@ -44,3 +46,24 @@
     def visit_project(self, project):
         for command in [command for command in project.commands if isinstance(command,Mkdir)]:
             self._do_mkdir(project, command.directory)
+
+class RmdirBuilderPlugin(AbstractPlugin):
+    """Execute all "rmdir" commands for all projects."""
+    def __init__(self, workdir):
+        self.workdir = workdir
+        
+    def _do_rmdir(self, project, directory):
+        projectpath = get_project_directory(self.workdir,project)
+        dirpath = os.path.abspath(os.path.join(projectpath,directory))
+        if not dirpath.startswith(projectpath):
+            raise Error, "Directory '%s' to be deleted not within project path '%s'!" % (directory, projectpath)
+        
+        if os.path.exists(dirpath):
+            if not os.path.isdir(dirpath):
+                raise Error, "Directory path '%s' to be removed exists as a file!" % dirpath
+            
+            shutil.rmtree(dirpath)
+
+    def visit_project(self, project):
+        for command in [command for command in project.commands if isinstance(command,Rmdir)]:
+            self._do_rmdir(project, command.directory)

Copied: gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py (from r161573, gump/branches/Gump3/pygump/python/gump/test/testPluginMkdirBuilder.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py?view=diff&rev=161577&p1=gump/branches/Gump3/pygump/python/gump/test/testPluginMkdirBuilder.py&r1=161573&p2=gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py&r2=161577
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testPluginMkdirBuilder.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py Sat Apr 16 08:02:50 2005
@@ -22,17 +22,42 @@
 
 from tempfile import mkdtemp
 from os import mkdir
+from os import makedirs
 from os.path import abspath
 from os.path import isdir
 from os.path import join
 
 from shutil import rmtree
 
-from gump.plugins.mkdirbuilder import MkdirBuilderPlugin
+from gump.plugins.dirbuilder import MkdirBuilderPlugin
+from gump.plugins.dirbuilder import RmdirBuilderPlugin
 
 from gump.model import Error, Workspace, Repository, Module, Project, Mkdir, Rmdir
 
-class MkdirBuilderTestCase(TestCase):
+class DirBuilderTestCase(TestCase):
+    def test_do_rmdir(self):
+        basedir = abspath(mkdtemp())
+        try:
+            w = Workspace("w")
+            mkdir(join(basedir,w.name))
+            r = Repository(w,"r")
+            mkdir(join(basedir,w.name,r.name))
+            m = Module(r,"m")
+            mpath = join(basedir,w.name,r.name,m.name)
+            mkdir(mpath)
+            p = Project(m,"p")
+
+            cmd = Rmdir(p,"somedir")
+
+            plugin = RmdirBuilderPlugin(basedir)
+            
+            makedirs(join(mpath, cmd.directory, "nested", "stuff", "here"))
+            plugin._do_rmdir(cmd.project, cmd.directory)
+            self.assertFalse(isdir(join(mpath,cmd.directory)))
+            self.assert_(isdir(join(mpath)))
+        finally:
+            rmtree(basedir)
+        
     def test_do_mkdir(self):
         basedir = abspath(mkdtemp())
         try:
@@ -84,7 +109,7 @@
 
 # this is used by testrunner.py to determine what tests to run
 def test_suite():
-    return unittest.makeSuite(MkdirBuilderTestCase,'test')
+    return unittest.makeSuite(DirBuilderTestCase,'test')
 
 # this allows us to run this test by itself from the commandline
 if __name__ == '__main__':