Package SpecClient :: Module Spec
[hide private]
[frames] | no frames]

Source Code for Module SpecClient.Spec

  1  """Spec module 
  2   
  3  This module define the Spec class for emulating a kind of Spec interpreter in 
  4  a Python object 
  5  """ 
  6   
  7  __author__ = 'Matias Guijarro' 
  8  __version__ = '1.0' 
  9   
 10  import SpecConnectionsManager 
 11  import SpecEventsDispatcher 
 12  import SpecCommand 
 13  import SpecWaitObject 
14 15 -class Spec:
16 """Spec objects provide remote Spec facilities to the connected client.""" 17 18 @property
19 - def specVersion(self):
20 return self.__specVersion
21
22 - def __init__(self, specVersion = None, timeout = None):
23 """Constructor 24 25 Keyword arguments: 26 connection -- either a 'host:port' string pointing to a Spec version (defaults to None) 27 timeout -- optional connection timeout (defaults to None) 28 """ 29 self.connection = None 30 31 if specVersion is not None: 32 self.connectToSpec(specVersion, timeout = timeout) 33 else: 34 self.__specVersion = None
35 36
37 - def connectToSpec(self, specVersion, timeout = None):
38 """Connect to a remote Spec 39 40 Mainly used for two-steps object creation. 41 To be extended by derivated classes. 42 43 Arguments: 44 specVersion -- 'host:port' string representing the Spec version to connect to 45 timeout -- optional connection timeout (defaults to None) 46 """ 47 self.__specVersion = specVersion 48 49 self.connection = SpecConnectionsManager.SpecConnectionsManager().getConnection(specVersion) 50 51 w = SpecWaitObject.SpecWaitObject(self.connection) 52 w.waitConnection(timeout)
53 54
55 - def __getattr__(self, attr):
56 if attr.startswith('__'): 57 raise AttributeError 58 59 return SpecCommand.SpecCommand(attr, self.connection)
60
61 - def _getMotorsMneNames(self):
62 """Return motors mnemonics and names list.""" 63 if self.connection is not None and self.connection.isSpecConnected(): 64 get_motor_mnemonics = SpecCommand.SpecCommand('local md[]; for (i=0; i<MOTORS; i++) { md[i][motor_mne(i)]=motor_name(i) }; return md', self.connection) 65 66 motorMne = get_motor_mnemonics() 67 motorList = [None]*len(motorMne) 68 for motor_index, motor_dict in motorMne.iteritems(): 69 mne, name = motor_dict.items()[0] 70 motorList[int(motor_index)]={"mne": mne, "name": name } 71 return motorList 72 else: 73 return []
74
75 - def getMotorsMne(self):
76 """Return motor mnemonics list.""" 77 motorMneList = [] 78 for motor_dict in self._getMotorsMneNames(): 79 motorMneList.append(motor_dict["mne"]) 80 return motorMneList
81
82 - def getMotorsNames(self):
83 """Return motors names list.""" 84 motorNamesList = [] 85 for motor_dict in self._getMotorsMneNames(): 86 motorNamesList.append(motor_dict["name"]) 87 return motorNamesList
88 89
90 - def getVersion(self):
91 if self.connection is not None: 92 versionChannel = self.connection.getChannel('var/VERSION') 93 94 return versionChannel.read()
95 96
97 - def getName(self):
98 if self.connection is not None: 99 nameChannel = self.connection.getChannel('var/SPEC') 100 101 return nameChannel.read()
102