~ubuntu-branches/ubuntu/saucy/liblarch/saucy-proposed

« back to all changes in this revision

Viewing changes to liblarch/tree.py

  • Committer: Package Import Robot
  • Author(s): Luca Falavigna
  • Date: 2013-05-05 14:22:10 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130505142210-scyeprq1t3cnjbsr
Tags: 2.1.0-2
* Upload to unstable.
* debian/control:
  - Use canonical URIs for VCS fields.
* debian/watch:
  - Point to GitHub repository, thanks Bart Martens!

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
# -----------------------------------------------------------------------------
19
19
 
20
 
import threading
21
20
import processqueue
22
21
from liblarch.treenode import _Node
23
22
 
40
39
        _Node._set_tree(self.root,self)
41
40
 
42
41
        self._queue = processqueue.SyncQueue()
43
 
        self._origin_thread = threading.current_thread()
44
42
 
45
43
    def __str__(self):
46
44
        return "<Tree: root = '%s'>" % self.root
81
79
 
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)
85
83
 
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)
88
86
 
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)
91
89
 
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)
94
92
 
95
93
    def break_relationship(self, parent_id, child_id):
96
 
        self._external_request(self._break_relationship, False, parent_id, child_id)
97
 
 
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)
104
 
        else:
105
 
            self._queue.low_push(request_type, *args)
106
 
 
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)
111
95
 
112
96
    def refresh_all(self):
113
97
        """ Refresh all nodes """