async def main(): parser = make_parser("Inject configuration into a pristine database.") parser.add_argument("--config", type=str, metavar="FILE", help="The configuration to load.") args = parser.parse_args() if not args.config: raise Exception("A configuration file is required!") enable_logging(args.log_target, args.log_level) async with Connection.from_args(args) as tree: assert await tree.list_directory("/") == [], "tree must be empty when starting" with open(args.config, "r", encoding="utf-8") as fp: assert args.config.endswith("yaml") config = yaml.load(fp) formulas = await slurp_config(tree, "/", config) await create_formulas(tree, formulas)
async def main(): parser = make_parser("Map room colors into light colors.") args = parser.parse_args() enable_logging(args.log_target, args.log_level) async with Connection.from_args(args) as tree: palette = defaultdict(dict) # {color_name: {light_kind: Color}} colors = await tree.get_matching_files("/global/palette/*/*light/color") for path, value in colors.items(): color_name = Path(path).parent.parent.name log.info("Learning about color: {}".format(color_name)) color = await Color.create(Path(path), value, tree) palette[color_name][color.light_kind] = color await tree.watch_matching_files("/room/*/color", make_room_color_handler(palette, tree)) while True: try: await asyncio.sleep(500) except KeyboardInterrupt: return