~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to scripts/svnlogservice

  • Committer: wagrant
  • Date: 2008-12-23 01:58:44 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1063
Set PATH_INFO and PATH_TRANSLATED properly for student CGI scripts.

If the requested path doesn't exist, interpretservice now traverses up the
directory tree until it finds a prefix of the path that does exist. If we are
allowed to execute that path, we do so, giving it the trimmed bits in
PATH_INFO. If execution is not permissible, we 404 anyway.

Fixes [ 2094777 ] Serve: Allow path after CGI script

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import os
27
27
import time
 
28
import cgi
28
29
import pysvn
29
30
 
30
 
from common import cgirequest
 
31
import common.cgirequest
 
32
import common.util
 
33
import common.date
 
34
import common.svn
31
35
 
32
 
req = cgirequest.CGIRequest()
 
36
req = common.cgirequest.CGIRequest()
33
37
req.install_error_handler()
34
38
req.content_type = "text/html"
35
39
 
36
40
req.write('<h1>Subversion Log</h1>\n')
37
41
 
38
 
 
39
 
def pretty_time(epochtime):
40
 
    return time.asctime(time.localtime(epochtime))
41
 
 
42
 
def pretty_path(path):
43
 
    return '%s %s' % (path['action'], path['path'])
44
 
 
45
 
def pretty_paths(paths):
 
42
r_str = req.get_fieldstorage().getfirst("r")
 
43
sr = common.svn.revision_from_string(r_str)
 
44
 
 
45
def pretty_path(cpath, revno=None):
 
46
    path = cpath['path']
 
47
    # XXX: We can't assume that the repository root is always equivalent to
 
48
    #      the current user's home directory, although it does work for our
 
49
    #      current setup.
 
50
    url = common.util.make_path(os.path.join('files',
 
51
                                    common.util.split_path(req.path)[0],
 
52
                                    path[1:]))
 
53
    if revno:
 
54
        url += '?r=%d' % revno
 
55
    return '%s <a href="%s">%s</a>' % (cpath['action'], cgi.escape(url, True),
 
56
                                       cgi.escape(path))
 
57
 
 
58
def pretty_paths(paths, revno=None):
46
59
    output = '<ul>'
47
60
    for path in paths:
48
 
        output += '<li>' + pretty_path(path) + '</li>'
 
61
        output += '<li>' + pretty_path(path, revno) + '</li>'
49
62
    output += '</ul>'
50
63
    return output
51
64
 
52
65
def pretty_log(log):
53
 
    return '''
 
66
    revno = log.revision.number
 
67
    author = cgi.escape(log.author)
 
68
    message = cgi.escape(log.message)
 
69
    result = '''
54
70
<div class="svnlogentry">
55
71
        <div class="svnloginfo">
56
 
                Revision <strong>%d</strong> by <strong>%s</strong> on <strong>%s</strong>
 
72
                Revision <a href="%s?r=%d" style="font-weight: bold">%d</a>
 
73
                by <strong>%s</strong> on <strong>%s</strong>
 
74
''' % (cgi.escape(common.util.make_path(os.path.join('files', req.path))),
 
75
       revno, revno, author, common.date.make_date_nice(log.date))
 
76
 
 
77
    # Now we get ugly. We need to sometimes present [select] and [diff] links.
 
78
    if sr and sr.kind == pysvn.opt_revision_kind.number and sr.number == revno:
 
79
        result += '[selected]'
 
80
    else:
 
81
        result += '<a href="%s?r=%d">[select]</a>' % (
 
82
              cgi.escape(common.util.make_path(os.path.join('svnlog', req.path))),
 
83
              revno)
 
84
    if sr and sr.kind == pysvn.opt_revision_kind.number:
 
85
        result += ' <a href="%s?r=%d&r=%d">[diff]</a>' % (
 
86
              cgi.escape(common.util.make_path(os.path.join('diff', req.path))),
 
87
              sr.number, revno)
 
88
 
 
89
    result += '''
57
90
        </div>
58
91
        <pre>%s</pre>
59
92
        <hr size="1"/>
61
94
        <div class="svnlogpathlist">
62
95
        %s
63
96
        </div>
64
 
</div>''' % (log.revision.number, log.author, pretty_time(log.date),
65
 
             log.message, pretty_paths(log.changed_paths))
 
97
</div>''' % (message, pretty_paths(log.changed_paths, log.revision.number))
 
98
    return result
66
99
 
67
100
try:
68
101
    client = pysvn.Client()