def test_update(): """test MutableMapping derived method""" items = [("a", "b"), ("c", "d"), ("e", "f")] d = OrderedDict(items) props = Properties(d) props.update({"g": "h", "c": "i"}) assert props == Properties( OrderedDict([("a", "b"), ("c", "i"), ("e", "f"), ("g", "h")]))
def test_update(): """test MutableMapping derived method""" items = [ ("a", "b"), ("c", "d"), ("e", "f") ] d = OrderedDict(items) props = Properties(d) props.update({ "g": "h", "c": "i" }) assert props == Properties(OrderedDict([ ("a", "b"), ("c", "i"), ("e", "f"), ("g", "h") ]))
def load_world_and_config(): # Get current properties props = Properties() with open(properties_path, "rb") as f: props.load(f, "utf-8") # Select world world_list = [x.name for x in Path(worlds_path).iterdir() if x.is_dir()] level_name = inquirer.prompt([ inquirer.List("level-name", message="Select a world", choices=world_list, default=props["level-name"].data), ])["level-name"] # Load world's configuration world_props_path = Path(worlds_path, level_name + ".properties") world_props = Properties() if world_props_path.is_file(): with open(world_props_path, "rb") as f: world_props.load(f, "utf-8") else: print("No configuration found for this world\n") world_props["level-name"] = level_name props.update(world_props) print("Writing following config to server.properties:") pprint.pprint(world_props.properties) print() with open(properties_path, "wb") as f: props.store(f, encoding="utf-8") # Prompt for restart/start action = inquirer.prompt([ inquirer.Confirm( "action", message=f"{'Restart' if server_is_running() else 'Start'} server?", default=True), ])["action"] if action: restart_server() if server_is_running() else start_server()