From 62a7ab90f6e9323c7141d023d44820abda6500ec Mon Sep 17 00:00:00 2001 From: Yoshinori Okuji <yo@nexedi.com> Date: Thu, 24 Nov 2005 18:55:24 +0000 Subject: [PATCH] This is a simple implementation of grep for ZODB. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4402 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Extensions/Grep.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 product/ERP5/Extensions/Grep.py diff --git a/product/ERP5/Extensions/Grep.py b/product/ERP5/Extensions/Grep.py new file mode 100755 index 0000000000..586cb5712c --- /dev/null +++ b/product/ERP5/Extensions/Grep.py @@ -0,0 +1,31 @@ +import re +import cgi + +def traverse(ob, r, result): + if hasattr(ob, 'objectValues'): + for sub in ob.objectValues(): + traverse(sub, r, result) + try: + text = ob.manage_FTPget() + except: + text = None + if text: + for l in text.split('\n'): + if r.search(l) is not None: + path = '/'.join(ob.getPhysicalPath()) + result.append((path, l)) + break + +def grep(self, pattern): + result = [] + traverse(self, re.compile(pattern), result) + html_element_list = ['<html>', '<body>'] + for path, line in result: + path = cgi.escape(path) + line = cgi.escape(line) + html_element_list.append('<a href="%s/manage_workspace">%s</a>: %s<br/>' % ( +path, path, line)) + html_element_list.extend(['</body>', '</html>']) + self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/html') + return '\n'.join(html_element_list) + -- 2.30.9