Beispiel #1
0
 def serve_edit(self, editurl, preview = None, msg = None):
     if not self.has_write_perm:
         return common.error_403(self)
     if preview is None:
         obj = self.repo.traverse(gitcontent.wiki_to_git_path(editurl))
         if obj is None:
             action = 'Creating'
             contents = ''
         else:
             action = 'Editing'
             contents = babygit.babygit.obj_contents(obj)
     else:
         action = 'Preview of'
         contents = preview
     o = self.response.out
     title = action + ' wiki page: ' + cgi.escape(editurl)
     o.write('<html><title>' + title + '</title>\n')
     o.write('<body><h1>' + title + '</h1>\n')
     if preview is not None:
         o.write(ghmarkup.process_ghmarkup(contents, '/'))
     o.write('<form method="post" action="/wiki/save/' + urllib.quote(editurl) + '">\n')
     o.write('<textarea cols="80" rows="24" name="content">')
     for line in contents.rstrip().split('\n'):
         o.write(cgi.escape(line) + '\n')
     o.write('</textarea>\n')
     o.write('<br >\n')
     o.write('Commit msg: <input type="text" name="msg" size="65"')
     if msg is not None:
         o.write(' value="' + cgi.escape(msg, True) + '"')
     o.write('>\n')
     o.write('<br >\n')
     o.write('<input type="submit" name="preview" value="Preview">\n')
     o.write('<input type="submit" name="save" value="Save">\n')
Beispiel #2
0
 def serve_edit(self, editurl, preview = None, msg = None):
     if not self.has_write_perm:
         return common.error_403(self)
     if preview is None:
         obj = self.repo.traverse(gitcontent.wiki_to_git_path(editurl))
         if obj is None:
             action = 'Creating'
             contents = ''
         else:
             action = 'Editing'
             contents = babygit.babygit.obj_contents(obj)
     else:
         action = 'Preview of'
         contents = preview
     o = self.response.out
     title = action + ' wiki page: ' + cgi.escape(editurl)
     o.write('<html><title>' + title + '</title>\n')
     o.write('<link rel=stylesheet href="/static/wiki.css" type="text/css">')
     o.write('<body><h1>' + title + '</h1>\n')
     if preview is not None:
         o.write(ghmarkup.process_ghmarkup(contents, '/'))
     o.write('<form method="post" action="/wiki/save/' + urllib.quote(editurl) + '">\n')
     o.write('<textarea cols="80" rows="24" name="content">')
     for line in contents.rstrip().split('\n'):
         o.write(cgi.escape(line) + '\n')
     o.write('</textarea>\n')
     o.write('<br >\n')
     o.write('Commit msg: <input type="text" name="msg" size="65"')
     if msg is not None:
         o.write(' value="' + cgi.escape(msg, True) + '"')
     o.write('>\n')
     o.write('<br >\n')
     o.write('<input type="submit" name="preview" value="Preview">\n')
     o.write('<input type="submit" name="save" value="Save">\n')
Beispiel #3
0
 def post(self, arg):
     if not self.has_write_perm:
         return common.error_403(self)
     if arg == '/commit':
         return self.do_commit()
     workspace_str = self.request.body
     username = self.username
     if username is None:
         username = '******'
     workspace = Workspace(key_name = username)
     workspace.workspace = zlib.compress(workspace_str)
     workspace.put()
Beispiel #4
0
    def serve_save(self, path, content, msg):
        if not self.has_write_perm:
            return common.error_403(self)

        babygit.stage.checkout(self.repo)
        content = content.replace('\r', '')
        if isinstance(content, unicode): content = content.encode('utf-8')
        git_path = gitcontent.wiki_to_git_path(path)
        tree = babygit.stage.save(self.repo, git_path, content)
        babygit.stage.add(self.repo, tree)
        author = self.identity
        msg = msg.rstrip() + '\n'
        commitsha = babygit.stage.commit(self.repo, author, msg)
        o = self.response.out
        url = '/wiki/' + path
        o.write('Succesfully saved <a href="' + url + '">' + cgi.escape(path) + '</a>')
Beispiel #5
0
    def serve_save(self, path, content, msg):
        if not self.has_write_perm:
            return common.error_403(self)

        babygit.stage.checkout(self.repo)
        content = content.replace('\r', '')
        if isinstance(content, unicode): content = content.encode('utf-8')
        git_path = gitcontent.wiki_to_git_path(path)
        tree = babygit.stage.save(self.repo, git_path, content)
        babygit.stage.add(self.repo, tree)
        author = self.identity
        msg = msg.rstrip() + '\n'
        commitsha = babygit.stage.commit(self.repo, author, msg)
        o = self.response.out
        url = '/wiki/' + path
        o.write('Succesfully saved <a href="' + url + '">' + cgi.escape(path) + '</a>')
