bitkeeper revision 1.418.1.2 (3f5f3d9cLa8n-CecxQixtspMMc7QAw)
authortlh20@labyrinth.cl.cam.ac.uk <tlh20@labyrinth.cl.cam.ac.uk>
Wed, 10 Sep 2003 15:05:00 +0000 (15:05 +0000)
committertlh20@labyrinth.cl.cam.ac.uk <tlh20@labyrinth.cl.cam.ac.uk>
Wed, 10 Sep 2003 15:05:00 +0000 (15:05 +0000)
ParseScript.java:
  new file

.rootkeys
tools/control/src/org/xenoserver/cmdline/ParseScript.java [new file with mode: 0644]

index 6d3796d221ec78923a90b910e218126378b98669..2409b7b4cc5b861628379c9d3aa19d2335907228 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -28,6 +28,7 @@
 3f05631dswxJX_TpcuG6tBstyHSetg tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
 3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
 3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
+3f5f3d95BlaPZ2JHfpjHuHscx2SJow tools/control/src/org/xenoserver/cmdline/ParseScript.java
 3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
 3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
 3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseScript.java b/tools/control/src/org/xenoserver/cmdline/ParseScript.java
new file mode 100644 (file)
index 0000000..061af93
--- /dev/null
@@ -0,0 +1,79 @@
+package org.xenoserver.cmdline;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.StringTokenizer;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.Reader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.Defaults;
+import org.xenoserver.control.Extent;
+import org.xenoserver.control.Library;
+import org.xenoserver.control.Settings;
+import org.xenoserver.control.VirtualDisk;
+import org.xenoserver.control.VirtualDiskManager;
+
+public class ParseScript extends CommandParser {
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    String filename = getStringParameter(args,'f',null);
+
+    try
+      {
+       Reader r;
+       BufferedReader br;
+       String next_line;
+       boolean stdin;
+
+       if (filename == null) {
+         r = new InputStreamReader (System.in);
+         stdin = true;
+       } else {
+         r = new FileReader (filename);
+         stdin = false;
+       }
+       br = new BufferedReader (r);
+       
+       if (stdin) prompt();
+       while ((next_line = br.readLine()) != null) 
+         {
+           StringTokenizer tok = new StringTokenizer(next_line, " ");
+           LinkedList arglist = new LinkedList();
+           while (tok.hasMoreTokens()) {
+             arglist.add (tok.nextToken ());
+           }
+           Main.executeArgList (d, arglist);
+           if (stdin) prompt();
+         }
+      }
+    catch (IOException ioe)
+      {
+       throw new ParseFailedException ("Could not read script \"" + filename + "\"", ioe);
+      }
+  }
+
+  void prompt() {
+    System.out.print ("$ ");
+    System.out.flush ();
+  }
+
+  public String getName() {
+    return "script";
+  }
+
+  public String getUsage() {
+    return "[-f<filename>]";
+  }
+
+  public String getHelpText() {
+    return ("Execute a series of xenctl command lines found in the specified file\n" +
+           "(or from standard input if no filename is given).  Execution terminates\n" +
+           "if any command fails.  If a command requires a domain ID then, if\n" +
+           "ommitted, the domain most recently created by the script will be used\n" +
+           "by default.\n");
+  }
+}