[Pythonmac-SIG] Spotlight and Python

David Reed dreedmac at columbus.rr.com
Wed May 11 16:51:34 CEST 2005


On May 11, 2005, at 2:28 AM, Jonathan Wight wrote:

> OK. The first version is online at:
>
> http://toxicsoftware.com/_private/Python%20Metadata%20Importer.pkg.zip
>
> The installer installs the mdimporter to /Library/Spotlight/ and  
> then calls mdimport -r to force Spotlight to reindex all Python files.
>
> You _may_ need Xcode installed to have this work successfully  
> (Apple defines the "public.python-script" UTI type - and it _may_  
> be defined in Xcode - I need to check).
>
> This version scans through .py files looking for function names and  
> class names. It adds them to the file's 'org_python_functions' and  
> 'org_python_classes' metadata attributes respectively
>
> You can view the python specific metadata using mdls
>
> [schwa at cobweb] Python Metadata Importer$ mdls *.py
> myimporter.py -------------
> kMDItemContentType         = "public.python-script"
> ... other metadata not shown ...
> kMDItemKind                = "Python Script"
> org_python_functions       = (find, main)
>
> And find it using mdfind:
>
> [schwa at cobweb] Spotlight$ mdfind "org_python_functions == 'main'" |  
> wc -l
>       41
>
> You can also use the Finder to search for functions/classes: bring  
> up a new search window, then choose "other…" in the attribute menu,  
> in the attribute search window look for the keyword "Python"... It  
> is quite impressive doing a search for python function names from  
> the finder.
>
> The importer actually uses an embedded python interpreter to parse  
> the python files (thanks to Bob for suggest the parser module). You  
> can see the python file inside the Resources folder of the  
> importer. The code currently leaks a few PyObjects so I'll be  
> working on that in the next version.
>
> Currently I do not add anything to kMDItemTextContent or any other  
> metadata attribute but this kind of stuff should be easy to do  
> (just a one line change to the Python code).
>
> Any feedback quite welcome.
>
> Cheers.
>
>     Jon.

Thanks for working on this. I'm not certain it is working correctly.  
I installed it about 3 hours ago so I would think it has had time to  
index my drive by now. It does seem to have indexed files that are  
part of python packages but it hasn't index Python files in my home  
directory and subdirectories. Is it skipping these on purpose or does  
it somehow not realize they are Python files (most of them were  
created with emacs and many on Linux systems before I switched to a  
Mac)? They all do have a .py extension.

Also, how do you uninstall your plugin?

I do have XCode installed.

Dave




More information about the Pythonmac-SIG mailing list