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

« back to all changes in this revision

Viewing changes to scripts/python-console

  • Committer: drtomc
  • Date: 2008-02-28 04:10:59 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:599
console: improve end of line handling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        del lines[-1]
64
64
 
65
65
        if len(lines) > 0:
66
 
            self.cmdQ.put({"output":lines})
 
66
            lines.append('')
 
67
            text = "\n".join(lines)
 
68
            self.cmdQ.put({"output":text})
67
69
            expiry.ping()
68
70
            ln = self.lineQ.get()
69
71
            if 'interrupt' in ln:
70
72
                raise Interrupt()
71
73
 
72
74
    def flush(self):
73
 
        res = self.remainder
74
 
        self.remainder = ''
75
 
        return res
 
75
        if len(self.remainder) > 0:
 
76
            self.cmdQ.put({"output":self.remainder})
 
77
            expiry.ping()
 
78
            ln = self.lineQ.get()
 
79
            self.remainder = ''
 
80
            if 'interrupt' in ln:
 
81
                raise Interrupt()
76
82
 
77
83
class PythonRunner(Thread):
78
84
    def __init__(self, cmdQ, lineQ):
79
85
        self.cmdQ = cmdQ
80
86
        self.lineQ = lineQ
81
 
        self.out = None
 
87
        self.stdout = None
82
88
        Thread.__init__(self)
83
89
 
84
90
    def execCmd(self, cmd):
85
91
        try:
86
92
            sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
87
 
            self.out = StdoutToWeb(self.cmdQ, self.lineQ)
88
 
            sys.stdout = self.out
89
 
            sys.stderr = self.out
 
93
            self.stdout = StdoutToWeb(self.cmdQ, self.lineQ)
 
94
            sys.stdout = self.stdout
 
95
            sys.stderr = self.stdout
90
96
            res = eval(cmd, self.globs, self.locls)
91
 
            self.cmdQ.put({"okay":(self.out.flush(),res)})
 
97
            self.stdout.flush()
 
98
            self.cmdQ.put({"okay":res})
92
99
            self.curr_cmd = ''
93
100
        except Exception, exc:
94
 
            self.cmdQ.put({"exc":(self.out.flush(),str(exc))})
 
101
            self.stdout.flush()
 
102
            self.cmdQ.put({"exc":str(exc)})
95
103
            self.curr_cmd = ''
96
104
 
97
105
    def run(self):
118
126
                    else:
119
127
                        self.execCmd(cmd)
120
128
                except Exception, exc:
121
 
                    self.cmdQ.put({"exc":(self.out.flush(),str(exc))})
 
129
                    self.stdout.flush()
 
130
                    self.cmdQ.put({"exc":str(exc)})
122
131
                    self.curr_cmd = ''
123
132
            if 'block' in ln:
124
133
                # throw away a partial command.
126
135
                    cmd = compile(ln['block'], "<web session>", 'exec');
127
136
                    self.execCmd(cmd)
128
137
                except Exception, exc:
129
 
                    self.cmdQ.put({"exc":(self.out.flush(),str(exc))})
 
138
                    self.stdout.flush()
 
139
                    self.cmdQ.put({"exc":str(exc)})
130
140
                    self.curr_cmd = ''
131
141
 
132
142
def daemonize():