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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: William Grant
  • Date: 2011-08-24 08:24:36 UTC
  • Revision ID: me@williamgrant.id.au-20110824082436-2kthurhl385pegut
natty needs --include=ubuntu-keyring,gnupg in debootstrap. Fix jailbuilder to cope.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import StringIO
26
26
from optparse import OptionParser
27
27
 
28
 
import cjson
 
28
try:
 
29
    import json
 
30
except ImportError:
 
31
    import simplejson as json
29
32
 
30
33
from ivle import zip as zipmod
31
34
import ivle.conf.app.server
 
35
import ivle.mimetypes
32
36
 
33
37
def determine_file_type(filename):
34
38
    filetype = mimetypes.guess_type(filename)[0]
35
39
    if filetype is None:
36
 
         filetype = ivle.conf.mimetypes.default_mimetype
 
40
        filetype = ivle.mimetypes.DEFAULT_MIMETYPE
37
41
    return filetype
38
42
 
39
43
def throw_error(message, extra={}):
40
44
    error = {'error': message}
41
45
    error.update(extra)
42
 
    print cjson.encode(error)
 
46
    print json.dumps(error)
43
47
    sys.exit(0)
44
48
 
45
49
parser = OptionParser()
111
115
    else:
112
116
        if not download and \
113
117
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
114
 
            throw_error('is-executable', {'path': filename})
 
118
            throw_error('is-executable', {'path': filename.decode('utf-8')})
115
119
 
116
120
        if not download and (
117
121
            (ivle.conf.app.server.blacklist_served_filetypes and \
137
141
    zipfile = StringIO.StringIO()
138
142
    zipmod.make_zip(zipbasepath, paths, zipfile)
139
143
 
140
 
    print cjson.encode({'type': zip_mimetype,
141
 
                        'name': zipfilename})
 
144
    print json.dumps({'type': zip_mimetype,
 
145
                      'name': zipfilename.decode('utf-8'),
 
146
                      'size': len(zipfile.getvalue()),
 
147
                      })
142
148
 
143
149
    stream = zipfile
144
150
    stream.seek(0)
145
151
else:
146
152
 
147
 
    print cjson.encode({'type': determine_file_type(filename),
148
 
                        'name': os.path.basename(filename)})
 
153
    print json.dumps({'type': determine_file_type(filename),
 
154
                      'name': os.path.basename(filename).decode('utf-8'),
 
155
                      'size': os.path.getsize(filename),
 
156
                      })
149
157
    stream = open(filename)
150
 
    
 
158
 
151
159
next = stream.read(1024)
152
160
while next:
153
161
    sys.stdout.write(next)