コード例 #1
0
def view_history(name, gitref):
    """Serve a page name from git repo (an old version of a page).

    .. note:: this is a bottle view

    * this is a GET only method : you can not change a committed page

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
        :gitref: (str) -- hexsha of the git commit to look into

    Returns:
        bottle response object or 404 error page
    """
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    content = read_committed_file(gitref, name + '.rst')
    if content:
        html_body = publish_parts(content,
                                  writer=AttowikiWriter(),
                                  settings=None,
                                  settings_overrides=None)['html_body']
        history = commit_history(name + '.rst')
        return template('page',
                        type="history",
                        name=name,
                        extended_name=None,
                        is_repo=check_repo(),
                        history=history,
                        gitref=gitref,
                        content=html_body)
    else:
        return abort(404)
コード例 #2
0
ファイル: views.py プロジェクト: joergwork/attowiki
def view_history(name, gitref):
    """serve a page name from git repo (an old version of a page)

    .. note:: this is a bottle view

    * this is a GET only method : you can not change a committed page

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
        :gitref: (str) -- hexsha of the git commit to look into

    Returns:
        bottle response object or 404 error page
    """
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    content = read_committed_file(gitref, name + '.rst')
    if content:
        html_body = publish_parts(content,
                                  writer=HisWriter(),
                                  settings=None,
                                  settings_overrides=None)['html_body']
        history = commit_history(name + '.rst')
        return template('page',
                        type="history",
                        name=name,
                        extended_name=None,
                        is_repo=check_repo(),
                        history=history,
                        gitref=gitref,
                        content=html_body)
    else:
        return abort(404)
コード例 #3
0
def view_history_diff(name, gitref):
    """Serve a page name from git repo (an old version of a page).

       then return the diff between current source and the old commited source

       This function does not use any template it returns only plain text

    .. note:: this is a bottle view

    * this is a GET only method : you can not change a committed page

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
        :gitref: (str) -- hexsha of the git commit to look into

    Returns:
        bottle response object or 404 error page
    """
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    response.set_header('Content-Type', 'text/html; charset=utf-8')
    old_content = read_committed_file(gitref, name + '.rst')
    if old_content:
        old_content = old_content.decode('utf-8')
        files = glob.glob("{0}.rst".format(name))
        if len(files) > 0:
            file_handle = open(files[0], 'r')
            current_content = file_handle.read().decode('utf-8')
            differ = difflib.Differ()
            result = list(
                differ.compare(old_content.splitlines(),
                               current_content.splitlines()))
            return template('diff_view',
                            type="history",
                            name=name,
                            extended_name='__diff__',
                            is_repo=check_repo(),
                            history=commit_history("{0}.rst".format(name)),
                            gitref=gitref,
                            content=result)
        else:
            return abort(404)
    else:
        return abort(404)
コード例 #4
0
ファイル: views.py プロジェクト: ThomasChiroux/attowiki
def view_history_diff(name, gitref):
    """Serve a page name from git repo (an old version of a page).

       then return the diff between current source and the old commited source

       This function does not use any template it returns only plain text

    .. note:: this is a bottle view

    * this is a GET only method : you can not change a committed page

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
        :gitref: (str) -- hexsha of the git commit to look into

    Returns:
        bottle response object or 404 error page
    """
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    response.set_header('Content-Type', 'text/html; charset=utf-8')
    old_content = read_committed_file(gitref, name + '.rst')
    if old_content:
        old_content = old_content.decode('utf-8')
        files = glob.glob("{0}.rst".format(name))
        if len(files) > 0:
            file_handle = open(files[0], 'r')
            current_content = file_handle.read().decode('utf-8')
            differ = difflib.Differ()
            result = list(differ.compare(old_content.splitlines(),
                                         current_content.splitlines()))
            return template('diff_view',
                            type="history",
                            name=name,
                            extended_name='__diff__',
                            is_repo=check_repo(),
                            history=commit_history("{0}.rst".format(name)),
                            gitref=gitref,
                            content=result)
        else:
            return abort(404)
    else:
        return abort(404)
コード例 #5
0
def view_history_source(name, gitref=None):
    """Serve a page name from git repo (an old version of a page).

       then return the reST source code

       This function does not use any template it returns only plain text

    .. note:: this is a bottle view

    * this is a GET only method : you can not change a committed page

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
        :gitref: (str) -- hexsha of the git commit to look into

    Returns:
        bottle response object or 404 error page
    """
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    response.set_header('Content-Type', 'text/html; charset=utf-8')
    if gitref is None:
        files = glob.glob("{0}.rst".format(name))
        if len(files) > 0:
            file_handle = open(files[0], 'r')
            content = file_handle.read()
        else:
            return abort(404)
    else:
        content = read_committed_file(gitref, name + '.rst')
    if content:
        return template('source_view',
                        type="history",
                        name=name,
                        extended_name='__source__',
                        is_repo=check_repo(),
                        history=commit_history("{0}.rst".format(name)),
                        gitref=gitref,
                        content=content.decode('utf-8'))
    else:
        return abort(404)
