Mercurial > p > roundup > code
comparison roundup/support.py @ 3487:a2ae11191968
added class PrioList (patch from rfe [SF#413165])
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Tue, 24 Jan 2006 08:16:59 +0000 |
| parents | 293a17149765 |
| children | 5cd1c83dea50 |
comparison
equal
deleted
inserted
replaced
| 3486:34ada15b9936 | 3487:a2ae11191968 |
|---|---|
| 22 | 22 |
| 23 def ensureParentsExist(dest): | 23 def ensureParentsExist(dest): |
| 24 if not os.path.exists(os.path.dirname(dest)): | 24 if not os.path.exists(os.path.dirname(dest)): |
| 25 os.makedirs(os.path.dirname(dest)) | 25 os.makedirs(os.path.dirname(dest)) |
| 26 | 26 |
| 27 class PrioList: | |
| 28 '''Manages a sorted list. | |
| 29 | |
| 30 Currently only implements method 'append' and iteration from a | |
| 31 full list interface. | |
| 32 Implementation: We manage a "sorted" status and sort on demand. | |
| 33 Appending to the list will require re-sorting before use. | |
| 34 >>> p = PrioList () | |
| 35 >>> for i in 5,7,1,-1 : | |
| 36 ... p.append (i) | |
| 37 ... | |
| 38 >>> for k in p : | |
| 39 ... print k | |
| 40 ... | |
| 41 -1 | |
| 42 1 | |
| 43 5 | |
| 44 7 | |
| 45 | |
| 46 ''' | |
| 47 def __init__(self): | |
| 48 self.list = [] | |
| 49 self.sorted = True | |
| 50 | |
| 51 def append(self, item): | |
| 52 self.list.append (item) | |
| 53 self.sorted = False | |
| 54 | |
| 55 def __iter__(self): | |
| 56 if not self.sorted : | |
| 57 self.list.sort () | |
| 58 self.sorted = True | |
| 59 return iter (self.list) | |
| 60 | |
| 27 # vim: set et sts=4 sw=4 : | 61 # vim: set et sts=4 sw=4 : |
