Changeset 13793 for fact


Ignore:
Timestamp:
05/19/12 04:34:45 (12 years ago)
Author:
neise
Message:
evolving
Location:
fact/tools/PyDimCtrl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/PyDimCtrl/fpydim.py

    r13789 r13793  
    1919
    2020class FactDimServer( object ):
    21 
    2221    def __init__(self, name):
    2322        """ sets name of instance to name of server, all uppercase
    2423        """
    2524        self.name = name.upper()
     25        self.print_state = False
     26        self.print_msg = False
     27        self.reg_state_cb()
     28        self.reg_msg_cb()
    2629
    2730    def _cmd(self, cmdstr, *args):
     
    8083        return True
    8184
    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()
    83129
    84130# utility functions for dynamic addid of methods to classes
     
    168214# the values are not needed, so it might be any iteratable python listlike type
    169215# to be precise
    170 def ParseServersServiceList( servers )
     216def ParseServersServiceList( servers ):
    171217   
    172218    services = {}
     
    225271                services[server][service[0]] = (
    226272                        service[1], service[2], dd[service[0]])
    227     return services
     273    return services, dd
    228274
    229275
    230276servers = ParseDnsServerList()
    231 services = ParseServersServiceList( servers )
     277services, dd = ParseServersServiceList( servers )
    232278
    233279# create one class for each Fact Dim Server
     
    236282    FactDimServerClasses.append(
    237283            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)
    238291
    239292# create an instace of each of the classes
     
    241294# all the ServerClass instances are collected in a list
    242295# so one can get a quick overview --> print dims
    243 all_dims = []
     296dims = []
    244297for i,server_name in enumerate(servers):
     298    if server_name == 'DIS_DNS':
     299        continue
    245300    new_instance = FactDimServerClasses[i](server_name)
    246     all_dims.append( new_instance )
     301    dims.append( new_instance )
     302    globals()[server_name.lower()] = new_instance
    247303del 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         continue
    255     globals()[dim.name.lower()] = dim
    256     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)
    266304
    267305##############################################################################
  • fact/tools/PyDimCtrl/service.py

    r13789 r13793  
    11#!/usr/bin/python -tti
    2 #from fpydim import *
     2from fpydim import *
    33
    44
Note: See TracChangeset for help on using the changeset viewer.