[Erp5-report] r25987 - /erp5/trunk/products/ERP5/Extensions/Grep.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Mar 11 17:23:18 CET 2009
Author: fabien
Date: Wed Mar 11 17:23:17 2009
New Revision: 25987
URL: http://svn.erp5.org?rev=25987&view=rev
Log:
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
Modified:
erp5/trunk/products/ERP5/Extensions/Grep.py
Modified: erp5/trunk/products/ERP5/Extensions/Grep.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Extensions/Grep.py?rev=25987&r1=25986&r2=25987&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Extensions/Grep.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Extensions/Grep.py [utf8] Wed Mar 11 17:23:17 2009
@@ -12,11 +12,11 @@
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 \
hasattr(aq_base(ob), 'objectValues'):
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:
if hasattr(aq_base(ob), 'manage_FTPget'):
text = ob.manage_FTPget()
@@ -32,9 +32,10 @@
i+1+command_line_arguments['A']]
path = '/'.join(ob.getPhysicalPath())
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):
raise Unauthorized(self)
command_line_arguments = {} # emulate grep command line args
@@ -42,12 +43,13 @@
command_line_arguments['B'] = int(B)
command_line_arguments['r'] = int(r)
highlight = int(highlight)
+ first_occurence = int(first_occurence)
re_flags = 0
if int(i) :
re_flags = re.IGNORECASE
result = []
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">'
html = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'
More information about the Erp5-report
mailing list