def get_value(self, domain, selector): """ Returns descriptor value, None if descriptor was not found. """ selector = self._version_lookup(domain, selector) if not selector: return None fullpath = self.pathFromSelector(domain, selector) + ".value" if not os.path.isfile(fullpath): return None try: value = Descriptor.unserialize_value(store_serializer, open(fullpath, "rb").read()) except: log.error("Could not unserialize value from file %s", fullpath) raise return value
def find_by_value(self, domain, selector_prefix, value_regex): result = [] # File paths to explore pathprefix = self.basepath + '/' + domain + selector_prefix paths = [path for path in self.existing_paths if path.startswith(pathprefix)] for path in paths: # open and run re.match() on every file matching *.value for name in os.listdir(path): if os.path.isfile(path + name) and name.endswith('.value'): contents = Descriptor.unserialize_value( store_serializer, open(path + name, 'rb').read()) if re.match(value_regex, contents): selector = path[len(self.basepath)+len(domain)+1:] +\ name.split('.')[0] desc = self.get_descriptor(domain, selector) result.append(desc) return result
def get_value(self, agent_id, desc_domain, selector): result = str(self.iface.get_value(str(agent_id), desc_domain, selector)) if result == "": return None return Descriptor.unserialize_value(serializer, result)