def test_save_objects(self): objs = [self.obj1, self.obj2] storage.save_objects(self.path, self.extension, objs) for obj, data in zip(objs, [self.d1, self.d2]): # TODO Ideally the below would work without calling convert. path = "%s/%s%s" % (self.path, convert.uuid_to_base32(obj.uuid), self.extension) self.assertTrue(os.path.exists(path)) loaded_data = storage.load(path) self.assertDictEqual(data, loaded_data)
def save_objects(path, extension, objs): """ Save game objects to files with the given extension under the given path. For each file, creates a file path from the given directory path, extension and obj.name. The file path and obj are then passed to save_object. """ if not os.path.exists(path): raise IOError("Path not found: '%s'" % path) if not os.path.isdir(path): raise IOError("Path is not directory: '%s'" % path) for obj in objs: obj_path = "%s/%s%s" % (path, convert.uuid_to_base32(obj.uuid), extension) save_object(obj_path, obj)
def save_player(player): storage.save_object(config.path.player_file_pattern % convert.uuid_to_base32(player.uuid), player)
def load_player(player_uuid): return storage.load_file(config.path.player_file_pattern % convert.uuid_to_base32(player_uuid), entity.new_mobile)
def player_exists(player_uuid): return os.path.exists(config.path.player_file_pattern % convert.uuid_to_base32(player_uuid))
def save_user(user): storage.save_object(config.path.user_file_pattern % convert.uuid_to_base32(user.uuid), user)
def load_user(user_uuid): return storage.load_file(config.path.user_file_pattern % convert.uuid_to_base32(user_uuid), User)
def user_exists(user_uuid): return os.path.exists(config.path.user_file_pattern % convert.uuid_to_base32(user_uuid))