- # we hook a process so grepping runs in background.
- #debug('on background')
- global hook_file_grep, script_path, bytecode
- timeout = 1000*60*5 # 5 min
-
- quotify = lambda s: '"%s"' %s
- files_string = ', '.join(map(quotify, search_in_files))
-
- global tmpFile
- # we keep the file descriptor as a global var so it isn't deleted until next grep
- tmpFile = tempfile.NamedTemporaryFile(prefix=SCRIPT_NAME,
- dir=weechat.info_get('weechat_dir', ''))
- cmd = grep_process_cmd %dict(logs=files_string, head=head, pattern=pattern, tail=tail,
- hilight=hilight, after_context=after_context, before_context=before_context,
- exact=exact, matchcase=matchcase, home_dir=home_dir, script_path=script_path,
- count=count, invert=invert, bytecode=bytecode, filename=tmpFile.name,
- python=weechat.info_get('python2_bin', '') or 'python')
-
- #debug(cmd)
- hook_file_grep = weechat.hook_process(cmd, timeout, 'grep_file_callback', tmpFile.name)
- global pattern_tmpl
+ global hook_file_grep, grep_stdout, grep_stderr, pattern_tmpl
+ grep_stdout = grep_stderr = b''
+ hook_file_grep = weechat.hook_process(
+ 'func:grep_process',
+ get_config_int('timeout_secs') * 1000,
+ 'grep_process_cb',
+ ''
+ )