def inspect_by_resource(context:Resource): factories = { **dict(gather_installed("turberfield.ipc.poa")), **dict(gather_installed("turberfield.ipc.role")), **dict(gather_installed("turberfield.ipc.routing")), } with open(os.path.join(*context[:-1]) + context.suffix, 'r') as record: try: typ = factories[context.policy] obj = typ.from_json(record.read()) except (AttributeError, KeyError) as e: return None else: return obj
def inspect_by_resource(context: Resource): factories = { **dict(gather_installed("turberfield.ipc.poa")), **dict(gather_installed("turberfield.ipc.role")), **dict(gather_installed("turberfield.ipc.routing")), } with open(os.path.join(*context[:-1]) + context.suffix, "r") as record: try: typ = factories[context.policy] obj = typ.from_json(record.read()) except (AttributeError, KeyError) as e: return None else: return obj
def test_state_tables(self): states = dict(gather_installed("turberfield.utils.states")) con = Connection(**Connection.options()) with con as db: rv = Creation(*schema.values()).run(db) tables = self.get_tables(db) self.assertIn("state", [t.get("name") for t in tables])
def create_from_resource(path:Resource, poa:list, role:list, routing:list, prefix="flow_", suffix=""): if all(path[:5]) and not any(path[5:]): parent = os.path.join(*path[:5]) drctry = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=parent) flow = path._replace(flow=os.path.basename(drctry)) # MRO important here. for registry, choices in [ ("turberfield.ipc.routing", routing), ("turberfield.ipc.poa", poa), ("turberfield.ipc.role", role) ]: policies = dict(gather_installed(registry)) for option in choices: try: typ = policies[option] if issubclass(typ, Pooled): others = [Flow.inspect(i) for i in Flow.find(path, application="*", policy=option)] obj = typ.allocate(others=others) else: obj = typ() flow = flow._replace(policy=option, suffix=".json") with open(os.path.join(*flow[:-1]) + flow.suffix, 'w') as record: record.write(obj.__json__()) record.flush() except KeyError: warnings.warn("No policy found for '{}'.".format(option)) yield None except Exception as e: warnings.warn("Create error: {}".format(e)) yield None else: yield flow
def create_from_resource(path: Resource, poa: list, role: list, routing: list, prefix="flow_", suffix=""): if all(path[:5]) and not any(path[5:]): parent = os.path.join(*path[:5]) drctry = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=parent) flow = path._replace(flow=os.path.basename(drctry)) # MRO important here. for registry, choices in [ ("turberfield.ipc.routing", routing), ("turberfield.ipc.poa", poa), ("turberfield.ipc.role", role), ]: policies = dict(gather_installed(registry)) for option in choices: try: typ = policies[option] if issubclass(typ, Pooled): others = [Flow.inspect(i) for i in Flow.find(path, application="*", policy=option)] obj = typ.allocate(others=others) else: obj = typ() flow = flow._replace(policy=option, suffix=".json") with open(os.path.join(*flow[:-1]) + flow.suffix, "w") as record: record.write(obj.__json__()) record.flush() except KeyError: warnings.warn("No policy found for '{}'.".format(option)) yield None except Exception as e: warnings.warn("Create error: {}".format(e)) yield None else: yield flow
async def __call__(self, loop=None): """ In a business location, the game is driven by user interaction. Clock ticks operate the game calendar. Outside of business locations, we wait for a clock tick and offer dialogue. """ player = self.businesses[0].proprietor self.ensemble = [player] + addisonarches.scenario.common.ensemble while not Clock.public.running: await asyncio.sleep(0, loop=loop) while Clock.public.running: if self.here is None: # Not at a business seqList = OrderedDict(gather_installed("turberfield.interfaces.sequence", log=self._log)) choice = next(iter(seqList.keys()), None) self._log.info("Selected sequence '{0}'.".format(choice)) folder = seqList[choice] self.dialogueQueue = asyncio.Queue(maxsize=1, loop=loop) while folder: folder = await run_through( folder, self.ensemble, self.dialogueQueue, loop=loop) else: self._log.info("Dialogue complete.") self.dialogueQueue = None self.shot = None self.location = self.home await Clock.public.active.wait() self.declare( dict( diorama=self.diorama, frame=self.frame, progress=self.progress, inventory=self.inventory, businesses=self.businesses ), loop=loop ) await Clock.public.inactive.wait()
def find_theme(cfg, output, default="january"): name = cfg[cfg.default_section].get("theme", default) try: theme_module = importlib.import_module(name) theme_class = next(i for i in vars(theme_module).values() if inspect.isclass(i) and issubclass(i, Theme) and inspect.getmodule(i) is theme_module) logging.info( "Selected {0.__name__} theme from '{1}' module.".format( theme_class, name)) except (ModuleNotFoundError, StopIteration): themes = dict(gather_installed("turberfield.interfaces.theme")) theme_class = themes.get(name) or themes.get(default) logging.info("Selected '{0.__name__}' theme from [ {1} ]".format( theme_class, ",".join(themes.keys()))) theme_module = inspect.getmodule(theme_class) theme_package = ".".join(theme_module.__name__.split(".")[:-1]) return theme_class and theme_class( cfg, output.resolve(), parent_package=theme_package)