def get_attribute_values(node, locations, attribute_name): """ Get unique attribute values from locations. Given a list of locations, and an attribute name, it cooking the locations at the given node, and gets a list of unique values for the attribute_name. Args: node (str): node locations (list): locations to cook attribute_name (str): Attribute name to fetch Returns: list. List of unique attributes """ runtime = FnGeolib.GetRegisteredRuntimeInstance() txn = runtime.createTransaction() client = txn.createClient() op = Nodes3DAPI.GetOp(txn, NodegraphAPI.GetNode(node.getName())) txn.setClientOp(client, op) runtime.commit(txn) attribute_values = [] for location in locations: cooked_location = client.cookLocation(location) attrs = cooked_location.getAttrs() attribute = attrs.getChildByName(attribute_name) attribute_value = attribute.getChildByName("value").getValue() if attribute_value not in attribute_values: attribute_values.append(attribute_value) return attribute_values
def __viewNodeChangedEvent(self, node): viewedTime = NodegraphAPI.GetCurrentTime() viewedNode = NodegraphAPI.GetViewNode() print "viewNode ---> ", viewedNode if not viewedNode: self.__runtime = None self.__client = None return self.__runtime = FnGeolib.GetRegisteredRuntimeInstance() txn = self.__runtime.createTransaction() op = Nodes3DAPI.GetOp(txn, viewedNode, viewedTime) if not op: self.__runtime = None return self.__client = txn.createClient() txn.setClientOp(self.__client, op) self.__runtime.commit(txn) self.__setLocations()
def getClient(node=None): runtime = FnGeolib.GetRegisteredRuntimeInstance() transaction = runtime.createTransaction() client = transaction.createClient() if node: terminalOp = Nodes3DAPI.GetOp(transaction, node) transaction.setClientOp(client, terminalOp) runtime.commit(transaction) return client
def getAll(): node = NodegraphAPI.GetViewNode() runtime = FnGeolib.GetRegisteredRuntimeInstance() txn = runtime.createTransaction() client = txn.createClient() op = Nodes3DAPI.GetOp(txn, node) txn.setClientOp(client, op) runtime.commit(txn) locationPathsAndData = [] traversal = FnGeolib.Util.Traversal(client, "/root") while traversal.valid(): locationPathsAndData.append( (traversal.getLocationPath(), traversal.getLocationData())) traversal.next() for i in locationPathsAndData: print i