WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH][XM-TEST][2/4] Clean up Console.py

To: Xen Developers <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH][XM-TEST][2/4] Clean up Console.py
From: Dan Smith <danms@xxxxxxxxxx>
Date: Wed, 09 Nov 2005 12:30:12 -0800
Delivery-date: Wed, 09 Nov 2005 20:30:23 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)
Remove semicolons from Console.py.  It's a habit.

Signed-off-by: Dan Smith <danms@xxxxxxxxxx>
# HG changeset patch
# User danms@xxxxxxxxxx
# Node ID e3c6808b2871a6c2c3d19c47bdbfd031e20727de
# Parent  e7aaeeb8c28da6dc07a5907e9557e104024fb00e
Remove semicolons from Console.py.  It's a habit.

diff -r e7aaeeb8c28d -r e3c6808b2871 tools/xm-test/lib/XmTestLib/Console.py
--- a/tools/xm-test/lib/XmTestLib/Console.py    Wed Nov  9 20:03:03 2005
+++ b/tools/xm-test/lib/XmTestLib/Console.py    Wed Nov  9 20:05:41 2005
@@ -23,13 +23,13 @@
      a _very_ specific value, set in the PROMPT
      variable of this script
 """
-import sys;
-import os;
-import pty;
-import tty;
-import termios;
-import fcntl;
-import select;
+import sys
+import os
+import pty
+import tty
+import termios
+import fcntl
+import select
 
 from Test import *
 
@@ -52,15 +52,15 @@
                             are included in the history buffer
         """
 
-        self.TIMEOUT          = 30;
-        self.PROMPT           = "@%@%> ";
-        self.domain           = domain;
-        self.historyBuffer    = [];
-        self.historyLines     = 0;
-        self.historyLimit     = historyLimit;
-        self.historySaveAll   = historySaveAll;
-        self.historySaveCmds  = historySaveCmds;
-        self.debugMe          = False;
+        self.TIMEOUT          = 30
+        self.PROMPT           = "@%@%> "
+        self.domain           = domain
+        self.historyBuffer    = []
+        self.historyLines     = 0
+        self.historyLimit     = historyLimit
+        self.historySaveAll   = historySaveAll
+        self.historySaveCmds  = historySaveCmds
+        self.debugMe          = False
         self.limit            = None
 
         consoleCmd = ["/usr/sbin/xm", "xm", "console", domain]
@@ -68,62 +68,62 @@
         if verbose:
             print "Console executing: " + str(consoleCmd)
 
-        pid, fd = pty.fork();
+        pid, fd = pty.fork()
 
         if pid == 0:
-            os.execvp("/usr/sbin/xm", consoleCmd[1:]);
-
-        self.consolePid = pid;
-        self.consoleFd  = fd;
-
-        tty.setraw(self.consoleFd, termios.TCSANOW);
+            os.execvp("/usr/sbin/xm", consoleCmd[1:])
+
+        self.consolePid = pid
+        self.consoleFd  = fd
+
+        tty.setraw(self.consoleFd, termios.TCSANOW)
             
         bytes = self.__chewall(self.consoleFd)
         if bytes < 0:
             raise ConsoleError("Console didn't respond")
 
     def __addToHistory(self, line):
-        self.historyBuffer.append(line);
-        self.historyLines += 1;
+        self.historyBuffer.append(line)
+        self.historyLines += 1
         if self.historyLines > self.historyLimit:
-            self.historyBuffer = self.historyBuffer[1:];
-            self.historyLines -= 1;
+            self.historyBuffer = self.historyBuffer[1:]
+            self.historyLines -= 1
 
 
     def clearHistory(self):
         """Clear the history buffer"""
-        self.historyBuffer = [];
-        self.historyLines = 0;
+        self.historyBuffer = []
+        self.historyLines = 0
 
 
     def getHistory(self):
         """Returns a string containing the entire history buffer"""
-        output = "";
+        output = ""
 
         for line in self.historyBuffer:
-            output += line + "\n";
-
-        return output;
+            output += line + "\n"
+
+        return output
 
 
     def setTimeout(self, timeout):
         """Sets the timeout used to determine if a remote command
         has blocked"""
