ia64/xen-unstable

changeset 708:5627b762b3be

bitkeeper revision 1.418.1.2 (3f5f3d9cLa8n-CecxQixtspMMc7QAw)

ParseScript.java:
new file
author tlh20@labyrinth.cl.cam.ac.uk
date Wed Sep 10 15:05:00 2003 +0000 (2003-09-10)
parents c336be9fa2b2
children ad58e3192187 79f86eafbcdd
files .rootkeys tools/control/src/org/xenoserver/cmdline/ParseScript.java
line diff
     1.1 --- a/.rootkeys	Wed Sep 10 15:04:38 2003 +0000
     1.2 +++ b/.rootkeys	Wed Sep 10 15:05:00 2003 +0000
     1.3 @@ -28,6 +28,7 @@ 3f05631djnPcaqmzMFSa8RLmGCZ-0Q tools/con
     1.4  3f05631dswxJX_TpcuG6tBstyHSetg tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
     1.5  3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
     1.6  3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
     1.7 +3f5f3d95BlaPZ2JHfpjHuHscx2SJow tools/control/src/org/xenoserver/cmdline/ParseScript.java
     1.8  3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
     1.9  3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
    1.10  3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseScript.java	Wed Sep 10 15:05:00 2003 +0000
     2.3 @@ -0,0 +1,79 @@
     2.4 +package org.xenoserver.cmdline;
     2.5 +
     2.6 +import java.util.Iterator;
     2.7 +import java.util.LinkedList;
     2.8 +import java.util.StringTokenizer;
     2.9 +
    2.10 +import java.io.BufferedReader;
    2.11 +import java.io.FileReader;
    2.12 +import java.io.Reader;
    2.13 +import java.io.InputStreamReader;
    2.14 +import java.io.IOException;
    2.15 +
    2.16 +import org.xenoserver.control.CommandFailedException;
    2.17 +import org.xenoserver.control.Defaults;
    2.18 +import org.xenoserver.control.Extent;
    2.19 +import org.xenoserver.control.Library;
    2.20 +import org.xenoserver.control.Settings;
    2.21 +import org.xenoserver.control.VirtualDisk;
    2.22 +import org.xenoserver.control.VirtualDiskManager;
    2.23 +
    2.24 +public class ParseScript extends CommandParser {
    2.25 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    2.26 +    String filename = getStringParameter(args,'f',null);
    2.27 +
    2.28 +    try
    2.29 +      {
    2.30 +	Reader r;
    2.31 +	BufferedReader br;
    2.32 +	String next_line;
    2.33 +	boolean stdin;
    2.34 +
    2.35 +	if (filename == null) {
    2.36 +	  r = new InputStreamReader (System.in);
    2.37 +	  stdin = true;
    2.38 +	} else {
    2.39 +	  r = new FileReader (filename);
    2.40 +	  stdin = false;
    2.41 +	}
    2.42 +	br = new BufferedReader (r);
    2.43 +	
    2.44 +	if (stdin) prompt();
    2.45 +	while ((next_line = br.readLine()) != null) 
    2.46 +	  {
    2.47 +	    StringTokenizer tok = new StringTokenizer(next_line, " ");
    2.48 +	    LinkedList arglist = new LinkedList();
    2.49 +	    while (tok.hasMoreTokens()) {
    2.50 +	      arglist.add (tok.nextToken ());
    2.51 +	    }
    2.52 +	    Main.executeArgList (d, arglist);
    2.53 +	    if (stdin) prompt();
    2.54 +	  }
    2.55 +      }
    2.56 +    catch (IOException ioe)
    2.57 +      {
    2.58 +	throw new ParseFailedException ("Could not read script \"" + filename + "\"", ioe);
    2.59 +      }
    2.60 +  }
    2.61 +
    2.62 +  void prompt() {
    2.63 +    System.out.print ("$ ");
    2.64 +    System.out.flush ();
    2.65 +  }
    2.66 +
    2.67 +  public String getName() {
    2.68 +    return "script";
    2.69 +  }
    2.70 +
    2.71 +  public String getUsage() {
    2.72 +    return "[-f<filename>]";
    2.73 +  }
    2.74 +
    2.75 +  public String getHelpText() {
    2.76 +    return ("Execute a series of xenctl command lines found in the specified file\n" +
    2.77 +	    "(or from standard input if no filename is given).  Execution terminates\n" +
    2.78 +	    "if any command fails.  If a command requires a domain ID then, if\n" +
    2.79 +	    "ommitted, the domain most recently created by the script will be used\n" +
    2.80 +	    "by default.\n");
    2.81 +  }
    2.82 +}