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

« back to all changes in this revision

Viewing changes to services/diffservice

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 
20
 
# Author: David Coles, Will Grant
21
 
 
22
 
'''
23
 
A script for generating a Subversion diff. It is intended to be run via
24
 
trampoline by ivle.webapp.filesystem.diff.DiffView.
25
 
'''
26
 
 
27
 
import os
28
 
import sys
29
 
 
30
 
import cjson
 
20
# Script: diffservice
 
21
# Author: David Coles
 
22
# Date:   26/2/2008
 
23
 
 
24
# A CGI script for generating a diff report page in HTML. It is intended to be 
 
25
# run from the trampoline by the Diff application.
 
26
 
 
27
import cgi
 
28
import os.path
31
29
import pysvn
 
30
import re
32
31
 
 
32
from ivle import cgirequest
33
33
import ivle.svn
34
34
 
 
35
def htmlfy_diff(difftext):
 
36
    """Adds HTML markup to a udiff string"""
 
37
    output = cgi.escape(difftext)
 
38
    subs = {
 
39
     r'^([\+\-]{3})\s(\S+)\s\((.+)\)$':
 
40
         r'<span class="diff-files">\1 \2 <em>(\3)</em></span>',
 
41
     r'^\@\@ (.*) \@\@$':
 
42
         r'<span class="diff-range">@@ \1 @@</span>',
 
43
     r'^\+(.*)$':
 
44
         r'<span class="diff-add">+\1</span>',
 
45
     r'^\-(.*)$':
 
46
         r'<span class="diff-sub">-\1</span>',
 
47
     r'^\\(.*)$':
 
48
         r'<span class="diff-special">\\\1</span>'
 
49
    }
 
50
 
 
51
    for match in subs:
 
52
        output = re.compile(match, re.MULTILINE).sub(subs[match], output)
 
53
 
 
54
    return output
 
55
 
 
56
# Use a CGIRequest object to make the CGI environment look like the normal
 
57
# IVLE handler environment.
 
58
 
 
59
req = cgirequest.CGIRequest()
 
60
req.install_error_handler()
 
61
req.content_type = "text/html"
 
62
 
 
63
# Beginning of the page
 
64
req.write('<div id="ivle_padding">\n')
 
65
req.write('<h1>Diff</h1>\n')
35
66
 
36
67
# Default revisions
37
68
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
38
69
                                    pysvn.opt_revision_kind.working]]
39
 
 
40
 
# Override revisions from argv.
41
 
for ri in range(len(sys.argv[2:4])):
42
 
    r = ivle.svn.revision_from_string(sys.argv[2 + ri])
 
70
# Override revisions from query string
 
71
fields = req.get_fieldstorage()
 
72
field_r = fields.getlist("r")
 
73
for ri in range(len(field_r)):
 
74
    r = ivle.svn.revision_from_string(field_r[ri])
43
75
    if r is not None:
44
76
        revs[ri] = r
45
77
 
46
78
# Attempt to get the diff for these revisons
47
79
try:
48
80
    svnclient = pysvn.Client()
49
 
    svnclient.exception_style = 1
50
81
    diff = svnclient.diff
51
82
    diff_text = diff( '/tmp/svndiff',
52
 
        os.path.join('/home', sys.argv[1]),
 
83
        os.path.join('/home', req.path),
53
84
        revision1=revs[0],
54
85
        revision2=revs[1]
55
86
    )
56
 
    print cjson.encode({'diff': diff_text})
57
 
except pysvn.ClientError, e:
58
 
    error = e[0]
59
 
 
60
 
    try:
61
 
        code = e[1][0][1]
62
 
        # See subversion/include/svn_error_codes.h.
63
 
        # 155007: WC_NOT_DIRECTORY.
64
 
        # 160013: FS_NOT_FOUND
65
 
        # 200005: UNVERSIONED_RESOURCE
66
 
        if code in (155007, 160013, 200005):
67
 
            error = 'notfound'
68
 
        else:
69
 
            error = '%s (code %d)' % (error, code) 
70
 
    except IndexError:
71
 
        pass
72
 
 
73
 
    print cjson.encode({'error': error})
 
87
 
 
88
    # Split up the udiff into individual files
 
89
    diff_matcher = re.compile(
 
90
        r'^Index: (.*)\n\=+\n((?:[^I].*\n)*)',re.MULTILINE
 
91
    )
 
92
    split_diff = diff_matcher.findall(diff_text)
 
93
 
 
94
    # Prints output
 
95
    for filediff in split_diff:
 
96
        filename = filediff[0]
 
97
        diffbody = htmlfy_diff(filediff[1])
 
98
        req.write('<p><b>File:</b> %s</p>\n'
 
99
            % cgi.escape(filename))
 
100
        req.write('<pre class="diff">%s</pre>\n' % diffbody)
 
101
 
 
102
except pysvn._pysvn_2_5.ClientError, e:
 
103
    req.write('<p><b>Error:</b></p>\n')
 
104
    req.write('<pre class="diff">%s</pre>\n' % cgi.escape(str(e)))
 
105
 
 
106
req.write('</div>\n')