January 2010

Thrift with Python on Win32


Thrift is a wonderful protocol, it’s all sum up in a single paragraph:


Thrift is a software framework for scalable cross-language services development. It combines a powerful software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, and Ruby. Thrift was developed at Facebook and released as open source.

And I really like it especially now since the system I’ve build and supporting now are written in python / c++ / ruby, these systems need to talk to each other, thrift, it’s like the answers to the prayers! : )

I have back-end systems that runs in Linux, and has client app that runs in Windows. Compiling and using thrift in Linux based system are straight forward, but unfortunately its not as easy in MS Windows platform.

At this time of writing, the code checkout from Thrift Apache Incubator still need to be further modify so that it can be compile with MSVC. These are the steps I’ve went through to get the thrift for python to build:

Ingredient:
1. Python 2.6.4
2. Visual C++ 2008 Express Edition
3. thrift-incubating-0.2.0.tar.gz
4. Windows Xp (obviously)

Read this post at http://issues.apache.org/jira/browse/THRIFT-252 to understands what needs to be edit.

Build thrift for python:
1. On Linux machine, apply the patch to the thrift source. Yes, on Linux machine, or you’ll have line ending problem.
2. Install python 2.6.4 and Visual C++ 2008 Express Edition on your Windows XP machine.
3. Copy the patched thrift source to your Windows machine, e.g: C:\tmp\thrift-0.2.0\
4. Start a command prompt and follow the following steps:

C:\> cd c:\tmp\thrift-0.2.0\lib\py\
C:\tmp\thrift-0.2.0\lib\py> python setup.py install

That’s it! Everything should compile and install to your python site-package directory. To test just do the following:

C:\> python
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import thrift
>>>

No error is good news : )

I had to modify the patch by Michael Greene to fix a problem where the LITTLE_ENDIAN and BIG_ENDIAN was not define in my attempt of getting it build with MSVC9, other than that, everything else he did work marvelously, thanks! : )

Here’s the diff file that work for me, and the binary build that should work for python 2.6.4 on Windows.

just the diff file to modify fastbinary.c and setup.py
thrift-0.2.0-msvc-patch.diff

the patched source package:
thrift-0.2.0-msvc-patched.tar.gz

if you want to skip the compilation and just want to thrift right away with python 2.6.4, here’s the binary, extract and copy to C:\Python26\Lib\site-packages\
thrift-python-2.6.4-win32.zip

NOTE: Due to the source of thrift are still actively being improve, it’s best not to apply the diff to the source you’ve just check out, as it MAY have already been fix, its best to open up the related files, and read through, to make sure the patch is still needed.

Goodbye NucleusCMS.

I’ve been a happy NucleusCMS user since the beginning of me blogging years back, but the recent problem with the spam on the comment is forcing me to move to a blog engine that has better spam management interface. i.e: comment approval system… etc. Believe me, I’ve tried all the spam fighting plugins available to NucleusCMS already, but it work to an extend that I still need to manually clear out hundreds of spam message manually.

A short searching around the web shows me that wordpress seems to be a good replacement, I really like the admin interface, and it even come with import engine to convert an existing blog!

Following the guide at wordpress, with some luck, I’ve manage to get all the entry from my Nucleus blog into the newly installed wordpress : )

Some comment in blog post are missing, not sure why, and I can’t tell if this will help be combat the comment spam more effectively, but I’m still happy.