def waitConnection(connection, timeout = None): """Wait for a connection to Spec to be established Arguments: connection -- a 'host:port' string timeout -- optional timeout (defaults to None) """ if isinstance(connection, str) or (is_python2() and isinstance(connection, unicode)): from pyspec.client.SpecConnectionsManager import SpecConnectionsManager connection = SpecConnectionsManager().getConnection(str(connection)) w = SpecWaitObject(connection) w.waitConnection(timeout = timeout)
def __init__(self, command = None, connection = None, callbacks = None): self.command = None self.connection = None self.specVersion = None self.isConnected = self.isSpecConnected #alias if isinstance(connection, str) or (is_python2() and isinstance(connection, unicode)): # # connection is given in the 'host:port' form # self.connectToSpec(str(connection)) else: self.connection = connection if command is not None: self.setCommand(command)
def waitReply(connection, command, argsTuple, timeout = None): """Wait for a reply from a remote Spec server Arguments: connection -- a 'host:port' string command -- command to execute argsTuple -- tuple of arguments for the command timeout -- optional timeout (defaults to None) """ if isinstance(connection, str) or (is_python2() and isinstance(connection, unicode)): connection = str(connection) from pyspec.client.SpecConnectionsManager import SpecConnectionsManager connection = SpecConnectionsManager().getConnection(connection) waitConnection(connection, timeout = timeout) w = SpecWaitObject(connection) w.waitReply(command, argsTuple, timeout=timeout) return w.value
def waitChannelUpdate(chanName, connection, waitValue = None, timeout = None): """Wait for a channel to be updated Arguments: chanName -- channel name (e.g 'var/toto') connection -- a 'host:port' string waitValue -- value to wait (defaults to None) timeout -- optional timeout (defaults to None) """ if isinstance(connection, str) or (is_python2() and isinstance(connection, unicode)): connection = str(connection) from pyspec.client.SpecConnectionsManager import SpecConnectionsManager connection = SpecConnectionsManager().getConnection(connection) waitConnection(connection, timeout = timeout) w = SpecWaitObject(connection) w.waitChannelUpdate(chanName, waitValue = waitValue, timeout = timeout) return w.value
def dataType(self, data): """Try to guess data type Works for obvious cases only - it is a hard job guessing ARRAY_* types, we ignore this case (user has to provide a suitable datatype) - we cannot make a difference between ERROR type and STRING type """ #if type(data) == types.StringType: #if type(data) == str: if isinstance(data,str): return STRING elif isinstance(data,dict): return ASSOC #elif isinstance(data,int) or isinstance(data,long) or isinstance(data,float): elif isinstance(data,int) or isinstance(data,float): return STRING elif is_python2() and isinstance(data,long): return STRING elif isinstance(data, SpecArray.SpecArrayData): self.rows, self.cols = data.shape return data.type