def userkeys(cls, slug, username): game = get_game_by_slug(slug) if not game: response.status_int = 404 return {'ok': False, 'msg': 'Game does not exist: %s' % slug} # !!! Move this into the user model user_path = join(cls.datapath, slug, username) if not exists(user_path): response.status_int = 404 return {'ok': False, 'msg': 'User does not exist: %s' % slug} userdata = UserData(user=get_user(username), game=game) if userdata is None: response.status_int = 400 return {'ok': False, 'msg': 'No session with that ID exists'} data_list = userdata.get_keys() userdata = {} for i in data_list: file_path = join(cls.datapath, slug, username, i) + '.txt' f = _File(i, file_path, username, file_path) userdata[f.name] = { 'assetName': f.name, 'isJson': f.is_json(), 'size': f.get_size() } return {'ok': True, 'data': userdata}
def set(cls, key, params=None): userdata = UserData(cls._get_gamesession(params)) value = params['value'] userdata.set(key, value) return {'ok': True}
def userkeys(cls, slug, username): game = get_game_by_slug(slug) if not game: response.status_int = 404 return {'ok': False, 'msg': 'Game does not exist: %s' % slug} # !!! Move this into the user model user_path = join(cls.datapath, slug, username) if not exists(user_path): response.status_int = 404 return {'ok': False, 'msg': 'User does not exist: %s' % slug} userdata = UserData(user=get_user(username), game=game) if userdata is None: response.status_int = 400 return {'ok': False, 'msg': 'No session with that ID exists'} data_list = userdata.get_keys() userdata = { } for i in data_list: file_path = join(cls.datapath, slug, username, i) + '.txt' f = _File(i, file_path, username, file_path) userdata[f.name] = { 'assetName': f.name, 'isJson': f.is_json(), 'size': f.get_size() } return { 'ok': True, 'data': userdata }
def remove(cls, key, params=None): userdata = UserData(cls._get_gamesession(params)) try: userdata.remove(key) except UserDataKeyError: response.status_int = 404 return {'ok': False, 'msg': 'Key does not exist'} else: return {'ok': True}
def read(cls, key, params=None): _set_json_headers(response.headers) userdata = UserData(cls._get_gamesession(params)) try: value = userdata.get(key) except UserDataKeyError: response.status_int = 404 return {'ok': False, 'msg': 'Key does not exist'} else: return {'ok': True, 'value': value}
def get_asset(asset, slug, userdata=None): game = get_game_by_slug(slug) if userdata: # asset = user / key (username, key) = asset.split('/', 1) user = get_user(username) userdata = UserData(user=user, game=game) json_asset = json.loads(userdata.get(key)) filename = key + '.txt' else: filename = get_absolute_path(os.path.join(game.path, asset)) with open(filename, 'r') as handle: json_asset = json.load(handle) return (json_asset, filename)
def remove_all(cls, params=None): userdata = UserData(cls._get_gamesession(params)) userdata.remove_all() return {'ok': True}
def exists(cls, key, params=None): _set_json_headers(response.headers) userdata = UserData(cls._get_gamesession(params)) return {'ok': True, 'exists': userdata.exists(key)}
def read_keys(cls, params=None): _set_json_headers(response.headers) userdata = UserData(cls._get_gamesession(params)) return {'ok': True, 'keys': userdata.get_keys()}