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

« back to all changes in this revision

Viewing changes to services/diffservice

  • Committer: William Grant
  • Date: 2010-02-25 03:18:21 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225031821-mi9a2tm5679fht4d
Shuffle things around so that req.user and req.store only construct when actually retrieved, and ensure they're not retrieved for media files. Saves 50ms of DB connection time per request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import os
28
28
import sys
 
29
import locale
29
30
 
30
31
import cjson
31
32
import pysvn
32
33
 
33
34
import ivle.svn
34
35
 
 
36
# Set locale to UTF-8
 
37
locale.setlocale(locale.LC_CTYPE, "en_US.UTF-8")
35
38
 
36
39
# Default revisions
37
40
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
48
51
    svnclient = pysvn.Client()
49
52
    svnclient.exception_style = 1
50
53
    diff = svnclient.diff
51
 
    diff_text = diff( '/tmp/svndiff',
 
54
 
 
55
    # pysvn's diff tempfile behaviour changes with Subversion 1.6.x.
 
56
    # < 1.6 wants a filename, >= 1.6 wants a directory.
 
57
    if pysvn.svn_version > (1, 6):
 
58
        tmp_path = '/tmp'
 
59
    else:
 
60
        tmp_path = '/tmp/svndiff'
 
61
 
 
62
    diff_text = diff(tmp_path,
52
63
        os.path.join('/home', sys.argv[1]),
53
64
        revision1=revs[0],
54
65
        revision2=revs[1]
55
66
    )
56
 
    print cjson.encode({'diff': diff_text})
 
67
    print cjson.encode({'diff': diff_text.decode('utf-8')})
57
68
except pysvn.ClientError, e:
58
69
    error = e[0]
59
70
 
60
71
    try:
61
72
        code = e[1][0][1]
62
73
        # See subversion/include/svn_error_codes.h.
 
74
        # 150000: ERR_ENTRY_NOT_FOUND
63
75
        # 155007: WC_NOT_DIRECTORY.
64
76
        # 160013: FS_NOT_FOUND
65
77
        # 200005: UNVERSIONED_RESOURCE
66
 
        if code in (155007, 160013, 200005):
 
78
        if code in (150000, 155007, 160013, 200005):
67
79
            error = 'notfound'
68
80
        else:
69
81
            error = '%s (code %d)' % (error, code)