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

« back to all changes in this revision

Viewing changes to scripts/diffservice

  • Committer: mattgiuca
  • Date: 2008-06-16 06:22:45 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:773
cgirequest.py: Fixed req.path attribute, so it now DOES NOT include the
    query string part of the URI.
    (This is now consistent with the non-jail req.path. Access to the query
    string is done through req.get_fieldstorage).
    NOTE: This may break code which tries to access the query string directly.
    However all code should be using get_fieldstorage.
scripts/diffservice: Refactor so it's properly using the CGIRequest object
    rather than directly writing to CGI output and parsing query string.
    (Otherwise this code would have been broken by the above change).
    Now uses the request object and fieldstorage for input and output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from os import path
31
31
import pysvn
32
32
import re
33
 
import urlparse
34
33
 
35
34
def htmlfy_diff(difftext):
36
35
    """Adds HTML markup to a udiff string"""
71
70
# IVLE handler environment.
72
71
 
73
72
req = cgirequest.CGIRequest()
74
 
 
75
 
# CGI Headers
76
 
print("Content-Type: text/html\n")
77
 
print("\n")
 
73
req.content_type = "text/html"
78
74
 
79
75
# Beginning of the page
80
 
print('<div id="ivle_padding">')
81
 
print('<h1>Diff</h1>')
 
76
req.write('<div id="ivle_padding">\n')
 
77
req.write('<h1>Diff</h1>\n')
82
78
 
83
79
# Work out the revisions from query
84
 
url = urlparse.urlparse(req.path)
85
 
querystr = url[4]
86
 
urlpath = url[2]
87
 
query = parse_qs(querystr)
 
80
fields = req.get_fieldstorage()
 
81
field_r = fields.getlist("r")
88
82
# Default revisions
89
83
rev1=pysvn.Revision( pysvn.opt_revision_kind.base )
90
84
rev2=pysvn.Revision( pysvn.opt_revision_kind.working )
91
 
if 'r' in query:
92
 
    if len(query['r']) == 2:
93
 
        r2 = get_revision(query['r'][1])
 
85
# Override revisions from query string
 
86
if len(field_r) >= 1:
 
87
    r1 = get_revision(field_r[0])
 
88
    if r1 != None:
 
89
        rev1 = r1
 
90
    if len(field_r) >= 2:
 
91
        r2 = get_revision(field_r[1])
94
92
        if r2 != None:
95
93
            rev2 = r2
96
 
    r1 = get_revision(query['r'][0])
97
 
    if r1 != None:
98
 
        rev1=r1
99
94
 
100
95
# Attempt to get the diff for these revisons
101
96
try:
102
97
    svnclient = pysvn.Client()
103
98
    diff = svnclient.diff
104
99
    diff_text = diff( '/tmp/svndiff',
105
 
        path.join('/home/', urlpath),
 
100
        path.join('/home/', req.path),
106
101
        revision1=rev1,
107
102
        #revision1=pysvn.Revision( pysvn.opt_revision_kind.base ),
108
103
        #url_or_path2=url_or_path,
123
118
    split_diff = diff_matcher.findall(diff_text)
124
119
 
125
120
    # Prints output
126
 
    print("<dl>")
 
121
    req.write("<dl>\n")
127
122
    for filediff in split_diff:
128
123
        filename = filediff[0]
129
124
        diffbody = htmlfy_diff(filediff[1])
130
 
        print("<dt><strong>File:</strong> " + filename + "</dt>")
131
 
        print("<dd><code><pre>" + diffbody + "</pre></code></dd>")
132
 
    print("</dl>")
 
125
        req.write("<dt><strong>File:</strong> " + filename + "</dt>\n")
 
126
        req.write("<dd><code><pre>" + diffbody + "</pre></code></dd>\n")
 
127
    req.write("</dl>\n")
133
128
 
134
129
except pysvn._pysvn_2_5.ClientError, e:
135
 
    print("<dl><dt><strong>Error:</strong></dt><dd>")
136
 
    print(e)
137
 
    print("</dd></dl>")
 
130
    req.write("<dl><dt><strong>Error:</strong></dt><dd>\n")
 
131
    req.write(e + "\n")
 
132
    req.write("</dd></dl>\n")
138
133
 
139
 
print('</div>')
 
134
req.write('</div>\n')