def pfstring_to_pfdict(self, pfstring): """Return a dictionary from the 'string' field of a status packet which contains a parameter file.""" # TODO Should this be a method on DLSource since that's the only place # it's used? pfstring = pfstring.strip('\0') pfptr = _stock._pfnew() try: r = _stock._pfcompile(pfstring, pfptr) if r != 0: raise Exception("pfcompile failed") pfdict = _stock._pfget(pfptr, None) return pfdict finally: _stock._pffree(pfptr)
def __init__(self, options): r, confpf = _stock._pfread(options.parameter_file) if r < 0: raise Exception("Failed to open configuration parameter file %s." % repr(options.parameter_file)) [self.set_val(k, confpf, options) for k in DEFAULTS.iterkeys()] self.instances={} instdict = _stock._pfget(confpf,'instances') for instname, instcfg in instdict.iteritems(): sources = {} for srcname, srccfg in instcfg.iteritems(): srccfg = {} if srccfg == '' else srccfg source = SourceConfig(self, srccfg) sources[srcname] = source self.instances[instname] = sources self.templates = TemplateLookup(directories=['templates'])
def unstuff(self, srcname, time, raw_packet): pkt = None try: type, pkt = _pkt._unstuffPkt(srcname, time, raw_packet) check_error(type, UnstuffError) self.string = _pkt._Pkt_string_get(pkt) self.pkttype.update(dict(zip(self._pkttypefields, _pkt._Pkt_pkttype_get(pkt)))) if _pkt._Pkt_type_get(pkt) == _pkt.Pkt_pf: pfptr = _pkt._Pkt_pfptr_get(pkt) if pfptr != None: try: self.pfdict = _stock._pfget(pfptr, None) finally: _stock._pffree(pfptr) self.time = time finally: if pkt is not None: _pkt._freePkt(pkt)
def set_val(self, k, pf, options=None): """Sets the attribute 'k'. Look first in options, then in pf. Always converts type to int if at all possible, which is kludgy, but acceptable at the moment. """ v = None if options is not None: try: v = getattr(options, k) except AttributeError: pass if v is None: v = _stock._pfget(pf,k) if v is None or v == '': v = DEFAULTS[k] try: v = int(v) except (ValueError, TypeError): pass setattr(self, k, v)