gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r986938 - /gump/trunk/cron/gump.py
Date Wed, 18 Aug 2010 21:00:19 GMT
Author: bodewig
Date: Wed Aug 18 21:00:18 2010
New Revision: 986938

URL: http://svn.apache.org/viewvc?rev=986938&view=rev
Log:
make the pre/post run script code actually work for scripts living in the cron directory -
not that the old code worked for any other directory

Modified:
    gump/trunk/cron/gump.py

Modified: gump/trunk/cron/gump.py
URL: http://svn.apache.org/viewvc/gump/trunk/cron/gump.py?rev=986938&r1=986937&r2=986938&view=diff
==============================================================================
--- gump/trunk/cron/gump.py (original)
+++ gump/trunk/cron/gump.py Wed Aug 18 21:00:18 2010
@@ -247,6 +247,27 @@ def tailFile(file, lines, _eol = None, _
 def tailFileToString(file, lines, eol = None, marker = None):
     return "".join(tailFile(file, lines, eol, marker))
 
+def run_prepost_script(env_var, script_type):
+    """
+    runs a local PRE or POST script if the corresponding envoronment
+    variable has been specified and the script exists.
+    """
+    if os.environ.has_key(env_var):
+        pp_script = os.environ[env_var]
+        if not os.path.exists(pp_script):
+            pp_script = os.path.join(start_dir, pp_script)
+        if os.path.exists(pp_script):
+            pp_name = os.path.basename(pp_script)
+            pp_exit = runCommand(pp_script,
+                                 outputFile = os.path.join(".",
+                                                           pp_name + ".out")
+                                 )
+            if pp_exit:
+                return 1
+        else:
+            log.write('No %s script [%s].\n' % (script_type, pp_script))
+    return 0
+
 def doRun():
     # Starting up...
     writeRunLogEntry('Gump Start-up. Arguments [%s]' % sys.argv)
@@ -411,17 +432,8 @@ def doRun():
             if os.path.exists('.timestamp'): 
                 os.remove('.timestamp')
 
-            if os.environ.has_key('HOST_LOCAL_PRE_RUN'):
-                pre_run_script = os.environ['HOST_LOCAL_PRE_RUN']
-                if os.path.exists(pre_run_script):
-                    pre_exit = runCommand(os.path.join('.', pre_run_script), \
-                                          outputFile = \
-                                              os.path.join(pre_run_script,
-                                                           ".out"))
-                    if pre_exit:
-                        result = 1
-                else:
-                    log.write('No pre-run script [%s].\n' % pre_run_script)
+            if run_prepost_script('HOST_LOCAL_PRE_RUN', 'pre-run'):
+                result = 1
 
             if not result:
                 # Process/build command line
@@ -445,20 +457,8 @@ def doRun():
                     result = 1
 
             if not result:
-                if os.environ.has_key('HOST_LOCAL_POST_RUN'):
-                    post_run_script = os.environ['HOST_LOCAL_POST_RUN']
-                    if os.path.exists(post_run_script):
-                        post_exit = runCommand(os.path.join('.',
-                                                            post_run_script), \
-                                          outputFile = \
-                                                   os.path.join(post_run_script,
-                                                                ".out"))
-                        if post_exit:
-                            result = 1
-                    else:
-                        log.write('No post-run script [%s].\n' % \
-                                      post_run_script)
-
+                if run_prepost_script('HOST_LOCAL_POST_RUN', 'post-run'):
+                    result = 1
 
         except KeyboardInterrupt:
             log.write('Terminated by user interrupt...\n')
@@ -569,6 +569,7 @@ def doRun():
 # Do it! Do it!
 
 # Ensure we start in the correct directory, setting GUMP_HOME
+start_dir = os.path.abspath(os.getcwd())
 gumpHome = os.path.abspath(os.path.join(os.getcwd(), '..'))
 os.environ['GUMP_HOME'] = gumpHome
 os.chdir(gumpHome)



Mime
View raw message