Author: scooter
Date: 2011-03-16 05:32:31 -0700 (Wed, 16 Mar 2011)
New Revision: 24445

Modified:
   
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/handlers/CommandToolHandler.java
Log:
Added loop argument


Modified: 
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/handlers/CommandToolHandler.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/handlers/CommandToolHandler.java
   2011-03-16 00:14:33 UTC (rev 24444)
+++ 
csplugins/trunk/ucsf/scooter/commandTool/src/commandTool/handlers/CommandToolHandler.java
   2011-03-16 12:32:31 UTC (rev 24445)
@@ -35,6 +35,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.io.IOException;
 
 import java.util.Collection;
 import java.util.List;
@@ -57,6 +58,7 @@
 public class CommandToolHandler extends AbstractCommandHandler {
        private static String DURATION = "duration";
        private static String FILE = "file";
+       private static String LOOP = "loop";
        private static String MESSAGE = "message";
        private static String PAUSE = "pause";
        private static String RUN = "run";
@@ -64,12 +66,13 @@
 
        public CommandToolHandler() {
                super(CyCommandManager.reserveNamespace("commandTool"));
+               addDescription(PAUSE, "Pause and wait for user input");
+               addArgument(PAUSE, MESSAGE, "Press OK to proceed");
                addDescription(RUN, "Run a command script from a file");
                addArgument(RUN,FILE);
+               addArgument(RUN,LOOP);
                addDescription(SLEEP, "Sleep for a certain number of seconds");
                addArgument(SLEEP,DURATION);
-               addDescription(PAUSE, "Pause and wait for user input");
-               addArgument(PAUSE, MESSAGE, "Press OK to proceed");
        }
 
        public CyCommandResult execute(String command, Collection<Tunable>args)
@@ -81,17 +84,32 @@
                                 throws CyCommandException {
                CyCommandResult result = new CyCommandResult();
                if (command.equalsIgnoreCase(RUN)) {
+                       int loopCount = 1;
                        if (!args.containsKey(FILE))
                                throw new RuntimeException(RUN+" command 
requires a 'file' argument");
 
+                       if (args.containsKey(LOOP)) {
+                               try {
+                                       loopCount = 
Integer.parseInt(args.get(LOOP).toString());
+                               } catch (NumberFormatException nfe) {
+                                       throw new RuntimeException(RUN+" loop 
argument requires an integer value");
+                               }
+                       }
+
                        File inputFile = null;
                        try {
                                inputFile = new File(args.get(FILE).toString());
-                               CommandHandler.handleCommandFile(new 
FileReader(inputFile), args);
+                               do {
+                                       FileReader reader = new 
FileReader(inputFile);
+                                       
CommandHandler.handleCommandFile(reader, args);
+                                       reader.close();
+                               } while (--loopCount != 0);
        
                                result.addMessage("Completed execution of 
"+inputFile.toString());
                        } catch (FileNotFoundException e) {
                                throw new RuntimeException("Unable to open file 
"+inputFile.toString());
+                       } catch (IOException ioe) {
+                               throw new RuntimeException("IO Error: 
"+ioe.getMessage());
                        }
                } else if (command.equalsIgnoreCase(SLEEP)) {
                        if (!args.containsKey(DURATION))

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to