Exemple #1
0
    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 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 _get_row(cls, username, score):
     user = get_user(username)
     return {'user': {
                 'username': username,
                 'displayName': username,
                 'avatar': user.avatar},
             'score': score.score,
             'time': score.score_time}
 def from_dict(cls, gamesession):
     game = get_game_by_slug(gamesession['game'])
     # remove any sessions pointing at old games / users
     if game:
         return GameSession(game, get_user(gamesession['user']),
                            gamesession.get('gameSessionId', None),
                            gamesession.get('created', None))
     else:
         raise InvalidGameSession('No gamesession with that id')
 def from_dict(cls, gamesession):
     game = get_game_by_slug(gamesession['game'])
     # remove any sessions pointing at old games / users
     if game:
         return GameSession(game,
                            get_user(gamesession['user']),
                            gamesession.get('gameSessionId', None),
                            gamesession.get('created', None))
     else:
         raise InvalidGameSession('No gamesession with that id')
 def remove_all(cls, game):
     try:
         path = join_path(config['gameprofile_db'], game.slug)
     except KeyError:
         LOG.error('gameprofile_db path config variable not set')
         return
     for f in listdir(path):
         split_ext = f.rsplit('.', 1)
         if split_ext[1] == 'txt':
             GameProfile(get_user(split_ext[0]), game).remove()
     try:
         rmdir(path)
     except OSError:
         pass    # Skip if directory in use or not empty
 def remove_all(cls, game):
     try:
         path = join_path(config['gameprofile_db'], game.slug)
     except KeyError:
         LOG.error('gameprofile_db path config variable not set')
         return
     for f in listdir(path):
         split_ext = f.rsplit('.', 1)
         if split_ext[1] == 'txt':
             GameProfile(get_user(split_ext[0]), game).remove()
     try:
         rmdir(path)
     except OSError:
         pass  # Skip if directory in use or not empty
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)