gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r161593 - in gump/branches/Gump3/pygump/python/gump: plugins/builder.py test/testPluginBuilder.py
Date Sat, 16 Apr 2005 18:36:30 GMT
Author: leosimons
Date: Sat Apr 16 11:36:29 2005
New Revision: 161593

URL: http://svn.apache.org/viewcvs?view=rev&rev=161593
Log:
Start with the 'real building' with a script plugin.

* pygump/python/gump/plugins/builder.py,
  pygump/python/gump/test/testPluginBuilder.py:
    New plugin that handes 'script' commands.

Added:
    gump/branches/Gump3/pygump/python/gump/plugins/builder.py
      - copied, changed from r161577, gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py
    gump/branches/Gump3/pygump/python/gump/test/testPluginBuilder.py
      - copied, changed from r161577, gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py

Copied: gump/branches/Gump3/pygump/python/gump/plugins/builder.py (from r161577, gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/plugins/builder.py?view=diff&rev=161593&p1=gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py&r1=161577&p2=gump/branches/Gump3/pygump/python/gump/plugins/builder.py&r2=161593
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/plugins/dirbuilder.py (original)
+++ gump/branches/Gump3/pygump/python/gump/plugins/builder.py Sat Apr 16 11:36:29 2005
@@ -17,53 +17,40 @@
 __copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
-from gump.model import Mkdir
-from gump.model import Rmdir
-from gump.model import Error
+import os
+import sys
+from os.path import abspath, join, isfile
+
+from gump.model import Script, Error
 from gump.model.util import get_project_directory
 from gump.plugins import AbstractPlugin
+from gump.util.executor import Popen, PIPE, STDOUT
 
-import os
-import shutil
-
-class MkdirBuilderPlugin(AbstractPlugin):
-    """Execute all "mkdir" commands for all projects."""
+class ScriptBuilderPlugin(AbstractPlugin):
+    """Execute all "script" commands for all projects."""
     def __init__(self, workdir):
         self.workdir = workdir
         
-    def _do_mkdir(self, project, directory):
+    def _do_script(self, project, script):
+        # NOTE: no support for basedir="", an undocumented feature in gump2
         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 created not within project path '%s'!" % (directory,
projectpath)
         
-        if not os.path.isdir(dirpath):
-            if os.path.exists(dirpath):
-                raise Error, "Directory path '%s' to be created exists as a file!" % dirpath
+        scriptfile = abspath(join(projectpath, script.name))
+        if not isfile(scriptfile):
+            if sys.platform == "win32":
+                scriptfile += ".bat"
+            else:
+                scriptfile += ".sh"
             
-            os.makedirs(dirpath)
-
-    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
+            if not isfile(scriptfile):
+                raise Error, "No script '%s' found!" % scriptfile
         
-    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)
+        args = [scriptfile] + script.args
+        cmd = Popen(args,shell=True,cwd=projectpath,stdout=PIPE,stderr=STDOUT)
         
-        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)
+        script.build_log = cmd.communicate()[0]
+        script.build_exit_status = cmd.wait()
 
     def visit_project(self, project):
-        for command in [command for command in project.commands if isinstance(command,Rmdir)]:
-            self._do_rmdir(project, command.directory)
+        for command in [command for command in project.commands if isinstance(command,Script)]:
+            self._do_script(project, command)

Copied: gump/branches/Gump3/pygump/python/gump/test/testPluginBuilder.py (from r161577, gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testPluginBuilder.py?view=diff&rev=161593&p1=gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py&r1=161577&p2=gump/branches/Gump3/pygump/python/gump/test/testPluginBuilder.py&r2=161593
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testPluginDirBuilder.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testPluginBuilder.py Sat Apr 16 11:36:29 2005
@@ -21,21 +21,21 @@
 from unittest import TestCase
 
 from tempfile import mkdtemp
+import stat
+import os
 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.dirbuilder import MkdirBuilderPlugin
-from gump.plugins.dirbuilder import RmdirBuilderPlugin
+from gump.plugins.builder import ScriptBuilderPlugin
 
-from gump.model import Error, Workspace, Repository, Module, Project, Mkdir, Rmdir
+from gump.model import Workspace, Repository, Module, Project, Script, Error
 
-class DirBuilderTestCase(TestCase):
-    def test_do_rmdir(self):
+class BuilderTestCase(TestCase):
+    def test_do_script(self):
         basedir = abspath(mkdtemp())
         try:
             w = Workspace("w")
@@ -46,70 +46,30 @@
             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:
-            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 = Mkdir(p,"somedir")
-        
-            plugin = MkdirBuilderPlugin(basedir)
-            
-            plugin._do_mkdir(cmd.project, cmd.directory)
-            self.assert_(isdir(join(mpath,cmd.directory)))
-            rmtree(join(mpath,cmd.directory))
-            
-            plugin._do_mkdir(cmd.project, "some/nested/directory")
-            self.assert_(isdir(join(mpath,"some/nested/directory")))
-            rmtree(join(mpath,"some/nested/directory"))
-
-            p.add_command(cmd)
-            cmd2 = Mkdir(p,"somedir2")
-            p.add_command(cmd2)
-            cmd3 = Rmdir(p,"elsewhere")
-            p.add_command(cmd3)
-            plugin.visit_project(p)
-            
-            self.assert_(isdir(join(mpath,cmd.directory)))
-            self.assert_(isdir(join(mpath,cmd2.directory)))
-            self.assertFalse(isdir(join(mpath,cmd3.directory)))
-            rmtree(join(mpath,cmd.directory))
+            scriptpath = join(mpath,"dobuild")
+            scriptfile = open(scriptpath, mode='w')
+            scriptfile.write("""#!/bin/sh
+
+echo RESULT
+""")
+            scriptfile.close()
+            os.chmod(scriptpath, 0755)
+
+            plugin = ScriptBuilderPlugin(basedir)
+
+            cmd = Script(p, "dobuild")
+            plugin._do_script(cmd.project, cmd)
+            self.assertEqual("RESULT\n", cmd.build_log)
+            self.assertEqual(0, cmd.build_exit_status)
             
-            # failure on bad path
-            cmd = Mkdir(p,join("..", "..", "..", "somedir"))
-            self.assertRaises(Error, plugin._do_mkdir, cmd.project, cmd.directory)
-
-            # failure on bad file
-            cmd = Mkdir(p,"somedir")
-            file = open(join(mpath,cmd.directory),"w")
-            file.write("blah")
-            file.close()
-            self.assertRaises(Error, plugin._do_mkdir, cmd.project, cmd.directory)
+            cmd = Script(p, "nosuchscript")
+            self.assertRaises(Error, plugin._do_script, cmd.project, cmd)
         finally:
-            rmtree(basedir)
+            rmtree(basedir)        
 
 # this is used by testrunner.py to determine what tests to run
 def test_suite():
-    return unittest.makeSuite(DirBuilderTestCase,'test')
+    return unittest.makeSuite(BuilderTestCase,'test')
 
 # this allows us to run this test by itself from the commandline
 if __name__ == '__main__':



Mime
View raw message