parent
c35e72d6fc
commit
95f63f3ca2
27
method.py
27
method.py
|
@ -1398,3 +1398,30 @@ class RegisterRestore(Method):
|
|||
if len(name) > self.MAX_REG:
|
||||
name = name[0:self.MAX_REG] + '...'
|
||||
w.set_error('Restored %r from register %r' % (text2, name2))
|
||||
|
||||
class Grep(Method):
|
||||
'''help here'''
|
||||
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
|
||||
def _execute(self, w, **vargs):
|
||||
cmd = ("/usr/bin/grep", '-E', '-n', vargs['pattern'], '-')
|
||||
pipe = popen2.Popen3(cmd, capturestderr=True)
|
||||
pid = pipe.pid
|
||||
|
||||
indata = w.buffer.make_string()
|
||||
pipe.tochild.write(indata)
|
||||
pipe.tochild.close()
|
||||
|
||||
outdata = pipe.fromchild.read()
|
||||
errdata = pipe.childerr.read()
|
||||
status = pipe.wait() >> 8
|
||||
|
||||
if status == 0:
|
||||
num = len(outdata.split('\n'))
|
||||
w.application.data_buffer("*Grep*", outdata, switch_to=True)
|
||||
w.application.set_error("Grep: %d matches found" % num)
|
||||
elif status == 1:
|
||||
w.application.set_error("Grep: no matches found")
|
||||
else:
|
||||
w.application.data_buffer("*Grep*", outdata, switch_to=True)
|
||||
w.set_error("Grep: error (exited with status %d)" % status)
|
||||
|
Loading…
Reference in New Issue