Beispiel #6
0
    def post(self):
        if not self.has_write_perm:
            return common.error_403(self)

        name = self.request.get('name')
        content = self.request.get('content')
        number = self.request.get('number')
        url = self.request.get('url')
        logging.debug(`url`)

        # TODO: validate the name a bit more (no / or space)

        # Edit the content into the theorem text. This is probably best done
        # client-side, but for now we'll stick with the way it worked before.

        logging.debug(`(name, content, number)`)
        urlctx = read.UrlCtx(url)
        text = urlctx.resolve(url)
        if text is None:
            lines = []
        else:
            lines = text.readlines()
        digest = textutils.split_gh_file(lines)
        digestd = dict(digest)
        # Insert before number, or at end of file if not found
        if len(digest) == 0:
            insertpt = len(lines)
        elif digestd.has_key(number):
            insertpt = digestd[number][0]
        else:
            insertpt = skip_blank_lines(digest[-1][1][1], lines)
        if digestd.has_key(name):
            start, end = digestd[name]
            end = skip_blank_lines(end, lines)
            lines[start:end] = []
            if insertpt >= end:
                insertpt -= end - start
        contentlines = content.split('\n')
        while len(contentlines) > 0 and contentlines[-1].rstrip() == '':
            contentlines.pop()
        if len(contentlines) > 0:
            if insertpt > 0 and lines[insertpt - 1].rstrip() != '':
                contentlines.insert(0, '\n')
            contentlines.append('')
        lines[insertpt:insertpt] = contentlines
        lines = [line.rstrip() for line in lines]
        newcontent = '\n'.join(lines)
        if isinstance(newcontent, unicode): newcontent = newcontent.encode('utf-8')

        o = self.response.out

        # Verify
        pipe = StringIO.StringIO(newcontent)
        urlctx = read.UrlCtx(url, pipe)
        error_handler = ErrorHandler()
        ctx = verify.VerifyCtx(urlctx, verify.run, error_handler.error_handler)
        tmpout = StringIO.StringIO()
        ctx.run(urlctx, '-', ctx, tmpout)
        logging.debug(`tmpout.getvalue()`)
        if error_handler.fatal_error:
            # TODO: plumb actual error message
            o.write(json.encode(['error', error_handler.first_error[1]]))
            return

        # Now save the new text
        git_path = str(url)
        if git_path.startswith('/'): git_path = git_path[1:]
        babygit.stage.checkout(self.repo)
        tree = babygit.stage.save(self.repo, git_path, newcontent)
        babygit.stage.add(self.repo, tree)
        author = self.identity
        msg = 'Commit from web thm editor: save ' + name + '\n'
        commitsha = babygit.stage.commit(self.repo, author, msg)
        o.write(json.encode(['ok', 'successfully saved ' + name]))
Beispiel #7
0
    def post(self):
        if not self.has_write_perm:
            return common.error_403(self)

        name = self.request.get('name')
        content = self.request.get('content')
        number = self.request.get('number')
        url = self.request.get('url')
        logging.debug( ` url `)

        # TODO: validate the name a bit more (no / or space)

        # Edit the content into the theorem text. This is probably best done
        # client-side, but for now we'll stick with the way it worked before.

        logging.debug( ` (name, content, number) `)
        urlctx = read.UrlCtx(url)
        text = urlctx.resolve(url)
        if text is None:
            lines = []
        else:
            lines = text.readlines()
        digest = textutils.split_gh_file(lines)
        digestd = dict(digest)
        # Insert before number, or at end of file if not found
        if len(digest) == 0:
            insertpt = len(lines)
        elif digestd.has_key(number):
            insertpt = digestd[number][0]
        else:
            insertpt = skip_blank_lines(digest[-1][1][1], lines)
        if digestd.has_key(name):
            start, end = digestd[name]
            end = skip_blank_lines(end, lines)
            lines[start:end] = []
            if insertpt >= end:
                insertpt -= end - start
        contentlines = content.split('\n')
        while len(contentlines) > 0 and contentlines[-1].rstrip() == '':
            contentlines.pop()
        if len(contentlines) > 0:
            if insertpt > 0 and lines[insertpt - 1].rstrip() != '':
                contentlines.insert(0, '\n')
            contentlines.append('')
        lines[insertpt:insertpt] = contentlines
        lines = [line.rstrip() for line in lines]
        newcontent = '\n'.join(lines)
        if isinstance(newcontent, unicode):
            newcontent = newcontent.encode('utf-8')

        o = self.response.out

        # Verify
        pipe = StringIO.StringIO(newcontent)
        urlctx = read.UrlCtx(url, pipe)
        error_handler = ErrorHandler()
        ctx = verify.VerifyCtx(urlctx, verify.run, error_handler.error_handler)
        tmpout = StringIO.StringIO()
        ctx.run(urlctx, '-', ctx, tmpout)
        logging.debug( ` tmpout.getvalue() `)
        if error_handler.fatal_error:
            # TODO: plumb actual error message
            o.write(json.encode(['error', error_handler.first_error[1]]))
            return

        # Now save the new text
        git_path = str(url)
        if git_path.startswith('/'): git_path = git_path[1:]
        babygit.stage.checkout(self.repo)
        tree = babygit.stage.save(self.repo, git_path, newcontent)
        babygit.stage.add(self.repo, tree)
        author = self.identity
        msg = 'Commit from web thm editor: save ' + name + '\n'
        commitsha = babygit.stage.commit(self.repo, author, msg)
        o.write(json.encode(['ok', 'successfully saved ' + name]))