[Pythonmac-SIG] [Pythonmac-SIG] Spotlight and Python

Jonathan Wight jwight_lists at toxicsoftware.com
Fri May 13 06:43:37 CEST 2005


Version 0.7 is now online at:

http://toxicsoftware.com/_private/Python%20Metadata%20Importer/Version 
%200.7/Python%20Metadata%20Importer.dmg

Thanks to David Reed for helping me test and iron out the Unicode  
problems.

This version should work for pretty much anyone (famous last words).  
I've added added support for Unicode data, NSDate support, more  
robust error handling.

I'm going to add support for file level PythonDoc comments and for  
the file level python metadata (__author__, __date__ and so on) in  
the next version. I'll be putting the code online soon.

     Jon.

On May 11, 2005, at 02:28, 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.
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>
>
>





More information about the Pythonmac-SIG mailing list