コード例 #6
0
ファイル: views.py プロジェクト: ThomasChiroux/attowiki
def view_history_source(name, gitref=None):
    """Serve a page name from git repo (an old version of a page).

       then return the reST source code

       This function does not use any template it returns only plain text

    .. note:: this is a bottle view

    * this is a GET only method : you can not change a committed page

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
        :gitref: (str) -- hexsha of the git commit to look into

    Returns:
        bottle response object or 404 error page
    """
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    response.set_header('Content-Type', 'text/html; charset=utf-8')
    if gitref is None:
        files = glob.glob("{0}.rst".format(name))
        if len(files) > 0:
            file_handle = open(files[0], 'r')
            content = file_handle.read()
        else:
            return abort(404)
    else:
        content = read_committed_file(gitref, name + '.rst')
    if content:
        return template('source_view',
                        type="history",
                        name=name,
                        extended_name='__source__',
                        is_repo=check_repo(),
                        history=commit_history("{0}.rst".format(name)),
                        gitref=gitref,
                        content=content.decode('utf-8'))
    else:
        return abort(404)
コード例 #7
0
def view_page(name=None):
    """Serve a page name.

    .. note:: this is a bottle view

    * if the view is called with the POST method, write the new page
      content to the file, commit the modification and then display the
      html rendering of the restructured text file

    * if the view is called with the GET method, directly display the html
      rendering of the restructured text file

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
                        OPTIONAL

    if no filename is given, first try to find a "index.rst" file in the
    directory and serve it. If not found, serve the meta page __index__

    Returns:
        bottle response object
    """
    if request.method == 'POST':
        if name is None:
            # new file
            if len(request.forms.filename) > 0:
                name = request.forms.filename

        if name is not None:
            filename = "{0}.rst".format(name)
            file_handle = open(filename, 'w')
            file_handle.write(request.forms.content.encode('utf-8'))
            file_handle.close()
            add_file_to_repo(filename)
            commit(filename)

    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    if name is None:
        # we try to find an index file
        index_files = glob.glob("./[Ii][Nn][Dd][Ee][Xx].rst")
        if len(index_files) == 0:
            # not found
            # redirect to __index__
            return view_meta_index()
        else:
            name = index_files[0][2:-4]
    files = glob.glob("{0}.rst".format(name))
    if len(files) > 0:
        file_handle = open(files[0], 'r')
        html_body = publish_parts(file_handle.read(),
                                  writer=AttowikiWriter(),
                                  settings=None,
                                  settings_overrides=None)['html_body']
        history = commit_history("{0}.rst".format(name))
        return template('page',
                        type="view",
                        name=name,
                        extended_name=None,
                        is_repo=check_repo(),
                        history=history,
                        gitref=None,
                        content=html_body)
    else:
        return static_file(name, '')
コード例 #8
0
ファイル: views.py プロジェクト: joergwork/attowiki
def view_page(name=None):
    """serve a page name

    .. note:: this is a bottle view

    * if the view is called with the POST method, write the new page
      content to the file, commit the modification and then display the
      html rendering of the restructured text file

    * if the view is called with the GET method, directly display the html
      rendering of the restructured text file

    Keyword Arguments:
        :name: (str) -- name of the rest file (without the .rst extension)
                        OPTIONAL

    if no filename is given, first try to find a "index.rst" file in the
    directory and serve it. If not found, serve the meta page __index__

    Returns:
        bottle response object
    """
    if request.method == 'POST':
        if name is None:
            # new file
            if len(request.forms.filename) > 0:
                name = request.forms.filename

        if name is not None:
            filename = "{0}.rst".format(name)
            file_handle = open(filename, 'w')
            file_handle.write(request.forms.content.encode('utf-8'))
            file_handle.close()
            add_file_to_repo(filename)
            commit(filename)

    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    if name is None:
        # we try to find an index file
        index_files = glob.glob("./[Ii][Nn][Dd][Ee][Xx].rst")
        if len(index_files) == 0:
            # not found
            # redirect to __index__
            return view_meta_index()
        else:
            name = index_files[0][2:-4]

    files = glob.glob("{0}.rst".format(name))
    if len(files) > 0:
        file_handle = open(files[0], 'r')
        html_body = publish_parts(file_handle.read(),
                                  writer=HisWriter(),
                                  settings=None,
                                  settings_overrides=None)['html_body']
        history = commit_history("{0}.rst".format(name))
        return template('page',
                        type="view",
                        name=name,
                        extended_name=None,
                        is_repo=check_repo(),
                        history=history,
                        gitref=None,
                        content=html_body)
    else:
        return static_file(name, '')