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

« back to all changes in this revision

Viewing changes to scripts/diffservice

  • Committer: mattgiuca
  • Date: 2008-02-29 01:18:22 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:621
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic
    skeleton.
    "home" is the new default app, replacing "files".
    (It has a link to files).

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
 
import common.svn
29
 
import cgi
30
 
import os.path
 
28
from cgi import parse_qs
 
29
from os import path
31
30
import pysvn
32
31
import re
 
32
import urlparse
33
33
 
34
34
def htmlfy_diff(difftext):
35
35
    """Adds HTML markup to a udiff string"""
36
 
    output = cgi.escape(difftext)
37
 
    subs = {
38
 
     r'^([\+\-]{3})\s(\S+)\s\((.+)\)$':
39
 
         r'<span class="diff-files">\1 \2 <em>(\3)</em></span>',
40
 
     r'^\@\@ (.*) \@\@$':
41
 
         r'<span class="diff-range">@@ \1 @@</span>',
42
 
     r'^\+(.*)$':
43
 
         r'<span class="diff-add">+\1</span>',
44
 
     r'^\-(.*)$':
45
 
         r'<span class="diff-sub">-\1</span>',
46
 
     r'^\\(.*)$':
47
 
         r'<span class="diff-special">\\\1</span>'
48
 
    }
49
 
 
50
 
    for match in subs:
51
 
        output = re.compile(match, re.MULTILINE).sub(subs[match], output)
52
 
 
 
36
    output = 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)
53
52
    return output
54
53
 
 
54
def get_revision(r_str):
 
55
    """ Returns a Revison object for pysvn from a r query string """
 
56
    if r_str == "HEAD":
 
57
        return pysvn.Revision( pysvn.opt_revision_kind.head )
 
58
    elif r_str == "WORKING":
 
59
        return pysvn.Revision( pysvn.opt_revision_kind.working )
 
60
    elif r_str == "BASE":
 
61
        return pysvn.Revision( pysvn.opt_revision_kind.base )
 
62
    else:
 
63
        try:
 
64
            r = int(r_str)
 
65
            return pysvn.Revision( pysvn.opt_revision_kind.number, r)
 
66
        except:
 
67
            return None
 
68
        
55
69
# Use a CGIRequest object to make the CGI environment look like the normal
56
70
# IVLE handler environment.
57
71
 
58
72
req = cgirequest.CGIRequest()
59
 
req.install_error_handler()
60
 
req.content_type = "text/html"
 
73
 
 
74
# CGI Headers
 
75
print("Content-Type: text/html\n")
 
76
print("\n")
61
77
 
62
78
# Beginning of the page
63
 
req.write('<div id="ivle_padding">\n')
64
 
req.write('<h1>Diff</h1>\n')
 
79
print('<div id="ivle_padding">')
 
80
print('<h1>Diff</h1>')
65
81
 
 
82
# Work out the revisions from query
 
83
url = urlparse.urlparse(req.path)
 
84
querystr = url[4]
 
85
urlpath = url[2]
 
86
query = parse_qs(querystr)
66
87
# Default revisions
67
 
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
68
 
                                    pysvn.opt_revision_kind.working]]
69
 
# Override revisions from query string
70
 
fields = req.get_fieldstorage()
71
 
field_r = fields.getlist("r")
72
 
for ri in range(len(field_r)):
73
 
    r = common.svn.revision_from_string(field_r[ri])
74
 
    if r is not None:
75
 
        revs[ri] = r
 
88
rev1=pysvn.Revision( pysvn.opt_revision_kind.base )
 
89
rev2=pysvn.Revision( pysvn.opt_revision_kind.working )
 
90
if 'r' in query:
 
91
    if len(query['r']) == 2:
 
92
        r2 = get_revision(query['r'][1])
 
93
        if r2 != None:
 
94
            rev2 = r2
 
95
    r1 = get_revision(query['r'][0])
 
96
    if r1 != None:
 
97
        rev1=r1
76
98
 
77
99
# Attempt to get the diff for these revisons
78
100
try:
79
101
    svnclient = pysvn.Client()
80
102
    diff = svnclient.diff
81
103
    diff_text = diff( '/tmp/svndiff',
82
 
        os.path.join('/home', req.path),
83
 
        revision1=revs[0],
84
 
        revision2=revs[1]
 
104
        path.join('/home/', urlpath),
 
105
        revision1=rev1,
 
106
        #revision1=pysvn.Revision( pysvn.opt_revision_kind.base ),
 
107
        #url_or_path2=url_or_path,
 
108
        revision2=rev2,
 
109
        #revision2=pysvn.Revision( opt_revision_kind.working ),
 
110
        #recurse=True,
 
111
        #ignore_ancestry=False,
 
112
        #diff_deleted=True,
 
113
        #ignore_content_type=False,
 
114
        #header_encoding="",
 
115
        #diff_options=[]
85
116
    )
86
117
 
87
118
    # Split up the udiff into individual files
91
122
    split_diff = diff_matcher.findall(diff_text)
92
123
 
93
124
    # Prints output
 
125
    print("<dl>")
94
126
    for filediff in split_diff:
95
127
        filename = filediff[0]
96
128
        diffbody = htmlfy_diff(filediff[1])
97
 
        req.write('<p><b>File:</b> %s</p>\n'
98
 
            % cgi.escape(filename))
99
 
        req.write('<pre class="diff">%s</pre>\n' % diffbody)
 
129
        print("<dt><strong>File:</strong> " + filename + "</dt>")
 
130
        print("<dd><code><pre>" + diffbody + "</pre></code></dd>")
 
131
    print("</dl>")
100
132
 
101
133
except pysvn._pysvn_2_5.ClientError, e:
102
 
    req.write('<p><b>Error:</b></p>\n')
103
 
    req.write('<pre class="diff">%s</pre>\n' % cgi.escape(str(e)))
 
134
    print("<dl><dt><strong>Error:</strong></dt><dd>")
 
135
    print(e)
 
136
    print("</dd></dl>")
104
137
 
105
 
req.write('</div>\n')
 
138
print('</div>')