Monday, February 2, 2009

Puzzling over 'du' (disk usage)

Something (with 'du') that had me puzzled for a while:

I was looking at how much space was taken up by my MacPorts installation (on OS X 10.5.6).
I used the following alias to give me a breakdown by directory:
% alias sudodiskspace='sudo du -x -h -d 1'

% sudodiskspace /opt/local
9.1M /opt/local/bin
284K /opt/local/etc
12M /opt/local/include
83M /opt/local/lib
32K /opt/local/libexec
69M /opt/local/Library
68K /opt/local/sbin
107M /opt/local/share
175M /opt/local/var
455M /opt/local

% sudodiskspace /opt/local/var
1.0M /opt/local/var/cache
447M /opt/local/var/macports
448M /opt/local/var

That seemed strange - above it was reporting that the /opt/local/var directory was taking 175 MB, but now it is reporting that it takes up 448 MB.
I.e. 'du' seemed to be misreporting the space taken by sub-directories.

I thought something must be wrong and even resorted to looking at the source code for 'du' and I was considering building a version of 'du' that I could add debugging statements to.
But I decided to first look closer at what was in the /opt/local/var directory and so I did:
% ls -lR /opt/local/var | more
and scanning through the output, I started to notice that most of the files were listed as having 2 hard-links. Hmmm - that's unusual.
Sure enough, the files under /opt/local/var also occur (via hard-links) under /opt/local/include, /opt/local/lib, /opt/local/share, ...
So 'du' is giving me an accurate breakdown after all. But this points out that the breakdown from 'du' will be somewhat arbitrarily distributed across the sub-directories if they are sharing files via hard-links. (It depends on the order of traversal of the directories.)

Saturday, January 31, 2009

Installing Pygame on Leopard (OS X 10.5)

I was disappointed that the binary installers for Pygame available at expect that you have installed a version of Python from when Leopard (OS X 10.5) already comes with a perfectly good version of Python. I didn't want to install a whole separate version of Python just for Pygame.

So I decided to install Pygame from source. I followed the instructions on the "MacCompile" wiki at

Step 1:
I downloaded the latest versions of the SDL frameworks binaries for OS X (sometimes a bit more recent than the versions indicated on the above page):
SDL.framework 1.2.13
SDL_ttf.framework 2.0.9
SDL_mixer.framework 1.2.8
SDL_image.framework 1.2.7
and I copied the above framework folders from the DMGs to the /Library/Frameworks folder

Step 2:
I downloaded the source for the Numeric module (24.2) and then ran the command:
sudo python install
which installed some header files under /System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Numeric
and installed the Numeric module in /Library/Python/2.5/site-packages

Step 3:
I downloaded the combo installer for libpng & libjpeg from
and then renamed the libjpeg.dylib & libpng.dylib as recommended by the above instructions.

Step 4:
I downloaded the PyGame 1.8.1 source
and then (in the directory pygame-1.8.1release) ran the following command:
which gave the following output:

Using Darwin configuration...
Hunting dependencies...
Framework SDL found
Framework SDL_ttf found
Framework SDL_image found
Framework SDL_mixer found
Framework smpeg not found
PNG : found
JPEG : found
SCRAP : not found

Then I ran the following commands:
python build
sudo python install

As mentioned above, the Numeric module puts some header files into a "Numeric" sub-directory under /System/Library/Frameworks/Python.framework. That's not too bad, but I don't see why they couldn't have gone under /Library instead. The pygame stuff seems to have gone under /Library/Python/2.5/site-packages.

I tested the installation by running some of my Pygame programs - and it all seems to work fine.