def catchup(self, progress=None):
while True:
more = self._f.readline()
- if not more: return
+ if not more: break
self._progress[0] += len(more)
- if progress is not None:
- progress(*self._progress)
+ if progress: progress.progress(*self._progress)
self._lbuf += more
if self._lbuf.endswith('\n'):
self.chatline(self._lbuf.rstrip())
self._lbuf = ''
+ if progress: progress.caughtup()
+
+class ProgressPrintPercentage:
+ def __init__(self, f): self._f = f
+ def progress(self,done,total):
+ self._f.write("scan chat logs %3d%%\r" % ((done*100) / total))
+ self._f.flush()
+ def caughtup(self):
+ self._f.write(' \r')
+ self._f.flush()
def do_track_chat_log(args, bu):
if len(args) != 1: bu('ship-aid takes only chat log filename')
track = ChatLogTracker(pirate, logfn)
myself_pi = PirateInfo(pirate,3600)
track = ChatLogTracker(myself_pi, logfn)
-
- def pprogress(done,total):
- sys.stdout.write("scan chat logs %3d%%\r" %
- ((done*100) / total))
- sys.stdout.flush()
-
- track.catchup(pprogress)
- sys.stdout.write(' \r')
-
+ track.catchup(ProgressPrintPercentage(sys.stdout))
while True:
track.catchup()
if track.need_redisplay: