Author: tmckay Date: 2011-08-02 20:22:05 +0000 (Tue, 02 Aug 2011) New Revision: 4903
Modified: trunk/sage/python/sage/wallaby/wallabyoperations.py Log: Add edit_tags(self, node, tags)
Modified: trunk/sage/python/sage/wallaby/wallabyoperations.py =================================================================== --- trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-08-02 18:54:59 UTC (rev 4902) +++ trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-08-02 20:22:05 UTC (rev 4903) @@ -11,7 +11,7 @@ try: import wallaby from wallaby_collections import StorePatches - from tagging import StorePatches, NodePatches + from tagging import StorePatches, NodePatches, setup except: imports_ok = False
@@ -78,6 +78,10 @@ # Cache a list of nodes that are members of a tag self._nodes_by_tag = dict()
+ # Store the name of the partition group so we can filter it out + # of tags/groups that we return + self._partition_group = None + # Lock is used for synchronization with the caching thread and # for thread safety of any and all data that could be accessed # by multiple threads. @@ -127,6 +131,8 @@ while not self._stop: self._store = self._get_store() if self._store is not None: + setup(self._store) + self._partition_group = self._store.getPartitionGroup().name log.debug("WallabyOperations: found wallaby store object") break
@@ -374,9 +380,7 @@ n = node.name self._lock.acquire() if n in self._cache[WBTypes.NODES].data: - for g in self._cache[WBTypes.NODES].data[n].memberships: - if g in self._cache[WBTypes.TAGS].data: - names.append(g) + names = self._cache[WBTypes.NODES].data[n].getTags() self._lock.release() return names
@@ -390,7 +394,7 @@ self._store.addExplicitGroup(name) self.refresh((WBTypes.GROUPS,WBTypes.TAGS)) except Exception, e: - log.debug("Wallaby: create_tag, exception suppressed, %s" % str(e)) + log.debug("WallabyOperations: create_tag, exception suppressed, %s" % str(e)) return False return True
@@ -407,10 +411,38 @@ self._store.removeGroup(name) self.refresh() except Exception, e: - log.debug("Wallaby: remove_tag, exception suppressed, %s" % str(e)) + log.debug("WallabyOperations: remove_tag, exception suppressed, %s" % str(e)) return False return True
+ def edit_tags(self, node, tags): + ''' + Replace existing tags on a node with the specified tags. + + node -- a wallaby.Node object or the name of a wallaby.Node object + + tags -- the new set of tags for the node, list or tuple. + ''' + if type(node) in (str, unicode): + n = node + else: + n = node.name + self._lock.acquire() + if n in self._cache[WBTypes.NODES].data: + n = self._cache[WBTypes.NODES].data[n] + self._lock.release() + try: + # cast to list in case tags is a tuple, list required + start = time.time() + n.modifyTags("REPLACE", list(tags), create_missing_tags=True) + n.update() + except Exception, e: + log.debug("WallabyOperations: edit_tags, exception suppressed, %s" % str(e)) + return False + delta = time.time() - start + log.debug("WallabyOperations: edit_tags %s" % delta) + return True + def set_interval(self, which, refresh): ''' Set an individual refresh interval for a data item. @@ -468,7 +500,9 @@ tags = [] nodes_by_tag = dict() for g in groups: - if not g.name.startswith("+++") and g.getConfig() == {}: + if not g.name.startswith("+++") and \ + g.name != self._partition_group and \ + g.getConfig() == {}: tags.append(g) nodes = g.membership() nodes_by_tag[g.name] = nodes
cumin-developers@lists.fedorahosted.org