"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "roundup/support.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

support.py  (roundup-1.6.1):support.py  (roundup-2.0.0)
"""Implements various support classes and functions used in a number of """Implements various support classes and functions used in a number of
places in Roundup code. places in Roundup code.
""" """
from __future__ import print_function
__docformat__ = 'restructuredtext' __docformat__ = 'restructuredtext'
import os, time, sys, re import os, time, sys
class TruthDict: class TruthDict:
'''Returns True for valid keys, False for others. '''Returns True for valid keys, False for others.
''' '''
def __init__(self, keys): def __init__(self, keys):
if keys: if keys:
self.keys = {} self.keys = {}
for col in keys: for col in keys:
self.keys[col] = 1 self.keys[col] = 1
else:
self.__getitem__ = lambda name: 1
def __getitem__(self, name): def __getitem__(self, name):
return self.keys.has_key(name) if hasattr(self, 'keys'):
return name in self.keys
else:
return True
def ensureParentsExist(dest): def ensureParentsExist(dest):
if not os.path.exists(os.path.dirname(dest)): if not os.path.exists(os.path.dirname(dest)):
os.makedirs(os.path.dirname(dest)) os.makedirs(os.path.dirname(dest))
class PrioList: class PrioList:
'''Manages a sorted list. '''Manages a sorted list.
Currently only implements method 'append' and iteration from a Currently only implements method 'append' and iteration from a
full list interface. full list interface.
skipping to change at line 48 skipping to change at line 50
>>> for k in p: >>> for k in p:
... print k ... print k
... ...
-1 -1
1 1
5 5
7 7
''' '''
def __init__(self): def __init__(self):
self.list = [] self.list = []
self.sorted = True self.sorted = True
def append(self, item): def append(self, item):
self.list.append(item) self.list.append(item)
self.sorted = False self.sorted = False
def __iter__(self): def __iter__(self):
if not self.sorted: if not self.sorted:
self.list.sort() self.list.sort()
self.sorted = True self.sorted = True
skipping to change at line 72 skipping to change at line 74
'''Progress display for console applications. '''Progress display for console applications.
See __main__ block at end of file for sample usage. See __main__ block at end of file for sample usage.
''' '''
def __init__(self, info, sequence): def __init__(self, info, sequence):
self.info = info self.info = info
self.sequence = iter(sequence) self.sequence = iter(sequence)
self.total = len(sequence) self.total = len(sequence)
self.start = self.now = time.time() self.start = self.now = time.time()
self.num = 0 self.num = 0
self.stepsize = self.total / 100 or 1 self.stepsize = self.total // 100 or 1
self.steptimes = [] self.steptimes = []
self.display() self.display()
def __iter__(self): return self def __iter__(self): return self
def next(self): def __next__(self):
self.num += 1 self.num += 1
if self.num > self.total: if self.num > self.total:
print self.info, 'done', ' '*(75-len(self.info)-6) print(self.info, 'done', ' '*(75-len(self.info)-6))
sys.stdout.flush() sys.stdout.flush()
return self.sequence.next() return next(self.sequence)
if self.num % self.stepsize: if self.num % self.stepsize:
return self.sequence.next() return next(self.sequence)
self.display() self.display()
return self.sequence.next() return next(self.sequence)
# Python 2 compatibility:
next = __next__
def display(self): def display(self):
# figure how long we've spent - guess how long to go # figure how long we've spent - guess how long to go
now = time.time() now = time.time()
steptime = now - self.now steptime = now - self.now
self.steptimes.insert(0, steptime) self.steptimes.insert(0, steptime)
if len(self.steptimes) > 5: if len(self.steptimes) > 5:
self.steptimes.pop() self.steptimes.pop()
steptime = sum(self.steptimes) / len(self.steptimes) steptime = sum(self.steptimes) / len(self.steptimes)
self.now = now self.now = now
eta = steptime * ((self.total - self.num)/self.stepsize) eta = steptime * ((self.total - self.num)/self.stepsize)
# tell it like it is (or might be) # tell it like it is (or might be)
if now - self.start > 3: if now - self.start > 3:
M = eta / 60 M = eta / 60
H = M / 60 H = M / 60
M = M % 60 M = M % 60
S = eta % 60 S = eta % 60
if self.total: if self.total:
s = '%s %2d%% (ETA %02d:%02d:%02d)'%(self.info, s = '%s %2d%% (ETA %02d:%02d:%02d)' % (self.info,
self.num * 100. / self.total, H, M, S) self.num * 100. / self.total, H, M, S)
else: else:
s = '%s 0%% (ETA %02d:%02d:%02d)'%(self.info, H, M, S) s = '%s 0%% (ETA %02d:%02d:%02d)' % (self.info, H, M, S)
elif self.total: elif self.total:
s = '%s %2d%%'%(self.info, self.num * 100. / self.total) s = '%s %2d%%' % (self.info, self.num * 100. / self.total)
else: else:
s = '%s %d done'%(self.info, self.num) s = '%s %d done' % (self.info, self.num)
sys.stdout.write(s + ' '*(75-len(s)) + '\r') sys.stdout.write(s + ' '*(75-len(s)) + '\r')
sys.stdout.flush() sys.stdout.flush()
# vim: set et sts=4 sw=4 : # vim: set et sts=4 sw=4 :
 End of changes. 15 change blocks. 
15 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)