self.yoweb_url, self.flagid)`
class IslandFlagInfo(IslandExtendedInfo):
+ # Public data attributes (inherited):
+ # ocean
+ # name
+ # islandid
+ # yoweb_url
+ # flagid
+ # Public data attributes (additional):
+ # flag
def __init__(self, ocean, islename):
IslandExtendedInfo.__init__(self, ocean, islename)
self.flag = None
def __str__(self):
return IslandExtendedInfo.__str__(self) + '; ' + str(self.flag)
+class NullProgressReporter():
+ def start(self): pass
+ def doing(self, msg): pass
+ def stop(self): pass
+
+class TypewriterProgressReporter():
+ def start(self):
+ self._l = 0
+ def doing(self,m):
+ self._doing(m + '...')
+ def _doing(self,m):
+ self._write('\r')
+ self._write(m)
+ less = self._l - len(m)
+ if less > 0:
+ self._write(' ' * less)
+ self._write('\b' * less)
+ self._l = len(m)
+ sys.stdout.flush()
+ def stop(self):
+ self._doing('')
+ self._l = 0
+ def _write(self,t):
+ sys.stdout.write(t)
+
class OceanInfo():
# Public data attributes:
# oi.islands[islename] = IslandInfo(...)
# oi.arches[archname][islename] = IslandInfo(...)
- def __init__(self, isleclass=IslandBasicInfo):
+ def __init__(self, isleclass=IslandBasicInfo, progressreporter=None):
+ if progressreporter is None:
+ if opts.debug: progressreporter = NullProgressReporter()
+ else: progressreporter = TypewriterProgressReporter()
+
self.isleclass = isleclass
self.ocean = fetcher.ocean.lower().capitalize()
+ progressreporter.start()
+ progressreporter.doing('fetching ocean info')
+
cmdl = ['./yppedia-ocean-scraper']
if opts.localhtml is not None:
cmdl += ['--local-html-dir',opts.localhtml]
arch_re = regexp.compile('^ (\S.*)')
island_re = regexp.compile('^ (\S.*)')
+ oscraper.wait()
+ assert(oscraper.returncode == 0)
+
self.islands = { }
self.arches = { }
archname = None
+ isles = [ ]
+ progressreporter.doing('parsing ocean info')
+
for l in oscraper.stdout:
debug('OceanInfo collect l '+`l`)
l = l.rstrip('\n')
if m:
assert(archname is not None)
islename = m.group(1)
- isle = self.isleclass(self.ocean, islename)
- isle.arch = archname
- self.islands[islename] = isle
- self.arches[archname][islename] = isle
+ isles.append((archname, islename))
continue
m = arch_re.match(l)
if m:
self.arches[archname] = { }
continue
assert(False)
- oscraper.wait()
- assert(oscraper.returncode == 0)
+
+ for i in xrange(0, len(isles)-1):
+ (archname, islename) = isles[i]
+ progressreporter.doing(
+ 'fetching isle info %2d/%d (%s: %s)'
+ % (i, len(isles), archname, islename))
+ isle = self.isleclass(self.ocean, islename)
+ isle.arch = archname
+ self.islands[islename] = isle
+ self.arches[archname][islename] = isle
+
+ progressreporter.stop()
def __str__(self):
return `(self.islands, self.arches)`
isle = oi.islands[islename]
print isle
+def do_embargoes(args, bu):
+ if (len(args)): bu('ocean takes no further arguments')
+ fetcher.default_ocean()
+ oi = OceanInfo(IslandFlagInfo)
+ wr = sys.stdout.write
+ print ('EMBARGOES: Island | Owning flag'+
+ ' | Embargoed flags')
+
+ def getflname(isle):
+ if isle.islandid is None: return 'uncolonisable'
+ if isle.flag is None: return 'uncolonised'
+ return isle.flag.name
+
+ for archname in sorted(oi.arches.keys()):
+ print 'ARCHIPELAGO: ',archname
+ for islename in sorted(oi.arches[archname].keys()):
+ isle = oi.islands[islename]
+ wr(' %-20s | ' % isle.name)
+ flname = getflname(isle)
+ wr('%-30s | ' % flname)
+ flag = isle.flag
+ if flag is None: print ''; continue
+ delim = ''
+ for rel in flag.relations:
+ (oname, oid, dummy, thisdeclaring,
+ odeclaringmin,odeclaringmax) = rel
+ if thisdeclaring >= 0: continue
+ wr(delim)
+ wr(oname)
+ delim = '; '
+ print ''
+
#----- modes which use the chat log parser are quite complex -----
class ProgressPrintPercentage: