OLD | NEW |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # | 3 # |
4 # This file is part of logilab-common. | 4 # This file is part of logilab-common. |
5 # | 5 # |
6 # logilab-common is free software: you can redistribute it and/or modify it unde
r | 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
9 # later version. | 9 # later version. |
10 # | 10 # |
11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT | 11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT |
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | 13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. | 14 # details. |
15 # | 15 # |
16 # You should have received a copy of the GNU Lesser General Public License along | 16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. | 17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. |
18 """Prioritized tasks queue""" | 18 """Prioritized tasks queue""" |
19 | 19 |
20 __docformat__ = "restructuredtext en" | 20 __docformat__ = "restructuredtext en" |
21 | 21 |
22 from bisect import insort_left | 22 from bisect import insort_left |
23 from Queue import Queue | 23 |
| 24 from six.moves import queue |
24 | 25 |
25 LOW = 0 | 26 LOW = 0 |
26 MEDIUM = 10 | 27 MEDIUM = 10 |
27 HIGH = 100 | 28 HIGH = 100 |
28 | 29 |
29 PRIORITY = { | 30 PRIORITY = { |
30 'LOW': LOW, | 31 'LOW': LOW, |
31 'MEDIUM': MEDIUM, | 32 'MEDIUM': MEDIUM, |
32 'HIGH': HIGH, | 33 'HIGH': HIGH, |
33 } | 34 } |
34 REVERSE_PRIORITY = dict((values, key) for key, values in PRIORITY.iteritems()) | 35 REVERSE_PRIORITY = dict((values, key) for key, values in PRIORITY.items()) |
35 | 36 |
36 | 37 |
37 | 38 |
38 class PrioritizedTasksQueue(Queue): | 39 class PrioritizedTasksQueue(queue.Queue): |
39 | 40 |
40 def _init(self, maxsize): | 41 def _init(self, maxsize): |
41 """Initialize the queue representation""" | 42 """Initialize the queue representation""" |
42 self.maxsize = maxsize | 43 self.maxsize = maxsize |
43 # ordered list of task, from the lowest to the highest priority | 44 # ordered list of task, from the lowest to the highest priority |
44 self.queue = [] | 45 self.queue = [] |
45 | 46 |
46 def _put(self, item): | 47 def _put(self, item): |
47 """Put a new item in the queue""" | 48 """Put a new item in the queue""" |
48 for i, task in enumerate(self.queue): | 49 for i, task in enumerate(self.queue): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 88 |
88 def __cmp__(self, other): | 89 def __cmp__(self, other): |
89 return cmp(self.priority, other.priority) | 90 return cmp(self.priority, other.priority) |
90 | 91 |
91 def __lt__(self, other): | 92 def __lt__(self, other): |
92 return self.priority < other.priority | 93 return self.priority < other.priority |
93 | 94 |
94 def __eq__(self, other): | 95 def __eq__(self, other): |
95 return self.id == other.id | 96 return self.id == other.id |
96 | 97 |
| 98 __hash__ = object.__hash__ |
| 99 |
97 def merge(self, other): | 100 def merge(self, other): |
98 pass | 101 pass |
OLD | NEW |