+ displayer = globals()['Display_'+opts.display]()
+
+ (myself, track) = prep_chat_log(args, bu, progress=displayer)
+
+ displayer.realstart()
+
+ if os.isatty(0): kr_create = KeystrokeReader
+ else: kr_create = DummyKeystrokeReader
+
+ try:
+ kreader = kr_create(0, 10)
+ ship_aid_core(myself, track, displayer, kreader)
+ finally:
+ kreader.stop()
+ print '\n'
+
+class KeyBasedSorter:
+ def compar_key_pa(self, pa):
+ pi = pa.pirate_info()
+ if pi is None: return None
+ return self.compar_key(pi)
+ def lsort_pa(self, l):
+ l.sort(key = self.compar_key_pa)
+
+class NameSorter(KeyBasedSorter):
+ def compar_key(self, pi): return pi.name
+ def desc(self): return 'name'
+
+class SkillSorter(NameSorter):
+ def __init__(self, relevant):
+ self._want = frozenset(relevant.split('/'))
+ self._avoid = set()
+ for p in core_duty_puzzles:
+ if isinstance(p,basestring): self._avoid.add(p)
+ else: self._avoid |= set(p)
+ self._avoid -= self._want
+ self._desc = '%s' % relevant
+
+ def desc(self): return self._desc
+
+ def compar_key(self, pi):
+ best_want = max([
+ pi.standings.get(puz,-1)
+ for puz in self._want
+ ])
+ best_avoid = [
+ -pi.standings.get(puz,standing_limit)
+ for puz in self._avoid
+ ]
+ best_avoid.sort()
+ def negate(x): return -x
+ debug('compar_key %s bw=%s ba=%s' % (pi.name, `best_want`,
+ `best_avoid`))
+ return (-best_want, map(negate, best_avoid), pi.name)
+
+def ship_aid_core(myself, track, displayer, kreader):
+
+ def find_vessel():
+ vn = track.vesselname()
+ if vn: return (vn, " on board the %s" % vn)
+ vn = track.lastvesselname()
+ if vn: return (vn, " ashore from the %s" % vn)
+ return (None, " not on a vessel")
+
+ def timeevent(t,e):
+ if t is None: return ' ' * 22
+ return " %-4s %-16s" % (format_time_interval(now - t),e)
+
+ displayer.show(track.myname() + find_vessel()[1] + '...')