def update_season(self): """ Update the world's season. """ for plugin in retrieve_plugins(ISeason).itervalues(): if plugin.day == self.day: self.world.season = plugin
def run_command(self, s): """ Given a command string from the console or chat, execute it. """ commands = retrieve_plugins(ICommand) # Register aliases. for plugin in commands.values(): for alias in plugin.aliases: commands[alias] = plugin t = s.strip().split(" ", 1) command = t[0].lower() parameters = t[1] if len(t) > 1 else "" if command and command in commands: try: for line in commands[command].dispatch(self, parameters): yield line except Exception, e: yield "Error: %s" % e
def dispatch(self, factory, parameters): plugins = retrieve_plugins(ICommand) l = [] # This is fairly brute-force and inelegant. I'm very open to # suggestions on improving it. for plugin in set(plugins.itervalues()): l.append((plugin.name, plugin.usage, plugin.info)) for alias in plugin.aliases: usage = plugin.usage.replace(plugin.name, alias) info = "Alias for %s" % plugin.name l.append((alias, usage, info)) name_pad = max(len(i[0]) for i in l) + 1 usage_pad = max(len(i[1]) for i in l) + 1 yield "%s %s %s" % ("Name:".ljust(name_pad), "Usage:".ljust(usage_pad), "Info:") for name, usage, info in sorted(l): yield "%s %s %s" % (name.ljust(name_pad), usage.ljust(usage_pad), info)
def pipeline(): generators = configuration.get("beta", "generators").split(",") generators = retrieve_named_plugins(ITerrainGenerator, generators) before = time.time() for i in range(10): chunk = Chunk(i, i) for generator in generators: generator.populate(chunk, 0) after = time.time() return after - before plugins = retrieve_plugins(ITerrainGenerator) t = empty_chunk() print "Baseline: %f seconds" % t for name, plugin in plugins.iteritems(): t = sequential_seeded(plugin) print "Sequential %s: %f seconds" % (name, t) t = repeated_seeds(plugin) print "Repeated %s: %f seconds" % (name, t) t = pipeline() print "Total pipeline: %f seconds" % t
def __init__(self): self.commands = retrieve_plugins(ICommand) StandardIO(self)