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

« back to all changes in this revision

Viewing changes to scripts/python-console

  • Committer: dcoles
  • Date: 2008-08-14 03:51:51 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1018
Console: Improvements to the console python library so we can attempt to call 
any function using a string version of it's arguments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
            sys.stdout = self.webio
159
159
            sys.stderr = self.webio
160
160
            # We don't expect a return value - 'single' symbol prints it.
161
 
            eval(cmd, self.globs)
 
161
            self.eval(cmd)
162
162
            self.webio.flush()
163
163
            self.cmdQ.put({"okay": None})
164
164
            self.curr_cmd = ''
219
219
            elif 'call' in ln:
220
220
                if isinstance(ln['call'], dict):
221
221
                    params = ln['call']
222
 
                    if 'args' in params:
223
 
                        args = params['args']
224
 
                    else:
225
 
                        args = []
226
 
                    if 'kwargs' in params:
227
 
                        kwargs = params['kwargs']
228
 
                    else:
229
 
                        kwargs = {}
230
 
 
231
222
                    try:
232
 
                        function = cPickle.loads(params['function'])
 
223
                        # Expand parameters
 
224
                        if isinstance(params['args'], list):
 
225
                            args = map(self.eval, params['args'])
 
226
                        else:
 
227
                            args = []
 
228
                        if isinstance(params['kwargs'], dict):
 
229
                            kwargs = {}
 
230
                            for kwarg in params['kwargs']:
 
231
                                kwargs[kwarg] = self.eval(
 
232
                                    params['kwargs'][kwarg])
 
233
                        else:
 
234
                            kwargs = {}
 
235
 
 
236
                        # Run the fuction
 
237
                        function = self.eval(params['function'])
233
238
                        result = function(*args, **kwargs)
234
239
                        self.cmdQ.put({'output': result})
235
 
                    except Exception,e:
236
 
                        self.cmdQ.put({'response': 'failure: %s'%repr(e)})
 
240
                    except Exception, e:
 
241
                        tb = format_exc_start(start=1)
 
242
                        self.cmdQ.put(
 
243
                            {"exc": ''.join(tb).decode('utf-8', 'replace')})
237
244
                else:
238
245
                    self.cmdQ.put({'response': 'failure'})
239
246
            elif 'inspect' in ln:
249
256
                    sys.stderr = stderr
250
257
                    # We don't expect a return value - 'single' symbol prints 
251
258
                    # it.
252
 
                    eval(cmd, self.globs)
 
259
                    self.eval(cmd)
253
260
                except Exception, e:
254
261
                    exception = {}
255
262
                    tb = format_exc_start(start=1)
269
276
            else:
270
277
                raise Exception, "Invalid Command"
271
278
 
 
279
    def eval(self, source):
 
280
        """ Evaluates a string in the private global space """
 
281
        return eval(source, self.globs)
 
282
 
272
283
def daemonize():
273
284
    if os.fork():   # launch child and...
274
285
        os._exit(0) # kill off parent