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

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Thu Jul 28 13:31:33 CDT 2011


Author: jonmon
Date: 2011-07-28 13:31:33 -0500 (Thu, 28 Jul 2011)
New Revision: 4865

Added:
   SwiftApps/GOSwift/pykoa/tools/koa_goswift_info.py
Modified:
   SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
   SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py
Log:
o added goswift_info command. This command will print information that the user requests about a certain run.
o removed unnecessary imports fomr koa_goswift_stat.py
o the goswift command not writes an info file containing certain information about a run.



Modified: SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-28 17:22:24 UTC (rev 4864)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-28 18:31:33 UTC (rev 4865)
@@ -26,12 +26,10 @@
 
     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 setup_opts(argv):
@@ -273,22 +271,26 @@
 
     # Execute the script
     cmd = os.path.join(os.environ["HOME"], "Swift_lib/swift-0.92/bin", "swift")
+
     os.chdir(work_directory)
-    execute = cmd + " -runid "+str(run_id)+" -sites.file sites.xml -tc.file tc -config cf script.swift 2>&1 | tee -a swift.out"
-    status = 0
+    status = -1
+    pid = -1
 
     if options.watch_swift_stdoutput:
-        pykoa.debug( "running %s in watch mode" % (execute))
         try:
             with BlockInterrupt():
-                p = subprocess.Popen(execute, close_fds=True,
-                                     shell=True, preexec_fn=enable_sigint,
+                execute = cmd + " -runid "+str(run_id)+" -sites.file sites.xml -tc.file tc -config cf script.swift 2>&1 | tee -a swift.out"
+                pykoa.debug( "running %s in watch mode" % (execute))
+                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)
+                pid = p.pid
         finally:
             if src_cred:
                 os.remove( proxyfile )
@@ -296,13 +298,22 @@
         sys.stdout.write( "Swift exit status: " + str(status) + "\n" )
 
     else:
+        execute = cmd + " -runid "+str(run_id)+" -sites.file sites.xml -tc.file tc -config cf script.swift &>>swift.out"
         pykoa.debug( "running %s in background mode" % (execute))
         p = subprocess.Popen(execute, close_fds=True,
                              shell=True, preexec_fn=enable_sigint,
                              cwd=os.getcwd(),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)        
+        pid = p.pid
 
+    with open("swift.info", "w") as swift_info:
+        swift_info.write("StartTime: "+str(datetime.datetime.utcnow())+"\n")
+        swift_info.write("Swift pid: "+str(pid)+"\n")
+        swift_info.write("Run id:    "+str(run_id)+"\n")
+        swift_info.write("\n")
+        swift_info.write("Command Line:\n     "+execute+"\n")
+
     return status
 
 def create_work_directory():
@@ -344,7 +355,7 @@
     (parser, options, args) = setup_opts(argv)
 
     # If I did not specify at least one site, print help message
-    if len(args) < 1:
+    if len(args) != 1:
         parser.print_help()
         return 1
 
@@ -362,7 +373,7 @@
 
     # get a space seperated String of the sites to execute on
     execution_sites=" ".join( map ( str, args ) )
-    sys.stdout.write( "\nExecuting Swift on: " + execution_sites + "\n" )
+    sys.stdout.write( "\nExecuting Swift with " + execution_sites + " credentials\n" )
     sys.stdout.write( "Execution directory: " + work_directory + "\n" )
 
     # If I do not execute the script, just print out all important information

