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

« back to all changes in this revision

Viewing changes to services/diffservice

Merge from object-publishing.

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
30
29
 
31
 
try:
32
 
    import json
33
 
except ImportError:
34
 
    import simplejson as json
 
30
import cjson
35
31
import pysvn
36
32
 
37
 
import ivle.conf
38
33
import ivle.svn
39
34
 
40
 
# Set locale to UTF-8
41
 
locale.setlocale(locale.LC_CTYPE, "en_US.UTF-8")
42
35
 
43
36
# Default revisions
44
37
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
52
45
 
53
46
# Attempt to get the diff for these revisons
54
47
try:
55
 
    svnclient = ivle.svn.create_auth_svn_client(username=ivle.conf.login,
56
 
                                                password=ivle.conf.svn_pass)
 
48
    svnclient = pysvn.Client()
57
49
    svnclient.exception_style = 1
58
50
    diff = svnclient.diff
59
 
 
60
 
    # pysvn's diff tempfile behaviour changes with Subversion 1.6.x.
61
 
    # < 1.6 wants a filename, >= 1.6 wants a directory.
62
 
    if pysvn.svn_version > (1, 6):
63
 
        tmp_path = '/tmp'
64
 
    else:
65
 
        tmp_path = '/tmp/svndiff'
66
 
 
67
 
    diff_text = diff(tmp_path,
 
51
    diff_text = diff( '/tmp/svndiff',
68
52
        os.path.join('/home', sys.argv[1]),
69
53
        revision1=revs[0],
70
54
        revision2=revs[1]
71
55
    )
72
 
    print json.dumps({'diff': diff_text.decode('utf-8')})
 
56
    print cjson.encode({'diff': diff_text})
73
57
except pysvn.ClientError, e:
74
58
    error = e[0]
75
59
 
76
60
    try:
77
61
        code = e[1][0][1]
78
62
        # See subversion/include/svn_error_codes.h.
79
 
        # 150000: ERR_ENTRY_NOT_FOUND
80
63
        # 155007: WC_NOT_DIRECTORY.
81
64
        # 160013: FS_NOT_FOUND
82
65
        # 200005: UNVERSIONED_RESOURCE
83
 
        if code in (150000, 155007, 160013, 200005):
 
66
        if code in (155007, 160013, 200005):
84
67
            error = 'notfound'
85
68
        else:
86
69
            error = '%s (code %d)' % (error, code) 
87
70
    except IndexError:
88
71
        pass
89
72
 
90
 
    print json.dumps({'error': error})
 
73
    print cjson.encode({'error': error})