-        self.TIMEOUT = timeout;
+        self.TIMEOUT = timeout
 
 
     def setPrompt(self, prompt):
         """Sets the string key used to delimit the end of command
         output"""
-        self.PROMPT = prompt;
+        self.PROMPT = prompt
 
 
     def __chewall(self, fd):
-        timeout = 0;
-        bytes   = 0;
+        timeout = 0
+        bytes   = 0
         
         while timeout < 3:
-            i, o, e = select.select([fd], [], [], 1);
+            i, o, e = select.select([fd], [], [], 1)
             if fd in i:
                 try:
                     foo = os.read(fd, 1)
@@ -143,7 +143,7 @@
         if self.debugMe:
             print "Ignored %i bytes of miscellaneous console output" % bytes
         
-        return bytes;
+        return bytes
 
 
     def __runCmd(self, command, saveHistory=True):
@@ -152,15 +152,15 @@
         lines  = 0
         bytes  = 0
 
-        self.__chewall(self.consoleFd);
+        self.__chewall(self.consoleFd)
 
         if verbose:
             print "[%s] Sending `%s'" % (self.domain, command)
 
-        os.write(self.consoleFd, "%s\n" % command);
+        os.write(self.consoleFd, "%s\n" % command)
 
         while 1==1:
-            i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT);
+            i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT)
 
             if self.consoleFd in i:
                 try:
@@ -182,59 +182,59 @@
                 if lines > 0:
                     output += line + "\n"
                     if saveHistory:
-                        self.__addToHistory(line);
+                        self.__addToHistory(line)
                 elif self.historySaveCmds and saveHistory:
-                    self.__addToHistory("*" + line);
-                lines += 1;
-                line = "";
+                    self.__addToHistory("*" + line)
+                lines += 1
+                line = ""
             elif str == "\r":
                 pass # ignore \r's
             else:
-                line += str;
+                line += str
 
             if line == self.PROMPT:
-                break;
-
-        return output;
+                break
+
+        return output
 
 
     def runCmd(self, command):
         """Runs a command on the remote terminal and returns the output
         as well as the return code.  For example:
         
-        ret = c.runCmd("ls");
-        print ret["output"];
-        sys.exit(run["return"]);
+        ret = c.runCmd("ls")
+        print ret["output"]
+        sys.exit(run["return"])
         
         """
 
         # Allow exceptions to bubble up
-        realOutput = self.__runCmd(command);
-        retOutput  = self.__runCmd("echo $?", saveHistory=False);
+        realOutput = self.__runCmd(command)
+        retOutput  = self.__runCmd("echo $?", saveHistory=False)
 
         try:
-            retCode =  int(retOutput);
+            retCode =  int(retOutput)
         except:
-            retCode = 255;
+            retCode = 255
         return {
             "output": realOutput,
             "return": retCode,
-            };
+            }
 
     def sendInput(self, input):
         """Sends input to the remote terminal, but doesn't check
         for a return code"""
-        realOutput = self.__runCmd(input);
+        realOutput = self.__runCmd(input)
         return {
             "output": realOutput,
             "return": 0,
-            };
+            }
 
     def closeConsole(self):
         """Closes the console connection and ensures that the console
         process is killed"""
-        os.close(self.consoleFd);
-        os.kill(self.consolePid, 2);
+        os.close(self.consoleFd)
+        os.kill(self.consolePid, 2)
 
 
     def setLimit(self, limit):
@@ -254,23 +254,23 @@
     code as the domU command.
     """
 
-    verbose = True;
+    verbose = True
     
     try:
-        t = XmConsole(sys.argv[1]);
+        t = XmConsole(sys.argv[1])
     except ConsoleError, e:
         print "Failed to attach to console (%s)" % str(e)
         sys.exit(255)
 
     try:
-        run = t.runCmd(sys.argv[2]);
+        run = t.runCmd(sys.argv[2])
     except ConsoleError, e:
         print "Console failed (%)" % str(e)
         sys.exit(255)
         
-    t.closeConsole();
+    t.closeConsole()
     
-    print run["output"],;
-    sys.exit(run["return"]);
+    print run["output"],
+    sys.exit(run["return"])
     
         
-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms@xxxxxxxxxx
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH][XM-TEST][2/4] Clean up Console.py, Dan Smith <=