Saved for later reference

online repository of stuff I had to google for hours to figure out – and random snippets of code

Mercurial module for Python 2.6/Win32

Tags: , , , , , , ,

I’ve compiled Mercurial 1.5.4 for Python 2.6, following this guide, and uploaded it here, since I guess it’ll be useful for later:

mercurial-1.5.4.win32-py2.6.exe

I use it for Trac 0.12 in a multi-repository setting, so we can keep our old SVN repo while having some of the larger projects on Hg.

Share

Simple Python ctypes Example – in Windows

Tags: , , , , , ,

I found this blog post, Simple Python ctypes Example, on Reddit, and thought I’d see how different the procedure was for Windows.

What you’ll need:

Creating the DLL

Create a file dlltest.c with the following content:

1
2
3
4
5
6
7
8
9
10
11
12
#include <windows.h>

BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}

__declspec(dllexport) int
multiply(int num1, int num2)
{
return num1 * num2;
}

Start the Visual Studio 2008 Command Prompt from the Start Menu (this sets up the path for the compiler and other files, which makes things easier) and go to the directory you saved dlltest.c to.

Compile it with the following command:

cl -LD dlltest.c -Fetest.dll

Testing the DLL

As in the original Linux example, this DLL is easily tested using similar commands:

1
2
3
4
>>> from ctypes import *
>>> libtest = cdll.LoadLibrary('test.dll')
>>> print libtest.multiply(2, 2)
4

So, that is the simplest DLL possible, I’ll look at (same as the original blog post) applying it to more complex examples later.

Share

Making a Trac install work on Apache 2.2/Python 2.6/win32

Tags: , , , , ,

I recently upgraded the systems to Python 2.6, and the worst part of that was getting Trac to work again.

This guide assumes you have a working install of Trac on Python 2.5/mod_python/Apache2.2 already, as described in the Trac install guide, and that Python 2.6 is installed.

What needs to be done:

  • Install Python 2.6 and Trac for 2.6
  • Build a new version of mod_python
  • Build a new version of libsvn
  • Replace Apache DLLs

Required software

You’ll need Visual C++ 2008 Express Edition or any retail version of VS 2008.

Preparing

Install Python 2.6 and Trac on 2.6 (using “ easy_install trac” is recommended)

You’ll probably also want to easy_install Pygments for source highlighting.

Building mod_python for 2.6

This guide to mod_python covers the creation and installation of a compatible version of the module.

At this point, you should be able to restart Apache and load up your “old” Trac on Python 2.6, but with the error message that “svn” support is not installed.

A pre-built version of this can be found here:  mod_python-3.3.2-dev-20080819.win32-py2.6.exe

Building svn/libsvn for Python 2.6

Follow my previous guide to compile and install Python SVN bindings.

At this point, if you restart Apache, your Trac will most likely throw an exception about “_mod” being undefined.

Replacing Apache DLLs to make libsvn work

There’s a slight difference between libapr-1.dll as supplied with Apache 2.2 and the one we built together with libsvn, so the fix is to replace the one in your Apache2.2\bin folder with the one you built yourself, and copying all the libsvn*.dll files you built in the previous step to the same folder.

Restarting Apache now should make Trac work fully, with Subversion support.

Share

© 2009 Saved for later reference. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.