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

« back to all changes in this revision

Viewing changes to services/diffservice

  • Committer: David Coles
  • Date: 2010-08-30 03:26:13 UTC
  • Revision ID: coles.david@gmail.com-20100830032613-d14vng0jkelniu3l
python-console: Fix globals broken with new JSON library.

simplejson always returns unicode strings. cJSON would return ordinary strings 
if possible. cPickle.loads() only accepts strings. At present we use pickle 
version 0 so they should all works as ASCII strings. Higher versions of pickle 
are not plain ASCII and are likely to break this and so this should be fixed 
at some point.

Also replaced unconditional exception with one that catches Pickle errors. Not 
sure the best way to report failures of these functions.

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
 
import cjson
 
31
try:
 
32
    import json
 
33
except ImportError:
 
34
    import simplejson as json
31
35
import pysvn
32
36
 
 
37
import ivle.conf
33
38
import ivle.svn
34
39
 
 
40
# Set locale to UTF-8
 
41
locale.setlocale(locale.LC_CTYPE, "en_US.UTF-8")
35
42
 
36
43
# Default revisions
37
44
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
45
52
 
46
53
# Attempt to get the diff for these revisons
47
54
try:
48
 
    svnclient = pysvn.Client()
 
55
    svnclient = ivle.svn.create_auth_svn_client(username=ivle.conf.login,
 
56
                                                password=ivle.conf.svn_pass)
49
57
    svnclient.exception_style = 1
50
58
    diff = svnclient.diff
51
 
    diff_text = diff( '/tmp/svndiff',
 
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,
52
68
        os.path.join('/home', sys.argv[1]),
53
69
        revision1=revs[0],
54
70
        revision2=revs[1]
55
71
    )
56
 
    print cjson.encode({'diff': diff_text})
 
72
    print json.dumps({'diff': diff_text.decode('utf-8')})
57
73
except pysvn.ClientError, e:
58
74
    error = e[0]
59
75
 
71
87
    except IndexError:
72
88
        pass
73
89
 
74
 
    print cjson.encode({'error': error})
 
90
    print json.dumps({'error': error})