Exemplo n.º 1
0
    def delete(cls, slug):
        """
        Deletes a game.
        """
        try:
            GameList.get_instance().delete_game(slug)
        except GameNotFoundError as e:
            response.status_int = 404
            return {'ok': False, 'msg': str(e)}

        response.headers['Cache-Control'] = 'no-store, no-cache, max-age=0'
        return {'ok': True}
Exemplo n.º 2
0
    def save(cls, slug):
        """
        Send a signal to save the data passed via the request parameters
        to a game.
        """
        game = get_game_by_slug(slug)
        if not game:
            response.status_int = 404
            return {'ok': False, 'msg': 'Game does not exist: %s' % slug}

        try:
            game.save(dict(request.params))
        except (GamePathNotFoundError, GamePathError) as e:
            response.status_int = 400
            return {'ok': False, 'msg': str(e)}
        else:
            GameList.get_instance().save_game_list()

        return _details(game)
Exemplo n.º 3
0
    def load(cls, slug):
        """
        Send a signal to load a game from the path specified in the request
        parameters.
        """
        game = get_game_by_slug(slug)
        if not game:
            response.status_int = 404
            return {'ok': False, 'msg': 'Game does not exist: %s' % slug}

        path = request.params.get('path', None)
        if not path:
            response.status_int = 400
            return {'ok': False, 'msg': 'Path not specified'}

        try:
            game.load(path)
        except GameError:
            response.status_int = 400
            return {'ok': False, 'msg': 'Unable to load details for game: %s' % slug}
        else:
            GameList.get_instance().save_game_list()

        return _details(game)
Exemplo n.º 4
0
    def create_slug(cls):
        title = request.params.get('title', None)
        if not title:
            response.status_int = 400
            return {'ok': False, 'msg': 'Title not specified'}

        base_slug = slugify(title)
        unique_slug = GameList.get_instance().make_slug_unique(base_slug)
        if base_slug == unique_slug:
            return {
                'ok': True,
                'data': base_slug,
            }
        else:
            return {
                'ok': True,
                'data': unique_slug,
                # TODO fix this! unique_slug can be up to 6 characters longer
                'msg': 'added %s to avoid slug clash.' % unique_slug[-2:]
            }
Exemplo n.º 5
0
    def directory_options(cls):
        directory = request.params.get('dir', None)
        if not directory:
            response.status_int = 400
            return {'ok': False, 'msg': 'Directory not specified'}

        directory = directory.strip()

        # Test for characters not legal in Windows paths
        if not set(directory).isdisjoint(set('*?"<>|\0')):
            response.status_int = 400
            return {'ok': False, 'msg': 'Bad directory'}

        try:
            absDir = get_absolute_path(directory)
        except TypeError:
            response.status_int = 400
            return {'ok': False, 'msg': 'Bad directory'}

        options = {
            'absDir': norm_path(absDir),
            'dir': directory
        }

        if not os.access(absDir, os.F_OK):
            options['create'] = True
        else:
            if not os.access(absDir, os.W_OK):
                options['inaccessible'] = True
            elif os.access(path_join(absDir, 'manifest.yaml'), os.F_OK):
                if GameList.get_instance().path_in_use(absDir):
                    options['inUse'] = True
                else:
                    options['overwrite'] = True
            else:
                options['usable'] = True

        return {'ok': True, 'data': options}
 def __init__(self, app, staticmax_max_age=0):
     self.app = app
     self.staticmax_max_age = staticmax_max_age
     self.cached_apps = {}
     self.game_list = GameList.get_instance()
     self.utf8_mimetypes = set(['text/html', 'application/json'])
Exemplo n.º 7
0
 def __init__(self, app, config):
     self.app = app
     self.user_id_counter = int(time() - 946080000)
     self.cookie_session_name = config.get('metrics.user.key', 'metrics_id')
     self.gamelist = GameList.get_instance()
Exemplo n.º 8
0
 def __init__(self, app, config):
     self.app = app
     self.user_id_counter = int(time() - 946080000)
     self.cookie_session_name = config.get('metrics.user.key', 'metrics_id')
     self.gamelist = GameList.get_instance()
Exemplo n.º 9
0
 def new(cls):
     game = GameList.get_instance().add_game()
     return {'ok': True, 'data': game.slug}
Exemplo n.º 10
0
 def list(cls):
     game_list = { }
     games = GameList.get_instance().list_all()
     for game in games:
         game_list[game.slug] = game.to_dict()
     return {'ok': True, 'data': game_list}