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

« back to all changes in this revision

Viewing changes to services/python-console

  • Committer: Matt Giuca
  • Date: 2010-07-22 02:12:36 UTC
  • mfrom: (1812.1.13 late-submit)
  • Revision ID: matt.giuca@gmail.com-20100722021236-k8kt4cqdtywzpk24
Merge from trunk late-submit.
Students may now submit projects after the deadline, but they are warned that the submission is late.
Lecturers are now given data on which submissions were made late, and how many days.
(LP: #598346)

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import cPickle
9
9
import cStringIO
10
10
import md5
11
 
import os
12
11
import Queue
13
12
import signal
14
13
import socket
171
170
 
172
171
    def run(self):
173
172
        # Set up global space and partial command buffer
174
 
        self.globs = {}
 
173
        self.globs = {'__name__': '__main__'}
175
174
        self.curr_cmd = ''
176
175
 
177
176
        # Set up I/O to use web interface
181
180
 
182
181
        # Handlers for each action
183
182
        actions = {
 
183
            'splash': self.handle_splash,
184
184
            'chat': self.handle_chat,
185
185
            'block': self.handle_block,
186
186
            'globals': self.handle_globals,
198
198
                response = {'error': repr(e)}
199
199
            finally:
200
200
                self.cmdQ.put(response)
201
 
                   
 
201
 
 
202
    def handle_splash(self, params):
 
203
        # Initial console splash screen
 
204
        python_version = '.'.join(str(v) for v in sys.version_info[:3])
 
205
        splash_text = ("""IVLE %s Python Console (Python %s)
 
206
Type "help", "copyright", "credits" or "license" for more information.
 
207
""" % (ivle.__version__, python_version))
 
208
        return {'output': splash_text}
 
209
 
202
210
    def handle_chat(self, params):
203
211
        # Set up the partial cmd buffer
204
212
        if self.curr_cmd == '':
254
262
    def handle_globals(self, params):
255
263
        # Unpickle the new space (if provided)
256
264
        if isinstance(params, dict):
257
 
            self.globs = {}
 
265
            self.globs = {'__name__': '__main__'}
258
266
            for g in params:
259
267
                try:
260
268
                    self.globs[g] = cPickle.loads(params[g])
369
377
    """Handles response from signals"""
370
378
    global terminate
371
379
    if signum == signal.SIGXCPU:
372
 
        terminate = "CPU Time Limit Exceeded"
 
380
        terminate = "CPU time limit exceeded"
373
381
 
374
382
def dispatch_msg(msg):
375
383
    global terminate
376
384
    if msg['cmd'] == 'terminate':
377
 
        terminate = "User requested console be terminated"
 
385
        terminate = "User requested restart"
378
386
    if terminate:
379
387
        raise ivle.chat.Terminate({"terminate":terminate})
380
388
    expiry.ping()
399
407
    for o in object:
400
408
        try:
401
409
            flat[o] = cPickle.dumps(object[o], PICKLEVERSION)
402
 
        except TypeError:
 
410
        except (TypeError, cPickle.PicklingError):
403
411
            try:
404
412
                o_type = type(object[o]).__name__
405
413
                o_name = object[o].__name__
412
420
if __name__ == "__main__":
413
421
    port = int(sys.argv[1])
414
422
    magic = sys.argv[2]
415
 
    
416
 
    # Sanitise the Enviroment
417
 
    os.environ = {}
418
 
    os.environ['PATH'] = '/usr/local/bin:/usr/bin:/bin'
419
 
 
420
 
    if len(sys.argv) >= 4:
421
 
        # working_dir
422
 
        os.chdir(sys.argv[3])
423
 
        os.environ['HOME'] = sys.argv[3]
424
423
 
425
424
    # Make python's search path follow the cwd
426
425
    sys.path[0] = ''