Added: SwiftApps/GOSwift/pykoa/tools/koa_goswift_info.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift_info.py	                        (rev 0)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift_info.py	2011-07-28 18:31:33 UTC (rev 4865)
@@ -0,0 +1,149 @@
+#!/usr/bin/python
+import commands
+
+import os
+import re
+import sys
+import subprocess
+import datetime
+
+from sqlalchemy.sql import text
+
+import pykoa
+import pykoa.tools
+from pykoa.process_observer import ProcessObserver
+from pykoa.signal_util import BlockInterrupt, enable_sigint
+from pykoa.tools import url_parse, myproxy
+from pykoa.tools import koa_transfer
+from pykoa.tools.koa_ep_activate import check_explicit_activate
+from pykoa.consumers import guc_util
+from pykoa.constants import get_scheme
+from pykoa.data import endpoint_dao
+from pykoa.data import creds_dao
+from pykoa.koaexception import ToolsException, cli_exception_handler
+
+def setup_opts(argv):
+    help_screen = """
+goswift_info [options] <run-number>
+
+Report information about a swiftrun, such as what is in the info file, tc file, sites file, and config file.
+
+At least one options must be specified.
+
+Type 'man goswift_info' for details. \
+"""
+
+    parser = pykoa.tools.get_option_parser(help_screen)
+    parser.add_option("--tc", dest="tc",
+                       default=False, action="store_true",
+                       help="Print the entire tc file that was used during the run")
+
+    parser.add_option("--sites", dest="sites",
+                      default=False, action="store_true",
+                      help="Print the entire sites file that was used during the run")
+
+    parser.add_option("--config", dest="config",
+                      default=False, action="store_true",
+                      help="Print the entire config file that was used during the run")
+
+    parser.add_option("--script", dest="script",
+                      default=False, action="store_true",
+                      help="Print the entire script file that was used during the run")
+
+    parser.add_option("--info", dest="info",
+                      default=False, action="store_true",
+                      help="Print the info file that was created for the run")
+
+    parser.add_option("--all", dest="all",
+                      default=False, action="store_true",
+                      help="Print all file that were used during the run")
+
+    (options, args) = pykoa.tools.parse_args(parser, argv)
+
+    return (parser, options, args)
+
+def print_info(run_id):
+    run_directory = os.environ["HOME"]+"/Swift/run."+str(run_id);
+    sys.stdout.write("--------------BEGIN INFO FILE----------------\n")
+    with open(run_directory+"/swift.info", "r") as swift_info:
+        for line in swift_info.readlines():
+            sys.stdout.write(line)
+    sys.stdout.write("--------------END INFO FILE----------------\n\n")
+    return 0
+
+def print_tc(run_id):
+    run_directory = os.environ["HOME"]+"/Swift/run."+str(run_id);
+    sys.stdout.write("--------------BEGIN TC FILE-------------------\n")
+    with open(run_directory+"/tc", "r") as swift_tc:
+        for line in swift_tc.readlines():
+            sys.stdout.write(line)
+    sys.stdout.write("--------------END TC FILE-------------------\n\n")
+    return 0
+
+def print_sites(run_id):
+    run_directory = os.environ["HOME"]+"/Swift/run."+str(run_id);
+    sys.stdout.write("--------------BEGIN SITES FILE---------------\n")
+    with open(run_directory+"/sites.xml", "r") as swift_sites:
+        for line in swift_sites.readlines():
+            sys.stdout.write(line)
+    sys.stdout.write("--------------END SITES FILE---------------\n\n")
+    return 0
+
+def print_config(run_id):
+    run_directory = os.environ["HOME"]+"/Swift/run."+str(run_id);
+    sys.stdout.write("--------------BEGIN CONFIG FILE--------------\n")
+    with open(run_directory+"/cf", "r") as swift_config:
+        for line in swift_config.readlines():
+            sys.stdout.write(line)
+    sys.stdout.write("--------------END CONFIG FILE--------------\n\n")
+    return 0
+
+def print_script(run_id):
+    run_directory = os.environ["HOME"]+"/Swift/run."+str(run_id);
+    sys.stdout.write("--------------BEGIN SCRIPT FILE--------------\n")
+    with open(run_directory+"/script.swift", "r") as swift_script:
+        for line in swift_script.readlines():
+            sys.stdout.write(line)
+    sys.stdout.write("--------------END SCRIPT FILE--------------\n\n")
+    return 0
+
+
+ at cli_exception_handler
+def main( argv=sys.argv[1:] ):
+    (parser, options, args) = setup_opts(argv)
+
+    if len(args) != 1:
+        parser.print_help()
+        return 1
+
+    if options.all:
+        print_info(args[0])
+        print_tc(args[0])
+        print_sites(args[0])
+        print_config(args[0])
+        print_script(args[0])
+        return 0
+
+    if options.info:
+        print_info(args[0])
+
+    if options.tc:
+        print_tc(args[0])
+
+    if options.sites:
+        print_sites(args[0])
+    
+    if options.config:
+        print_config(args[0])
+
+    if options.script:
+        print_script(args[0])
+
+    if not options.info and not options.tc and not options.sites and not options.config and not options.script:
+        sys.stderr.write("Please specify at least one options. Type 'help goswift_info' for a list of valid options\n")
+
+    return 0
+
+if __name__ == "__main__":
+    rc = main()
+    sys.exit(rc)


Property changes on: SwiftApps/GOSwift/pykoa/tools/koa_goswift_info.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py	2011-07-28 17:22:24 UTC (rev 4864)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py	2011-07-28 18:31:33 UTC (rev 4865)
@@ -2,25 +2,11 @@
 import commands
 
 import os
-import re
 import sys
-import subprocess
-import datetime
 
-from sqlalchemy.sql import text
-
 import pykoa
 import pykoa.tools
-from pykoa.process_observer import ProcessObserver
-from pykoa.signal_util import BlockInterrupt, enable_sigint
-from pykoa.tools import url_parse, myproxy
-from pykoa.tools import koa_transfer
-from pykoa.tools.koa_ep_activate import check_explicit_activate
-from pykoa.consumers import guc_util
-from pykoa.constants import get_scheme
-from pykoa.data import endpoint_dao
-from pykoa.data import creds_dao
-from pykoa.koaexception import ToolsException, cli_exception_handler
+from pykoa.koaexception import cli_exception_handler
 
 def setup_opts(argv):
     help_screen = """




More information about the Swift-commit mailing list