comparison roundup/support.py @ 7114:33eb82ad26ba

issue2551250: Fix sorting of detectors .. even if there are two with the same name and priority (can happen if they are created in two different files).
author Ralf Schlatterbeck <rsc@runtux.com>
date Wed, 21 Dec 2022 20:13:39 +0100
parents 01643d37785f
children 8ef97f7cfb6d
comparison
equal deleted inserted replaced
7113:5c6dd791d638 7114:33eb82ad26ba
39 >>> p = PrioList() 39 >>> p = PrioList()
40 >>> for i in 5,7,1,-1: 40 >>> for i in 5,7,1,-1:
41 ... p.append(i) 41 ... p.append(i)
42 ... 42 ...
43 >>> for k in p: 43 >>> for k in p:
44 ... print k 44 ... print (k)
45 ... 45 ...
46 -1 46 -1
47 1 47 1
48 5 48 5
49 7 49 7
50 50
51 ''' 51 '''
52 def __init__(self): 52 def __init__(self, key=None):
53 self.list = [] 53 self.list = []
54 self.key = key
54 self.sorted = True 55 self.sorted = True
55 56
56 def append(self, item): 57 def append(self, item):
57 self.list.append(item) 58 self.list.append(item)
58 self.sorted = False 59 self.sorted = False
59 60
60 def __iter__(self): 61 def __iter__(self):
61 if not self.sorted: 62 if not self.sorted:
62 self.list.sort() 63 self.list.sort(key=self.key)
63 self.sorted = True 64 self.sorted = True
64 return iter(self.list) 65 return iter(self.list)
65 66
66 67
67 class Progress: 68 class Progress:

Roundup Issue Tracker: http://roundup-tracker.org/