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

« back to all changes in this revision

Viewing changes to services/python-console

  • Committer: William Grant
  • Date: 2009-05-31 01:34:26 UTC
  • mto: (1281.1.8 aufsless)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: grantw@unimelb.edu.au-20090531013426-ys8aifjtbn8cis7i
ivle.makeuser.make_jail creates an appropriate /tmp.

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
11
12
import Queue
12
13
import signal
13
14
import socket
180
181
 
181
182
        # Handlers for each action
182
183
        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
 
 
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
 
 
 
201
                   
210
202
    def handle_chat(self, params):
211
203
        # Set up the partial cmd buffer
212
204
        if self.curr_cmd == '':
377
369
    """Handles response from signals"""
378
370
    global terminate
379
371
    if signum == signal.SIGXCPU:
380
 
        terminate = "CPU time limit exceeded"
 
372
        terminate = "CPU Time Limit Exceeded"
381
373
 
382
374
def dispatch_msg(msg):
383
375
    global terminate
384
376
    if msg['cmd'] == 'terminate':
385
 
        terminate = "User requested restart"
 
377
        terminate = "User requested console be terminated"
386
378
    if terminate:
387
379
        raise ivle.chat.Terminate({"terminate":terminate})
388
380
    expiry.ping()
407
399
    for o in object:
408
400
        try:
409
401
            flat[o] = cPickle.dumps(object[o], PICKLEVERSION)
410
 
        except (TypeError, cPickle.PicklingError):
 
402
        except TypeError:
411
403
            try:
412
404
                o_type = type(object[o]).__name__
413
405
                o_name = object[o].__name__
420
412
if __name__ == "__main__":
421
413
    port = int(sys.argv[1])
422
414
    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]
423
424
 
424
425
    # Make python's search path follow the cwd
425
426
    sys.path[0] = ''