| 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 | 23 from Queue import Queue |
| 24 from six.moves import queue | |
| 25 | 24 |
| 26 LOW = 0 | 25 LOW = 0 |
| 27 MEDIUM = 10 | 26 MEDIUM = 10 |
| 28 HIGH = 100 | 27 HIGH = 100 |
| 29 | 28 |
| 30 PRIORITY = { | 29 PRIORITY = { |
| 31 'LOW': LOW, | 30 'LOW': LOW, |
| 32 'MEDIUM': MEDIUM, | 31 'MEDIUM': MEDIUM, |
| 33 'HIGH': HIGH, | 32 'HIGH': HIGH, |
| 34 } | 33 } |
| 35 REVERSE_PRIORITY = dict((values, key) for key, values in PRIORITY.items()) | 34 REVERSE_PRIORITY = dict((values, key) for key, values in PRIORITY.iteritems()) |
| 36 | 35 |
| 37 | 36 |
| 38 | 37 |
| 39 class PrioritizedTasksQueue(queue.Queue): | 38 class PrioritizedTasksQueue(Queue): |
| 40 | 39 |
| 41 def _init(self, maxsize): | 40 def _init(self, maxsize): |
| 42 """Initialize the queue representation""" | 41 """Initialize the queue representation""" |
| 43 self.maxsize = maxsize | 42 self.maxsize = maxsize |
| 44 # ordered list of task, from the lowest to the highest priority | 43 # ordered list of task, from the lowest to the highest priority |
| 45 self.queue = [] | 44 self.queue = [] |
| 46 | 45 |
| 47 def _put(self, item): | 46 def _put(self, item): |
| 48 """Put a new item in the queue""" | 47 """Put a new item in the queue""" |
| 49 for i, task in enumerate(self.queue): | 48 for i, task in enumerate(self.queue): |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 87 |
| 89 def __cmp__(self, other): | 88 def __cmp__(self, other): |
| 90 return cmp(self.priority, other.priority) | 89 return cmp(self.priority, other.priority) |
| 91 | 90 |
| 92 def __lt__(self, other): | 91 def __lt__(self, other): |
| 93 return self.priority < other.priority | 92 return self.priority < other.priority |
| 94 | 93 |
| 95 def __eq__(self, other): | 94 def __eq__(self, other): |
| 96 return self.id == other.id | 95 return self.id == other.id |
| 97 | 96 |
| 98 __hash__ = object.__hash__ | |
| 99 | |
| 100 def merge(self, other): | 97 def merge(self, other): |
| 101 pass | 98 pass |
| OLD | NEW |