示例#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}
示例#2
0
    def set(cls, key, params=None):
        userdata = UserData(cls._get_gamesession(params))

        value = params['value']

        userdata.set(key, value)
        return {'ok': True}
示例#3
0
    def set(cls, key, params=None):
        userdata = UserData(cls._get_gamesession(params))

        value = params['value']

        userdata.set(key, value)
        return {'ok': True}
示例#4
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
        }
示例#5
0
    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}
示例#6
0
    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}
示例#7
0
    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}
示例#8
0
    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}
示例#9
0
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)
示例#10
0
    def remove_all(cls, params=None):
        userdata = UserData(cls._get_gamesession(params))

        userdata.remove_all()
        return {'ok': True}
示例#11
0
    def exists(cls, key, params=None):
        _set_json_headers(response.headers)
        userdata = UserData(cls._get_gamesession(params))

        return {'ok': True, 'exists': userdata.exists(key)}
示例#12
0
    def read_keys(cls, params=None):
        _set_json_headers(response.headers)
        userdata = UserData(cls._get_gamesession(params))

        return {'ok': True, 'keys': userdata.get_keys()}
示例#13
0
    def remove_all(cls, params=None):
        userdata = UserData(cls._get_gamesession(params))

        userdata.remove_all()
        return {'ok': True}
示例#14
0
    def exists(cls, key, params=None):
        _set_json_headers(response.headers)
        userdata = UserData(cls._get_gamesession(params))

        return {'ok': True, 'exists': userdata.exists(key)}
示例#15
0
    def read_keys(cls, params=None):
        _set_json_headers(response.headers)
        userdata = UserData(cls._get_gamesession(params))

        return {'ok': True, 'keys': userdata.get_keys()}