def _wait_for_init(self, line): data = OneOrMore(nestedExpr()).parseString(line) lst = data.asList() print "state 0:", lst if lst[0][0] == "get-session-id": global g_next_session_id self._session_id = g_next_session_id g_next_session_id += 1 self._initSolver(self._session_id) self.sendLine("%d" % (self._session_id)) self._state = 1 elif lst[0][0] == "set-session-id": self._session_id = long(lst[0][1]) #Find an existing solver instance if not self._session_id in g_solver_instances: self.sendLine("No such session") self.transport.loseConnection() else: self._initSolver(self._session_id) self.sendLine("%d" % (self._session_id)) self._state = 1 else: self.sendLine("Invalid command " + line + ", was expecting get-session-id or set-session-id") self.transport.loseConnection()
def lineReceived(self, line): print ">>", line if line == "sat": self._state = 1 self._outputLine(line) elif line == "unsat": self._outputLine(line) else: if self._state != 1: #This must be an error print ">>Not sat or unsat, must be an error" self.__outputLine(line) else: #Receive the solutions data = OneOrMore(nestedExpr()).parseString(line) lst = data.asList() #print lst try: #[[[['select', 'arr1', ['_', 'bv1', '32']], '#x7b']]] varname = lst[0][0][0][1] index = lst[0][0][0][2][1] concrete = lst[0][0][1] result = "%s %d %d" % (varname, int( index[2:]), int(concrete[2:], 16)) print result self._outputLine(result) except: pass
def _is_running(self, host): """Checks if a virtual machine is running. @param host: name of the virtual machine. @return: running status. """ #FIXME use domstate instead try: proc = subprocess.Popen([self.options.xen.path, 'list', '-l', host], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = proc.communicate() if proc.returncode != 0: log.debug("Xen returns error checking status for machine %s: %s" % (host, err)) return False data = OneOrMore(nestedExpr()).parseString(output) for row in data.asList()[0]: if row[0] == 'status' and row[1] == '2': return True return False except OSError as e: log.warning("Xen failed to check status for machine %s: %s" % (label, e)) return False