direct-io.hg
changeset 7721:3920df5da25e
Remove semicolons from Console.py. It's a habit.
author | danms@us.ibm.com |
---|---|
date | Thu Nov 10 11:47:27 2005 +0100 (2005-11-10) |
parents | 8a5dca8c1e8f |
children | 2bcfd776cb7f |
files | tools/xm-test/lib/XmTestLib/Console.py |
line diff
1.1 --- a/tools/xm-test/lib/XmTestLib/Console.py Thu Nov 10 11:43:26 2005 +0100 1.2 +++ b/tools/xm-test/lib/XmTestLib/Console.py Thu Nov 10 11:47:27 2005 +0100 1.3 @@ -23,13 +23,13 @@ 1.4 a _very_ specific value, set in the PROMPT 1.5 variable of this script 1.6 """ 1.7 -import sys; 1.8 -import os; 1.9 -import pty; 1.10 -import tty; 1.11 -import termios; 1.12 -import fcntl; 1.13 -import select; 1.14 +import sys 1.15 +import os 1.16 +import pty 1.17 +import tty 1.18 +import termios 1.19 +import fcntl 1.20 +import select 1.21 1.22 from Test import * 1.23 1.24 @@ -52,15 +52,15 @@ class XmConsole: 1.25 are included in the history buffer 1.26 """ 1.27 1.28 - self.TIMEOUT = 30; 1.29 - self.PROMPT = "@%@%> "; 1.30 - self.domain = domain; 1.31 - self.historyBuffer = []; 1.32 - self.historyLines = 0; 1.33 - self.historyLimit = historyLimit; 1.34 - self.historySaveAll = historySaveAll; 1.35 - self.historySaveCmds = historySaveCmds; 1.36 - self.debugMe = False; 1.37 + self.TIMEOUT = 30 1.38 + self.PROMPT = "@%@%> " 1.39 + self.domain = domain 1.40 + self.historyBuffer = [] 1.41 + self.historyLines = 0 1.42 + self.historyLimit = historyLimit 1.43 + self.historySaveAll = historySaveAll 1.44 + self.historySaveCmds = historySaveCmds 1.45 + self.debugMe = False 1.46 self.limit = None 1.47 1.48 consoleCmd = ["/usr/sbin/xm", "xm", "console", domain] 1.49 @@ -68,62 +68,62 @@ class XmConsole: 1.50 if verbose: 1.51 print "Console executing: " + str(consoleCmd) 1.52 1.53 - pid, fd = pty.fork(); 1.54 + pid, fd = pty.fork() 1.55 1.56 if pid == 0: 1.57 - os.execvp("/usr/sbin/xm", consoleCmd[1:]); 1.58 + os.execvp("/usr/sbin/xm", consoleCmd[1:]) 1.59 1.60 - self.consolePid = pid; 1.61 - self.consoleFd = fd; 1.62 + self.consolePid = pid 1.63 + self.consoleFd = fd 1.64 1.65 - tty.setraw(self.consoleFd, termios.TCSANOW); 1.66 + tty.setraw(self.consoleFd, termios.TCSANOW) 1.67 1.68 bytes = self.__chewall(self.consoleFd) 1.69 if bytes < 0: 1.70 raise ConsoleError("Console didn't respond") 1.71 1.72 def __addToHistory(self, line): 1.73 - self.historyBuffer.append(line); 1.74 - self.historyLines += 1; 1.75 + self.historyBuffer.append(line) 1.76 + self.historyLines += 1 1.77 if self.historyLines > self.historyLimit: 1.78 - self.historyBuffer = self.historyBuffer[1:]; 1.79 - self.historyLines -= 1; 1.80 + self.historyBuffer = self.historyBuffer[1:] 1.81 + self.historyLines -= 1 1.82 1.83 1.84 def clearHistory(self): 1.85 """Clear the history buffer""" 1.86 - self.historyBuffer = []; 1.87 - self.historyLines = 0; 1.88 + self.historyBuffer = [] 1.89 + self.historyLines = 0 1.90 1.91 1.92 def getHistory(self): 1.93 """Returns a string containing the entire history buffer""" 1.94 - output = ""; 1.95 + output = "" 1.96 1.97 for line in self.historyBuffer: 1.98 - output += line + "\n"; 1.99 + output += line + "\n" 1.100 1.101 - return output; 1.102 + return output 1.103 1.104 1.105 def setTimeout(self, timeout): 1.106 """Sets the timeout used to determine if a remote command 1.107 has blocked""" 1.108 - self.TIMEOUT = timeout; 1.109 + self.TIMEOUT = timeout 1.110 1.111 1.112 def setPrompt(self, prompt): 1.113 """Sets the string key used to delimit the end of command 1.114 output""" 1.115 - self.PROMPT = prompt; 1.116 + self.PROMPT = prompt 1.117 1.118 1.119 def __chewall(self, fd): 1.120 - timeout = 0; 1.121 - bytes = 0; 1.122 + timeout = 0 1.123 + bytes = 0 1.124 1.125 while timeout < 3: 1.126 - i, o, e = select.select([fd], [], [], 1); 1.127 + i, o, e = select.select([fd], [], [], 1) 1.128 if fd in i: 1.129 try: 1.130 foo = os.read(fd, 1) 1.131 @@ -143,7 +143,7 @@ class XmConsole: 1.132 if self.debugMe: 1.133 print "Ignored %i bytes of miscellaneous console output" % bytes 1.134 1.135 - return bytes; 1.136 + return bytes 1.137 1.138 1.139 def __runCmd(self, command, saveHistory=True): 1.140 @@ -152,15 +152,15 @@ class XmConsole: 1.141 lines = 0 1.142 bytes = 0 1.143 1.144 - self.__chewall(self.consoleFd); 1.145 + self.__chewall(self.consoleFd) 1.146 1.147 if verbose: 1.148 print "[%s] Sending `%s'" % (self.domain, command) 1.149 1.150 - os.write(self.consoleFd, "%s\n" % command); 1.151 + os.write(self.consoleFd, "%s\n" % command) 1.152 1.153 while 1==1: 1.154 - i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT); 1.155 + i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT) 1.156 1.157 if self.consoleFd in i: 1.158 try: 1.159 @@ -182,59 +182,59 @@ class XmConsole: 1.160 if lines > 0: 1.161 output += line + "\n" 1.162 if saveHistory: 1.163 - self.__addToHistory(line); 1.164 + self.__addToHistory(line) 1.165 elif self.historySaveCmds and saveHistory: 1.166 - self.__addToHistory("*" + line); 1.167 - lines += 1; 1.168 - line = ""; 1.169 + self.__addToHistory("*" + line) 1.170 + lines += 1 1.171 + line = "" 1.172 elif str == "\r": 1.173 pass # ignore \r's 1.174 else: 1.175 - line += str; 1.176 + line += str 1.177 1.178 if line == self.PROMPT: 1.179 - break; 1.180 + break 1.181 1.182 - return output; 1.183 + return output 1.184 1.185 1.186 def runCmd(self, command): 1.187 """Runs a command on the remote terminal and returns the output 1.188 as well as the return code. For example: 1.189 1.190 - ret = c.runCmd("ls"); 1.191 - print ret["output"]; 1.192 - sys.exit(run["return"]); 1.193 + ret = c.runCmd("ls") 1.194 + print ret["output"] 1.195 + sys.exit(run["return"]) 1.196 1.197 """ 1.198 1.199 # Allow exceptions to bubble up 1.200 - realOutput = self.__runCmd(command); 1.201 - retOutput = self.__runCmd("echo $?", saveHistory=False); 1.202 + realOutput = self.__runCmd(command) 1.203 + retOutput = self.__runCmd("echo $?", saveHistory=False) 1.204 1.205 try: 1.206 - retCode = int(retOutput); 1.207 + retCode = int(retOutput) 1.208 except: 1.209 - retCode = 255; 1.210 + retCode = 255 1.211 return { 1.212 "output": realOutput, 1.213 "return": retCode, 1.214 - }; 1.215 + } 1.216 1.217 def sendInput(self, input): 1.218 """Sends input to the remote terminal, but doesn't check 1.219 for a return code""" 1.220 - realOutput = self.__runCmd(input); 1.221 + realOutput = self.__runCmd(input) 1.222 return { 1.223 "output": realOutput, 1.224 "return": 0, 1.225 - }; 1.226 + } 1.227 1.228 def closeConsole(self): 1.229 """Closes the console connection and ensures that the console 1.230 process is killed""" 1.231 - os.close(self.consoleFd); 1.232 - os.kill(self.consolePid, 2); 1.233 + os.close(self.consoleFd) 1.234 + os.kill(self.consolePid, 2) 1.235 1.236 1.237 def setLimit(self, limit): 1.238 @@ -254,23 +254,23 @@ if __name__ == "__main__": 1.239 code as the domU command. 1.240 """ 1.241 1.242 - verbose = True; 1.243 + verbose = True 1.244 1.245 try: 1.246 - t = XmConsole(sys.argv[1]); 1.247 + t = XmConsole(sys.argv[1]) 1.248 except ConsoleError, e: 1.249 print "Failed to attach to console (%s)" % str(e) 1.250 sys.exit(255) 1.251 1.252 try: 1.253 - run = t.runCmd(sys.argv[2]); 1.254 + run = t.runCmd(sys.argv[2]) 1.255 except ConsoleError, e: 1.256 print "Console failed (%)" % str(e) 1.257 sys.exit(255) 1.258 1.259 - t.closeConsole(); 1.260 + t.closeConsole() 1.261 1.262 - print run["output"],; 1.263 - sys.exit(run["return"]); 1.264 + print run["output"], 1.265 + sys.exit(run["return"]) 1.266 1.267