Commit b2fdc9c4 authored by Fabien Morin's avatar Fabien Morin

add a new option to display all the occurences of the word (if the word is...

add a new option to display all the occurences of the word (if the word is three times in a file, display 3 lines)
This behavior is enable by default but can be disable by passing parameter first_occurence=1 to the external method


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25987 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eaeb5aae
...@@ -12,11 +12,11 @@ except: ...@@ -12,11 +12,11 @@ except:
skip_meta_types = ('Image', 'File') skip_meta_types = ('Image', 'File')
def traverse(ob, r, result, command_line_arguments): def traverse(ob, r, result, command_line_arguments, first_occurence):
if command_line_arguments['r'] and \ if command_line_arguments['r'] and \
hasattr(aq_base(ob), 'objectValues'): hasattr(aq_base(ob), 'objectValues'):
for sub in [o for o in ob.objectValues() if o.meta_type not in skip_meta_types]: for sub in [o for o in ob.objectValues() if o.meta_type not in skip_meta_types]:
traverse(sub, r, result, command_line_arguments) traverse(sub, r, result, command_line_arguments, first_occurence)
try: try:
if hasattr(aq_base(ob), 'manage_FTPget'): if hasattr(aq_base(ob), 'manage_FTPget'):
text = ob.manage_FTPget() text = ob.manage_FTPget()
...@@ -32,9 +32,10 @@ def traverse(ob, r, result, command_line_arguments): ...@@ -32,9 +32,10 @@ def traverse(ob, r, result, command_line_arguments):
i+1+command_line_arguments['A']] i+1+command_line_arguments['A']]
path = '/'.join(ob.getPhysicalPath()) path = '/'.join(ob.getPhysicalPath())
result.append((ob.absolute_url(), path, "\n".join(context))) result.append((ob.absolute_url(), path, "\n".join(context)))
break if first_occurence:
break
def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1): def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1, first_occurence=0):
if not _checkPermission(Permissions.ManagePortal, self): if not _checkPermission(Permissions.ManagePortal, self):
raise Unauthorized(self) raise Unauthorized(self)
command_line_arguments = {} # emulate grep command line args command_line_arguments = {} # emulate grep command line args
...@@ -42,12 +43,13 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1): ...@@ -42,12 +43,13 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1):
command_line_arguments['B'] = int(B) command_line_arguments['B'] = int(B)
command_line_arguments['r'] = int(r) command_line_arguments['r'] = int(r)
highlight = int(highlight) highlight = int(highlight)
first_occurence = int(first_occurence)
re_flags = 0 re_flags = 0
if int(i) : if int(i) :
re_flags = re.IGNORECASE re_flags = re.IGNORECASE
result = [] result = []
rx = re.compile(pattern, re_flags) rx = re.compile(pattern, re_flags)
traverse(self, rx, result, command_line_arguments) traverse(self, rx, result, command_line_arguments, first_occurence)
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
html = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' html = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment