How to Quickly Search Zope/Plone Code using Glimpse

by Jordan Baker last modified Dec 30, 2008 03:03 PM
Quickly search the entire Zope, CMF, Plone source from the command line using full-text indexer glimpse.

As you may have already found out being able to quickly find things in the Zope, CMF & Plone source is essential. The glimpse tool makes this a lot easier as it creates a command-line searchable interface for quick searching.

You can download glimpse from http://webglimpse.net/

Under OSX you can quickly install it via DarwinPorts:

$ sudo port install glimpse

In order to use it I've setup a couple aliases. Its been tested under OSX but should work under Linux and Solaris as well:

# Support to search Zope/Plone codebase via Glimpse (FAST!)
alias zcg='glimpse -H ~/zope.index'
alias zcgreindex='glimpseindex -H ~/zope.index  /sites/platforms/zcs/zope/lib/python /sites/platforms/zcs/Products'

You can add it to your .bash_profile so its available at each login. After changing this file, reload it so that the changes are recognized (otherwise the new aliases won't be recognized immediately):

$ source .bash_profile

Next, a folder must be created where the index will reside:

$ mkdir ~/zope.index

As well, a file which instructs to tool which files to exclude from the index. The file needs to be called '.glimpse_exclude' and must reside in the newly created 'zope.index' folder. The following line should be included in the file:

.svn

Now the index can be created:

$ zcgreindex

Once that is done you can search using zcg:

$ zcg "def getGroupMembers"
/sites/platforms/zcs/Products/GroupUserFolder/GroupDataTool.py:     def getGroupMembers(self, ):
/sites/platforms/zcs/Products/GroupUserFolder/interfaces/portal_groupdata.py:     def getGroupMembers():
/sites/platforms/zcs/Products/PlonePAS/interfaces/group.py:     def getGroupMembers(group_id):
/sites/platforms/zcs/Products/PlonePAS/plugins/group.py:     def getGroupMembers(self, group_id):
/sites/platforms/zcs/Products/PlonePAS/plugins/gruf.py:     def getGroupMembers(self, group_id):
/sites/platforms/zcs/Products/PlonePAS/tools/groupdata.py:     def getGroupMembers(self):
/sites/platforms/zcs/Products/PlonePAS/tools/groups.py:     def getGroupMembers(self, group_id):

[Note: putting def in front of the function name lets you search for where it is defined ]