diff options
author | tlh20@labyrinth.cl.cam.ac.uk <tlh20@labyrinth.cl.cam.ac.uk> | 2003-09-10 15:05:00 +0000 |
---|---|---|
committer | tlh20@labyrinth.cl.cam.ac.uk <tlh20@labyrinth.cl.cam.ac.uk> | 2003-09-10 15:05:00 +0000 |
commit | 81b68e2240a539b0b0dbb65e7d97c0f444e62096 (patch) | |
tree | 2dfb33013a11357e86ca45d94f7c99b0a70a9017 /tools | |
parent | 4035ab506dcfe600764bc79b73616bdc876075ad (diff) | |
download | xen-81b68e2240a539b0b0dbb65e7d97c0f444e62096.tar.gz xen-81b68e2240a539b0b0dbb65e7d97c0f444e62096.tar.bz2 xen-81b68e2240a539b0b0dbb65e7d97c0f444e62096.zip |
bitkeeper revision 1.418.1.2 (3f5f3d9cLa8n-CecxQixtspMMc7QAw)
ParseScript.java:
new file
Diffstat (limited to 'tools')
-rw-r--r-- | tools/control/src/org/xenoserver/cmdline/ParseScript.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseScript.java b/tools/control/src/org/xenoserver/cmdline/ParseScript.java new file mode 100644 index 0000000000..061af93128 --- /dev/null +++ b/tools/control/src/org/xenoserver/cmdline/ParseScript.java @@ -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"); + } +} |