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

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Tue Jul 5 13:01:06 CDT 2011


Author: jonmon
Date: 2011-07-05 13:01:06 -0500 (Tue, 05 Jul 2011)
New Revision: 4765

Modified:
   SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
Log:
o the goswift command now parse the swift package file via stdin(and only stdin)


Modified: SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-05 06:07:34 UTC (rev 4764)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-05 18:01:06 UTC (rev 4765)
@@ -55,7 +55,97 @@
 
     return (parser, options, args)
 
-# Do not know what this syntax is 
+def parse_stdin():
+    lines = []
+    index = 0
+
+    while True:
+        try:
+            lines.append( raw_input() )
+        except EOFError:
+            break
+
+    tc         = extract_tc( lines )
+    sites_file = extract_sites( lines )
+    config     = extract_config( lines )
+    script     = extract_script( lines )
+
+
+    return ( tc, sites_file, config, script )
+
+def extract_tc( lines ):
+    begin_tc = False
+    tc       = ""
+
+    for line in lines:
+ 
+        if line == "# begin tc":
+            begin_tc = True
+
+        elif line == "# end tc":
+            begin_tc = False
+            break
+
+        elif begin_tc:
+            tc += line + "\n"
+    
+    return tc
+
+def extract_sites( lines ):
+    begin_sites = False
+    sites       = ""
+
+    for line in lines:
+ 
+        if line == "# begin sites":
+            begin_sites = True
+
+        elif line == "# end sites":
+            begin_sites = False
+            break
+
+        elif begin_sites:
+            sites += line + "\n"
+    
+    return sites
+
+def extract_config( lines ):
+    begin_config = False
+    config       = ""
+
+    for line in lines:
+ 
+        if line == "# begin config":
+            begin_config = True
+
+        elif line == "# end config":
+            begin_config = False
+            break
+
+        elif begin_config:
+            config += line + "\n"
+    
+    return config
+
+def extract_script( lines ):
+    begin_script = False
+    script       = ""
+
+    for line in lines:
+ 
+        if line == "# begin script":
+            begin_script = True
+
+        elif line == "# end script":
+            begin_script = False
+            break
+
+        elif begin_script:
+            script += line + "\n"
+    
+    return script
+
+# Do not know what this syntax is but pops up in other pykoa_* files.
 @cli_exception_handler
 def main( argv=sys.argv[1:] ):
     (parser, options, args) = setup_opts(argv)
@@ -72,13 +162,19 @@
         parser.print_help()
         return 1
 
+    ( tc, sites_file, config, script ) = parse_stdin()
+
     # get a space seperated list of the sites to execute on
     sites=" ".join( map ( str, args ) )
     sys.stdout.write( "\nExecuting Swift on: " + sites + "\n" )
 
     # If I do not execute the script, just print out all pertatent information
     if options.do_not_execute:
-        sys.stdout.write( "swift -sites.file sites.xml -tc.file tc -config cf -cdm.file cdm script.swift\n\n" )
+        sys.stdout.write( "\nTC file: \n" + tc + "\n" )
+        sys.stdout.write( "SITES file: \n" + sites_file + "\n" )
+        sys.stdout.write( "CONFIG file: \n" + config + "\n" )
+        sys.stdout.write( "SWIFTSCRIPT file: \n" + script + "\n" )
+        sys.stdout.write( "swift -sites.file sites.xml -tc.file tc -config cf script.swift\n\n" )
         return 0
 
     # Execute the script




More information about the Swift-commit mailing list