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

« back to all changes in this revision

Viewing changes to scripts/diffservice

  • Committer: wagrant
  • Date: 2008-07-14 06:25:17 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:867
python-console: Fix traceback trimming when in block mode (worksheets).

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# run from the trampoline by the Diff application.
26
26
 
27
27
from common import cgirequest
28
 
from cgi import parse_qs
29
28
import cgi
30
 
from os import path
 
29
import os.path
31
30
import pysvn
32
31
import re
33
32
 
34
33
def htmlfy_diff(difftext):
35
34
    """Adds HTML markup to a udiff string"""
36
35
    output = cgi.escape(difftext)
37
 
    match_file = re.compile(r'^([\+\-]{3})\s(\S+)\s\((.+)\)$',re.MULTILINE)
38
 
    match_range = re.compile(r'^\@\@ (.*) \@\@$',re.MULTILINE)
39
 
    match_add = re.compile(r'^\+(.*)$',re.MULTILINE)
40
 
    match_sub = re.compile(r'^\-(.*)$',re.MULTILINE)
41
 
    match_special = re.compile(r'^\\(.*)$',re.MULTILINE)
42
 
    output = match_file.sub(
43
 
        r'<span class="diff-files">\1 \2 <em>(\3)</em></span>', output)
44
 
    output = match_range.sub(
45
 
        r'<span class="diff-range">@@ \1 @@</span>', output)
46
 
    output = match_add.sub(
47
 
        r'<span class="diff-add">+\1</span>', output)
48
 
    output = match_sub.sub(
49
 
        r'<span class="diff-sub">-\1</span>', output)
50
 
    output = match_special.sub(
51
 
        r'<span class="diff-special">\\\1</span>', output)
 
36
    subs = {
 
37
     r'^([\+\-]{3})\s(\S+)\s\((.+)\)$':
 
38
         r'<span class="diff-files">\1 \2 <em>(\3)</em></span>',
 
39
     r'^\@\@ (.*) \@\@$':
 
40
         r'<span class="diff-range">@@ \1 @@</span>',
 
41
     r'^\+(.*)$':
 
42
         r'<span class="diff-add">+\1</span>',
 
43
     r'^\-(.*)$':
 
44
         r'<span class="diff-sub">-\1</span>',
 
45
     r'^\\(.*)$':
 
46
         r'<span class="diff-special">\\\1</span>'
 
47
    }
 
48
 
 
49
    for match in subs:
 
50
        output = re.compile(match, re.MULTILINE).sub(subs[match], output)
 
51
 
52
52
    return output
53
53
 
54
54
def get_revision(r_str):
70
70
# IVLE handler environment.
71
71
 
72
72
req = cgirequest.CGIRequest()
 
73
req.install_error_handler()
73
74
req.content_type = "text/html"
74
75
 
75
76
# Beginning of the page
76
77
req.write('<div id="ivle_padding">\n')
77
78
req.write('<h1>Diff</h1>\n')
78
79
 
79
 
# Work out the revisions from query
 
80
# Default revisions
 
81
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
 
82
                                    pysvn.opt_revision_kind.working]]
 
83
# Override revisions from query string
80
84
fields = req.get_fieldstorage()
81
85
field_r = fields.getlist("r")
82
 
# Default revisions
83
 
rev1=pysvn.Revision( pysvn.opt_revision_kind.base )
84
 
rev2=pysvn.Revision( pysvn.opt_revision_kind.working )
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])
92
 
        if r2 != None:
93
 
            rev2 = r2
 
86
for ri in range(len(field_r)):
 
87
    r = get_revision(field_r[ri])
 
88
    if r is not None:
 
89
        revs[ri] = r
94
90
 
95
91
# Attempt to get the diff for these revisons
96
92
try:
97
93
    svnclient = pysvn.Client()
98
94
    diff = svnclient.diff
99
95
    diff_text = diff( '/tmp/svndiff',
100
 
        path.join('/home/', req.path),
101
 
        revision1=rev1,
102
 
        #revision1=pysvn.Revision( pysvn.opt_revision_kind.base ),
103
 
        #url_or_path2=url_or_path,
104
 
        revision2=rev2,
105
 
        #revision2=pysvn.Revision( opt_revision_kind.working ),
106
 
        #recurse=True,
107
 
        #ignore_ancestry=False,
108
 
        #diff_deleted=True,
109
 
        #ignore_content_type=False,
110
 
        #header_encoding="",
111
 
        #diff_options=[]
 
96
        os.path.join('/home', req.path),
 
97
        revision1=revs[0],
 
98
        revision2=revs[1]
112
99
    )
113
100
 
114
101
    # Split up the udiff into individual files
127
114
 
128
115
except pysvn._pysvn_2_5.ClientError, e:
129
116
    req.write('<p><b>Error:</b></p>\n')
130
 
    req.write('<pre class="diff">%s</pre>\n' % cgi.escape(e))
 
117
    req.write('<pre class="diff">%s</pre>\n' % cgi.escape(str(e)))
131
118
 
132
119
req.write('</div>\n')