gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r161569 - in gump/branches/Gump3/pygump/python/gump: config.py test/testUtilExecutor.py util/executor.py
Date Sat, 16 Apr 2005 14:21:25 GMT
Author: leosimons
Date: Sat Apr 16 07:21:24 2005
New Revision: 161569

URL: http://svn.apache.org/viewcvs?view=rev&rev=161569
Log:
Useful execution debugging and conditional checkouts.

* pygump/python/gump/config.py: configure gump.util.executor to log its command execution,
and add a new section at the bottom of the config file for all the 'irregular' configuration
bits like this.

* pygump/python/gump/util/executor.py, pygump/python/gump/test/testUtilExecutor.py: add some
tweaks to gump.util.executor that make it possible to log all executed commands for easier
debugging.

Modified:
    gump/branches/Gump3/pygump/python/gump/config.py
    gump/branches/Gump3/pygump/python/gump/test/testUtilExecutor.py
    gump/branches/Gump3/pygump/python/gump/util/executor.py

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=161568&r2=161569
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Sat Apr 16 07:21:24 2005
@@ -75,9 +75,8 @@
     config.database_user = settings.databaseuser
     config.database_password = settings.databasepassword
     
-    # set up logging
-    from logging.config import fileConfig
-    fileConfig('gump.log.config')
+    # set up other stuff
+    run_config_hooks(config)
     
     return config
 
@@ -99,10 +98,10 @@
     from gump.plugins.instrumentation import TimerPlugin
     pre_process_plugins.append(TimerPlugin("run_start"))
     
-    from gump.plugins.updater import CvsUpdater, SvnUpdater
-    pre_process_plugins.append(CvsUpdater(config.paths_work))
-    pre_process_plugins.append(SvnUpdater(config.paths_work))
-    
+    if config.do_update:
+        from gump.plugins.updater import CvsUpdater, SvnUpdater
+        pre_process_plugins.append(CvsUpdater(config.paths_work))
+        pre_process_plugins.append(SvnUpdater(config.paths_work))
     
     plugins = []
     # TODO: append more plugins here...
@@ -259,3 +258,19 @@
     return (MulticastPlugin(pre_process_plugins, error_handler),
             MulticastPlugin(plugins, error_handler),
             MulticastPlugin(post_process_plugins, error_handler))
+
+#
+# Miscellaneous configuration bits
+#
+def run_config_hooks(config):
+    """This function is the place to configure all things that aren't cleanly
+    "class-based", for example per-module configuration."""
+
+    # set up logging module
+    from logging.config import fileConfig
+    fileConfig('gump.log.config')
+    
+    # set up gump.util.executor module
+    # this will make Popen log all invocations
+    import gump.util.executor
+    gump.util.executor._log = get_logger(config, "util.executor")

Modified: gump/branches/Gump3/pygump/python/gump/test/testUtilExecutor.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testUtilExecutor.py?view=diff&r1=161568&r2=161569
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testUtilExecutor.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testUtilExecutor.py Sat Apr 16 07:21:24 2005
@@ -28,6 +28,22 @@
 from gump.util.executor import clean_up_processes
 
 class ZZZExecutorUtilTestCase(TestCase):
+    def test_command_logging(self):
+        if sys.platform == "win32":
+            return
+        
+        class _DummyLogger:
+            msg = None
+            
+            def debug(self,msg):
+                self.msg = msg
+        import gump.util.executor
+        gump.util.executor._log = _DummyLogger()
+        result = Popen(["pwd"], stdout=PIPE).communicate()[0]
+        self.assertNotEqual(None, gump.util.executor._log.msg)
+        self.assert_(gump.util.executor._log.msg.index("pwd") >= 0)
+        gump.util.executor._log = None
+        
     def test_zzz_run_simple_command_then_clean_up_processes(self):
         if sys.platform == "win32":
             return

Modified: gump/branches/Gump3/pygump/python/gump/util/executor.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/executor.py?view=diff&r1=161568&r2=161569
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/executor.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/executor.py Sat Apr 16 07:21:24 2005
@@ -30,11 +30,20 @@
 that doing this can take some time depending on how well-behaved your children
 are!"""
 
+# The reason we aren't using a cleaner class-based setup here like we do with
+# most of the other utility methods is that doing things this way (providing a
+# Popen class) means this module can be used as a drop-in replacement for the
+# subprocess module, which is, simply put, very convenient!
+
 __copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 import sys
 
+# set this to a logging-module-compatible logger to make this module log all
+# the commands it executes
+_log = None
+
 if sys.platform == "win32":
     from subprocess import PIPE
     from subprocess import STDOUT
@@ -108,6 +117,10 @@
                 # call in there while still supporting the originally provided
                 # function
                 pre_exec_function = lambda: (preexec_fn(),os.setpgid(0, _our_process_group))
+            
+            # a logger can be set for this module to make us log commands
+            if _log:
+                _log.debug("Executing command: '%s' in directory '%s'" % (" ".join(args),os.path.abspath(cwd
or os.curdir)))
             
             subprocess.Popen.__init__(self, args, bufsize=bufsize, executable=executable,
                      stdin=stdin, stdout=stdout, stderr=stderr,



Mime
View raw message