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

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Tue Aug 2 10:44:34 CDT 2011


Author: jonmon
Date: 2011-08-02 10:44:33 -0500 (Tue, 02 Aug 2011)
New Revision: 4929

Modified:
   SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py
Log:
o use the subprocess module instead of the commands moudle in koa_goswift_stat.py
o use os.access to check for existence in koa_goswift_stat.py
o removed the '-n' option, could not make it work at the moment in koa_goswift_stat.py



Modified: SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py	2011-08-02 15:42:48 UTC (rev 4928)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift_stat.py	2011-08-02 15:44:33 UTC (rev 4929)
@@ -1,9 +1,7 @@
 #!/usr/bin/python
-import commands
-
 import os
 import sys
-
+import subprocess
 import pykoa
 import pykoa.tools
 from pykoa.koaexception import cli_exception_handler
@@ -14,7 +12,7 @@
 
 Checks the status of a run started in the background using goswift by reading the last n lines of the stdout/stderr file. Only 1 run is allowed to get the status of at a time.
 
-Default number of lines is 10. This can be controlled by the -n option.
+Default number of lines is 50.
 
 Type 'man goswift_stat' for details. \
 """
@@ -22,12 +20,8 @@
     parser = pykoa.tools.get_option_parser(help_screen)
     parser.add_option("--debug", dest="debugging",
                       default=False, action="store_true",
-                      help="Get status from the last n lines of the Swift log file. See ")
+                      help="Get status from the last 50 lines of the Swift log file.")
 
-    parser.add_option("-n", dest="lines",
-                      default=10, action="store_true",
-                      help="Controls the number of lines to print from the swift log file or the stdout/stderr file.")
-
     (options, args) = pykoa.tools.parse_args(parser, argv)
 
     return (parser, options, args)
@@ -43,8 +37,14 @@
     status = 0
     home = os.environ["HOME"]
     swift_dir = home +"/Swift"
+
+    if not os.access( swift_dir, os.F_OK ):
+        sys.stderr.write( "Swift has not been run on this machine before.: "+swift_dir+" does not exist\n")
+        return 1
+
     work_dir = ""
 
+    # Get the work directory
     try:
         work_dir = "run."+str(int(args[0]))
     except ValueError:
@@ -52,37 +52,29 @@
         return 1
 
     run_dir = swift_dir + "/" + work_dir
-    if not os.path.isdir( run_dir ):
+    if not os.access( run_dir, os.F_OK ):
         sys.stderr.write( run_dir+" does not exist!\n" )
         return 1
 
+    # output from the log file if the log file exists
     if options.debugging:
-        if not os.path.isfile( run_dir+"/script-"+args[0]+".log"):
+        if not os.access( run_dir+"/script-"+args[0]+".log", os.F_OK):
             sys.stderr.write( run_dir+"/script-"+args[0]+".log does not exitst!\n" )
             return 1
 
-        try:
-            int(options.lines)
-        except ValueError:
-            sys.stderr.write( "The option passed to -n is not a number: "+option.lines )
-            return 1
-
-        (status, output) = commands.getstatusoutput( "tail -"+str(options.lines)+" "+run_dir+"/script-"+args[0]+".log" )
-        sys.stdout.write(output+"\n")
+        cmd = "tail -"+str(50)+" "+run_dir+"/script-"+args[0]+".log"
+        status = subprocess.call( cmd, close_fds=True,
+                                  shell=True )
+    # output from the swift.out file if it exists
     else:
-        if not os.path.isfile( run_dir+"/swift.out"):
+        if not os.access( run_dir+"/swift.out", os.F_OK):
             sys.stderr.write( run_dir+"/swift.out does not exitst!\n" )
             return 1
 
-        try:
-            int(options.lines)
-        except ValueError:
-            sys.stderr.write( "The option passed to -n is not a number: "+option.lines )
-            return 1
-
-        (status, output) = commands.getstatusoutput( "tail -"+str(options.lines)+" "+run_dir+"/swift.out" )
-        sys.stdout.write(output+"\n")
-
+        cmd = "tail -"+str(50)+" "+run_dir+"/swift.out"
+        status = subprocess.call( cmd, close_fds=True,
+                                  shell=True )
+           
     return status
     
 if __name__ == "__main__":




More information about the Swift-commit mailing list