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

« back to all changes in this revision

Viewing changes to services/python-console

  • Committer: William Grant
  • Date: 2009-06-29 01:55:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: grantw@unimelb.edu.au-20090629015555-49xxv0piiieunx8e
Add docs on configuring Apache.

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
170
171
 
171
172
    def run(self):
172
173
        # Set up global space and partial command buffer
173
 
        self.globs = {'__name__': '__main__'}
 
174
        self.globs = {}
174
175
        self.curr_cmd = ''
175
176
 
176
177
        # Set up I/O to use web interface
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 == '':
262
254
    def handle_globals(self, params):
263
255
        # Unpickle the new space (if provided)
264
256
        if isinstance(params, dict):
265
 
            self.globs = {'__name__': '__main__'}
 
257
            self.globs = {}
266
258
            for g in params:
267
259
                try:
268
260
                    self.globs[g] = cPickle.loads(params[g])
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] = ''