[Swift-commit] r4826 - SwiftApps/GOSwift/pykoa/tools

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Sun Jul 17 13:56:51 CDT 2011


Author: jonmon
Date: 2011-07-17 13:56:51 -0500 (Sun, 17 Jul 2011)
New Revision: 4826

Modified:
   SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
Log:
o Swift is not executed using the subprocess module.  This allows me to write the stdout and stderr as Swift writes to it in the subprocess.
o Cleaned up some imports that I no longer use.


Modified: SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-15 20:30:00 UTC (rev 4825)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-17 18:56:51 UTC (rev 4826)
@@ -1,7 +1,4 @@
 #!/usr/bin/python
-import commands
-import readline
-
 import os
 import re
 import sys
@@ -299,8 +296,8 @@
 	    check_explicit_activate([ep], options.myproxy_host)
 
         cred_file = myproxy.contact_myproxy_server(options.myproxy_host, 
-                options.myproxy_user, options.myproxy_dn,
-                lifetime=options.myproxy_lifetime)
+                                                   options.myproxy_user, options.myproxy_dn,
+                                                   lifetime=options.myproxy_lifetime)
 
         if not cred_file:
             return 1
@@ -321,6 +318,20 @@
 
     return ret
 
+class SwiftObserver(ProcessObserver):
+    def __init__(self):
+        self.lines = []
+
+    def stdout_event(self, line):
+        sys.stdout.write(line)
+        self.lines.append(line)
+        return
+
+    def stderr_event(self, line):
+        sys.stderr.write(line)
+        self.lines.append(line)
+        return
+
 def execute_swift(user_id, options, src_url, src_cred, src_subject, swift_dir, run_directory, home):
 
     if src_subject:
@@ -337,14 +348,30 @@
     os.environ["GLOBUS_SOURCE_PORT_RANGE"] = "50000,51000"
 
     # Execute the script
+    cmd = os.path.join(os.environ["HOME"], "swift-0.92/bin", "swift")
     os.chdir( swift_dir+"/"+run_directory )
-    ( status, output ) = commands.getstatusoutput( home+"/swift-0.92/bin/swift -sites.file sites.xml -tc.file tc -config cf script.swift" )
-    sys.stdout.write( "\nSwift output: " + output + "\n" )
+    execute = cmd + " -sites.file sites.xml -tc.file tc -config cf script.swift"
+
+    pykoa.debug( "running %s" % (execute))
+    try:
+        with BlockInterrupt():
+            p = subprocess.Popen(execute, close_fds=True,
+                                 shell=True, preexec_fn=enable_sigint,
+                                 cwd=os.getcwd(),
+                                 stdout=subprocess.PIPE,
+                                 stderr=subprocess.PIPE)
+
+            c = SwiftObserver()
+            status = c.run(p)
+    finally:
+        if src_cred:
+            os.remove( proxyfile )
+
+    with open( swift_dir+"/"+run_directory+"/swift.out", "w" ) as swift_out:
+        for line in c.lines:
+            swift_out.write( line )
+        
     sys.stdout.write( "Swift exit status: " + str(status) + "\n" )
-
-    if src_cred:
-        os.remove( proxyfile )
-       
     return status
 
 if __name__ == "__main__":




More information about the Swift-commit mailing list