82
80
####### INTERFACE FOR HANDLING REQUESTS #######################################
83
81
def add_node(self, node, parent_id=None, priority="low"):
84
self._external_request(self._add_node, priority, node, parent_id)
82
self._queue.push(self._add_node, node, parent_id, priority=priority)
86
84
def remove_node(self, node_id, recursive=False):
87
self._external_request(self._remove_node, True, node_id, recursive)
85
self._queue.push(self._remove_node, node_id, recursive)
89
87
def modify_node(self, node_id, priority="low"):
90
self._external_request(self._modify_node, priority, node_id)
88
self._queue.push(self._modify_node, node_id, priority=priority)
92
90
def new_relationship(self, parent_id, child_id):
93
self._external_request(self._new_relationship, False, parent_id, child_id)
91
self._queue.push(self._new_relationship, parent_id, child_id)
95
93
def break_relationship(self, parent_id, child_id):
96
self._external_request(self._break_relationship, False, parent_id, child_id)
98
def _external_request(self, request_type, priority, *args):
99
""" Put the reqest into queue and in the main thread handle it """
100
if priority == "high":
101
self._queue.priority_push(request_type, *args)
102
elif priority == "normal" or priority == "medium":
103
self._queue.push(request_type, *args)
105
self._queue.low_push(request_type, *args)
107
#I'm really wondering what is this line about
108
#It doesn't seem right nor useful, except for unit tests.
109
if self._origin_thread == threading.current_thread():
110
self._queue.process_queue()
94
self._queue.push(self._break_relationship, parent_id, child_id)
112
96
def refresh_all(self):
113
97
""" Refresh all nodes """