Using offlineimap on Snow Leopard – the really fugly hardcore solution

So, I got fed up with this issue now and found a solution that isn’t pretty. But it works, apparently without any relevant disadvantages, so I’ll live with it for the time being.

Update: in the comments below there’s a different, somewhat cleaner solution, which doesn’t require you to change your “system” Python files.

Yesterday I posted about the problem: offlineimap quits with a “trace trap”, which occurs when the line from _locale import * is executed.

For full reference, this line is line 31 of the file locale.py, which lives in your Python version’s library dir. For the standard Python 2.6 that comes with Snow Leopard, that path is /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6 — for your Python version the version number may vary, or in the case of a MacPorts installed Python, it’s going to be somewhere else entirely (/opt/local/lib/python2.5 for instance).

I tried hunting down the real origin of this problem, but I wasn’t able to find out anything in the end. I learned an awful lot about using the fantastic toolset that comes with Mac OS X and XCode (Python pdb and gdb, of course, but also the DTrace based stuff like Instruments, dtruss, opensnoop and the like — amazing stuff). But apart from demonstrating that _locale.so can apparently not be imported under the specific circumstances without crashing Python hard, I wasn’t able to get any further. I hope somebody will figure this out eventually.

Meanwhile, looking around the sources (isn’t open source wonderful… — some people always claim you can’t do anything useful with it), I found that there is actually a workaround implementation right there in locale.py. The offending import statement is nested in a try/except block and an exception called ImportError is caught. Presumably that’s the idea. Somehow the problem I’m seeing looks awfully like an import error to me, albeit more of a kick-your-ass-and-hopy-you-die sort of import error (that’s what they say, isn’t it?).

So. I just went and took out the import line and the try/except and left the code in place that would be executed in case of the ImportError. Brilliant, eh? Yeah well, I sort of hate it because I don’t like modifying something I’d call a “system library” from my point of view. Anyway. It works. offlineimap just synchronized about 400 messages or so. Cool.

In case you feel like doing the same thing, I’m making a patch file for the file locale.py available here: locale.py.patch

Please be aware that these instructions come without warranty!! They may not work for you or result in other issues! You follow these steps at your own risk!

In order to use the patch, follow these steps:

  1. Download the patch file and save it somewhere on your machine

  2. Find the correct path (see above) where your locale.py lives. Open a Terminal window and cd into that path.

  3. Make a backup copy of the original locale.py: sudo cp locale.py locale.py.orig

  4. Apply the patch with this command: sudo patch < /path/to/locale.py.patch

You should see output from the patch command saying patching file locale.py. This confirms that everything has gone to plan. Now try running offlineimap — it may just work.

Please be aware that these instructions come without warranty!! They may not work for you or result in other issues! You follow these steps at your own risk!

Have fun!

6 Comments on Using offlineimap on Snow Leopard – the really fugly hardcore solution

  1. Thanks so much for tracking this down and sharing the hack. Fugly and hardcore, as you say, but at least it works for now. You saved my Snow Leopard install

    Like

  2. If you instead just add:
    from locale import *
    before:
    from offlineimap import init

    does that also fix it for you?

    Like

  3. T. Joseph Carter // September 9, 2009 at 5:45 am // Reply

    Still a hack, but less fugly.

    Edit the offlineimap main script (the one you put into bin) and add “from locale import *” before “from offlineimap import init”.

    Suggestion from pogma in #fink on freenode. Works for me.

    Like

  4. Hey guys – yeah, that works! Thanks for stopping by and letting me know! 🙂

    I agree this is a rather cleaner workaround than mine. Cool!

    Like

  5. Good explanation, thanks. Maybe this is the point where we should stop calling this a hack then 🙂

    Like

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s