~ubuntu-branches/ubuntu/precise/gedit/precise

« back to all changes in this revision

Viewing changes to plugins/externaltools/tools/capture.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-04-14 16:41:13 UTC
  • mfrom: (1.1.78 upstream)
  • Revision ID: james.westby@ubuntu.com-20100414164113-0xgl3u73pcs0ngbc
Tags: 2.30.0git20100413-0ubuntu1
* Updating to git snaptshot since 2.30.1 will be after lucid
* debian/patches/90_autoconf.patch:
  - new version update

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import subprocess
24
24
import gobject
25
25
import fcntl
 
26
import glib
26
27
 
27
28
class Capture(gobject.GObject):
28
29
    CAPTURE_STDOUT = 0x01
113
114
                                 gobject.IO_IN | gobject.IO_HUP,
114
115
                                 self.on_output)
115
116
 
116
 
        # IO        
 
117
        # IO
117
118
        if self.input_text is not None:
118
119
            # Write async, in chunks of something
119
120
            self.write_buffer = str(self.input_text)
140
141
                self.pipe.stdin.close()
141
142
                
142
143
                self.idle_write_id = 0
 
144
 
143
145
                return False
144
146
            else:
145
147
                self.write_buffer = self.write_buffer[m:]
151
153
            return False
152
154
 
153
155
    def on_output(self, source, condition):
154
 
        line = source.read()
155
 
 
156
 
        if len(line) > 0:
157
 
            try:
158
 
                line = unicode(line, 'utf-8')
159
 
            except:
160
 
                line = unicode(line,
161
 
                               locale.getdefaultlocale()[1],
162
 
                               'replace')
163
 
 
164
 
            self.read_buffer += line
165
 
            lines = self.read_buffer.splitlines(True)
166
 
            
167
 
            if not lines[-1].endswith("\n"):
168
 
                self.read_buffer = lines[-1]
169
 
                lines = lines[0:-1]
170
 
            else:
171
 
                self.read_buffer = ''
172
 
 
173
 
            for line in lines:
174
 
                if not self.pipe or source == self.pipe.stdout:
175
 
                    self.emit('stdout-line', line)
 
156
        if condition & (glib.IO_IN | glib.IO_PRI):
 
157
            line = source.read()
 
158
 
 
159
            if len(line) > 0:
 
160
                try:
 
161
                    line = unicode(line, 'utf-8')
 
162
                except:
 
163
                    line = unicode(line,
 
164
                                   locale.getdefaultlocale()[1],
 
165
                                   'replace')
 
166
 
 
167
                self.read_buffer += line
 
168
                lines = self.read_buffer.splitlines(True)
 
169
                
 
170
                if not lines[-1].endswith("\n"):
 
171
                    self.read_buffer = lines[-1]
 
172
                    lines = lines[0:-1]
176
173
                else:
177
 
                    self.emit('stderr-line', line)
178
 
 
179
 
            return True
180
 
        else:
 
174
                    self.read_buffer = ''
 
175
 
 
176
                for line in lines:
 
177
                    if not self.pipe or source == self.pipe.stdout:
 
178
                        self.emit('stdout-line', line)
 
179
                    else:
 
180
                        self.emit('stderr-line', line)
 
181
 
 
182
        if condition & ~(glib.IO_IN | glib.IO_PRI):
181
183
            if self.read_buffer:
182
184
                if source == self.pipe.stdout:
183
185
                    self.emit('stdout-line', self.read_buffer)
184
186
                else:
185
187
                    self.emit('stderr-line', self.read_buffer)
186
 
                
 
188
 
187
189
                self.read_buffer = ''
188
 
            
 
190
 
189
191
            self.pipe = None
190
192
 
191
 
        return False
 
193
            return False
 
194
        else:
 
195
            return True
192
196
 
193
197
    def stop(self, error_code = -1):
194
198
        if self.pipe is not None: