Introducing Hugh Nibley, and Making uTidyLib work under OS X

This took me the better part of an hour to figure out so I thought I’d share.

I’ve been trying to get Matt Turner‘s GetBook.py working. It’s a Python script to generate epub ebooks from the books made available online by the Neal A. Maxwell Institute for Religious Scholarship at Brigham Young University. He wrote it primarily to make ebooks from the available Collected Works of Hugh Nibley (which is how I found it, searching for Nibley’s works in ePub format), but it will work for any of the books on the website.

If you’re not familiar with Nibley’s work, a nice entry point is his excellent Victoriosa Loquacitas: The Rise of Rhetoric and the Decline of Everything Else.

Anyway… libtidy (one of the prereqs for the GetBook script) kept segfaulting on my Mac. Eventually, I found a forum describing problems the Python binding has in 64 bit environments. To fix the problem, I added the following line to the lib.py (on my system, /Library/Python/2.6/site-packages/tidy/lib.py) file. Find the following section in lib.py:

sinkfactory=SinkFactory()

class _Document(object):
def __init__(self):
self.cdoc = _tidy.Create()

And insert the line beginning _tidy as follows:

sinkfactory=SinkFactory()

_tidy.Create.restype = ctypes.POINTER(ctypes.c_void_p)

class _Document(object):
def __init__(self):
self.cdoc = _tidy.Create()

And now everything works! If you don’t find the code fix here particularly useful, at least you’ve had the opportunity to become acquainted with Nibley, who is one of my very, very favorite authors.