+ self._progress[0] += len(more)
+ 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()
+
+ def changed(self):
+ rv = self._need_redisplay
+ self._need_redisplay = False
+ return rv
+ def myname(self):
+ # returns our pirate name
+ return self._myself.name
+ def vessel(self):
+ # returns the vessel we're aboard or None
+ return self._vessel
+ def aboard(self):
+ # returns a list of PirateAboard sorted by name
+ return [ self._v[pn]
+ for pn in sorted(self._v.keys())
+ if not pn.startswith('#') ]
+
+#---------- implementations of actual operation modes ----------
+
+def do_pirate(pirates, bu):
+ print '{'
+ for pirate in pirates:
+ info = PirateInfo(pirate)
+ print '%s: %s,' % (`pirate`, info)
+ print '}'
+
+def prep_crew_of(args, bu, max_age=300):
+ if len(args) != 1: bu('crew-of takes one pirate name')
+ pi = PirateInfo(args[0], max_age)
+ if pi.crew is None: return None
+ return CrewInfo(pi.crew[0], max_age)
+
+def do_crew_of(args, bu):
+ ci = prep_crew_of(args, bu)
+ print ci
+
+def do_standings_crew_of(args, bu):
+ ci = prep_crew_of(args, bu, 60)
+ tab = StandingsTable()
+ tab.headings()
+ for (rank, members) in ci.crew:
+ if not members: continue
+ tab.literalline('%s:' % rank)
+ for p in members:
+ pi = PirateInfo(p, random.randint(900,1800))
+ tab.pirate(pi)
+ print tab.results()
+
+class ProgressPrintPercentage:
+ def __init__(self, f=sys.stdout): 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()
+
+#----- modes which use the chat log parser are quite complex -----
+
+def prep_chat_log(args, bu,
+ progress=ProgressPrintPercentage(),
+ max_myself_age=3600):
+ if len(args) != 1: bu('this action takes only chat log filename')