- Timestamp:
- 05/19/12 04:34:45 (12 years ago)
- Location:
- fact/tools/PyDimCtrl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/PyDimCtrl/fpydim.py
r13789 r13793 19 19 20 20 class FactDimServer( object ): 21 22 21 def __init__(self, name): 23 22 """ sets name of instance to name of server, all uppercase 24 23 """ 25 24 self.name = name.upper() 25 self.print_state = False 26 self.print_msg = False 27 self.reg_state_cb() 28 self.reg_msg_cb() 26 29 27 30 def _cmd(self, cmdstr, *args): … … 80 83 return True 81 84 82 85 def state_callback(self, state): 86 self.sts = state 87 try: 88 self.stn = int(state[state.find('[')+1 : state.find(']')]) 89 except ValueError: 90 self.stn = None 91 if self.print_state: 92 print state 93 94 def msg_callback(self, msg): 95 if self.print_msg: 96 print msg 97 98 def reg_state_cb(self): 99 if not hasattr(self, 'state'): 100 raise TypeError(self.name+' has no CMD called STATE') 101 service_name = self.name.upper()+'/STATE' 102 self.state_sid = pydim.dic_info_service(service_name, "C", self.state_callback) 103 if not self.state_sid: 104 del self.state_sid 105 raise IOError('could not register STATE client') 106 107 def reg_msg_cb(self): 108 if not hasattr(self, 'state'): 109 raise TypeError(self.name+' has no CMD called STATE') 110 service_name = self.name.upper()+'/MESSAGE' 111 self.msg_sid = pydim.dic_info_service(service_name, "C", self.msg_callback) 112 if not self.msg_sid: 113 del self.msg_sid 114 raise IOError('could not register MESSAGE client') 115 116 def unreg_state_cb(self): 117 if hasattr(self, 'state_sid'): 118 pydim.dic_release_service(self.state_sid) 119 del self.state_sid 120 121 def unreg_msg_cb(self): 122 if hasattr(self, 'msg_sid'): 123 pydim.dic_release_service(self.msg_sid) 124 del self.msg_sid 125 126 def __del__(self): 127 self.unreg_state_cb() 128 self.unreg_msg_cb() 83 129 84 130 # utility functions for dynamic addid of methods to classes … … 168 214 # the values are not needed, so it might be any iteratable python listlike type 169 215 # to be precise 170 def ParseServersServiceList( servers ) 216 def ParseServersServiceList( servers ): 171 217 172 218 services = {} … … 225 271 services[server][service[0]] = ( 226 272 service[1], service[2], dd[service[0]]) 227 return services 273 return services, dd 228 274 229 275 230 276 servers = ParseDnsServerList() 231 services = ParseServersServiceList( servers )277 services, dd = ParseServersServiceList( servers ) 232 278 233 279 # create one class for each Fact Dim Server … … 236 282 FactDimServerClasses.append( 237 283 types.ClassType( server_name, (FactDimServer,), {}) ) 284 for cmd in services[server_name]: 285 if 'CMD' in services[server_name][cmd][1]: 286 cmdname = cmd.split('/')[1] 287 add_command(FactDimServerClasses[-1], cmd) 288 elif not services[server_name][cmd][1]: 289 cmdname = cmd.split('/')[1] 290 add_getter(FactDimServerClasses[-1], cmd) 238 291 239 292 # create an instace of each of the classes … … 241 294 # all the ServerClass instances are collected in a list 242 295 # so one can get a quick overview --> print dims 243 all_dims = []296 dims = [] 244 297 for i,server_name in enumerate(servers): 298 if server_name == 'DIS_DNS': 299 continue 245 300 new_instance = FactDimServerClasses[i](server_name) 246 all_dims.append( new_instance ) 301 dims.append( new_instance ) 302 globals()[server_name.lower()] = new_instance 247 303 del new_instance 248 249 dims = []250 #print "connecting to Dim Servers... "251 for dim in all_dims:252 # print dim.name.lower()253 if dim.name == 'DIS_DNS':254 continue255 globals()[dim.name.lower()] = dim256 dims.append(dim)257 258 for i,dim in enumerate(all_dims):259 for cmd in services[dim.name]:260 if 'CMD' in services[dim.name][cmd][1]:261 cmdname = cmd.split('/')[1]262 add_command(FactDimServerClasses[i], cmd)263 elif not services[dim.name][cmd][1]:264 cmdname = cmd.split('/')[1]265 add_getter(FactDimServerClasses[i], cmd)266 304 267 305 ############################################################################## -
fact/tools/PyDimCtrl/service.py
r13789 r13793 1 1 #!/usr/bin/python -tti 2 #from fpydim import *2 from fpydim import * 3 3 4 4
Note:
See TracChangeset
for help on using the changeset viewer.