[mac] archive category

Doctoring EXIF data for Sun Media (aka Ignatieff in Kuwait)

Not Iggy

A lot hinged on the veracity of the picture — the low-resolution image furnished to Teneycke lacked critical metadata that would have helped determine the time the picture was taken. However, the report that accompanied the picture referred to those metadata. (Pierre Karl Peladeau
President and CEO of Sun Media Corporation
)

Before sending your hoax photos to anybody at Sun Media, you better make sure that you doctor the EXIF metadata because they will check – trust me. You’re a busy lobbyist and you don’t have time to learn all about this nerdy stuff (metadata wazzat???). No problem, this is what you do.

First, get your doctored photo and open it with a metadata editor like ExifTool There are others available but you’re in a rush and there is an election afoot and you have a ton of disinformation that has to get out – today!

Well, as luck would have it, there is no metadata on your pic. Don’t panic! Your Iggy pic backstory is that he was in Kuwait so you need to copy legit metadata from a pic taken in Kuwait. Go ask Google Image search, type “Kuwait army” and restrict your results to large pictures. The reason that we are selecting only “large” images is that we want the original/unedited large size pics taken by some US military photographer – the exact ones downloaded off the camera. They are always huge files. I found one from Military Sealift Command from 2007 which is good enough for our demo. Save it to your current working directory as we are going to copy the EXIF metadata to make it look like our hoax pic was taken in Kuwait.

Using ExifTool, copy all the metadata from the authentic Kuwait photo to your fake Iggy pic (only one command – w00t):

$ exiftool -tagsFromFile metadata_source.jpg not_ignatieff_exif.jpg

Now, if you’re particularly lazy or busy you can stop there since the metadata is now copied. If you have more time on your hands you can actually edit the individual entries and geocode the photo. Check out what we did:

$ exiftool -list not_ignatieff_exif.jpg
ExifTool Version Number         : 8.56
File Name                       : not_ignatieff_exif.jpg
Directory                       : .
File Size                       : 78 kB
File Modification Date/Time     : 2011:04:27 13:18:53-07:00
File Permissions                : rw-r--r--
File Type                       : JPEG
MIME Type                       : image/jpeg
JFIF Version                    : 1.02
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : NIKON CORPORATION
Camera Model Name               : NIKON D2X
Orientation                     : Horizontal (normal)
X Resolution                    : 300
Y Resolution                    : 300
Resolution Unit                 : inches
Software                        : Adobe Photoshop CS2 Windows
Modify Date                     : 2007:09:24 12:06:07
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/180
F Number                        : 13.0
Exposure Program                : Aperture-priority AE
ISO                             : 100
Exif Version                    : 0221
Date/Time Original              : 2007:08:29 10:47:40
Create Date                     : 2007:08:29 10:47:40
Components Configuration        : Y, Cb, Cr, -
Exposure Compensation           : -2/3
Max Aperture Value              : 4.0
Metering Mode                   : Multi-segment
Light Source                    : Unknown
Flash                           : No Flash
Focal Length                    : 20.0 mm
User Comment                    : 
Sub Sec Time                    : 00
Sub Sec Time Original           : 00
Sub Sec Time Digitized          : 00
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 2100
Exif Image Height               : 1395
Sensing Method                  : One-chip color area
File Source                     : Digital Camera
Scene Type                      : Directly photographed
CFA Pattern                     : [Red,Green][Green,Blue]
Custom Rendered                 : Normal
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1
Focal Length In 35mm Format     : 30 mm
Scene Capture Type              : Standard
Gain Control                    : None
Contrast                        : Normal
Saturation                      : Normal
Sharpness                       : Normal
Subject Distance Range          : Unknown
GPS Version ID                  : 2.2.0.0
Compression                     : JPEG (old-style)
Thumbnail Offset                : 934
Thumbnail Length                : 5386
Current IPTC Digest             : 460cf28926b856dab09c01a1b0a79077
Application Record Version      : 2
Copyright Flag                  : False
Global Angle                    : 30
Global Altitude                 : 30
XMP Toolkit                     : Image::ExifTool 8.56
Format                          : image/jpeg
Compressed Bits Per Pixel       : 2
Date/Time Digitized             : 2007:08:29 10:47:40-04:00
Flash Fired                     : False
Flash Function                  : False
Flash Mode                      : Unknown
Flash Red Eye Mode              : False
Flash Return                    : No return detection
Color Mode                      : RGB
ICC Profile Name                : sRGB IEC61966-2.1
Creator Tool                    : Adobe Photoshop CS2 Windows
Metadata Date                   : 2007:09:24 12:06:07-04:00
Derived From Document ID        : adobe:docid:photoshop:0f10c753-6154-11dc-9f27-a9bb9c4b68e4
Derived From Instance ID        : adobe:docid:photoshop:0f10c753-6154-11dc-9f27-a9bb9c4b68e4
Document ID                     : uuid:FF3F520BB86ADC11827AB2BAB20EBAFA
Instance ID                     : uuid:319A5A0FB86ADC11827AB2BAB20EBAFA
History                         : 
Quality                         : 60%
DCT Encode Version              : 100
APP14 Flags 0                   : [14], Encoded with Blend=1 downsampling
APP14 Flags 1                   : (none)
Color Transform                 : YCbCr
Image Width                     : 640
Image Height                    : 480
Encoding Process                : Progressive DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:4:4 (1 1)
Aperture                        : 13.0
Shutter Speed                   : 1/180
Create Date                     : 2007:08:29 10:47:40.00
Date/Time Original              : 2007:08:29 10:47:40.00
Modify Date                     : 2007:09:24 12:06:07.00
Thumbnail Image                 : (Binary data 5386 bytes, use -b option to extract)
Image Size                      : 640x480
Light Value                     : 14.9
Scale Factor To 35 mm Equivalent: 1.5
Circle Of Confusion             : 0.020 mm
Field Of View                   : 61.9 deg
Focal Length                    : 20.0 mm (35 mm equivalent: 30.0 mm)
Hyperfocal Distance             : 1.54 m

Note: This is a parody entry. Don’t send any doctored pics to Sun Media. Also, don’t trust metadata as proof of anything.

Tags: , , , , , , ,

Manage multiple SSH private keys with IdentityFile

There are many guides that show you how to set-up your SSH client for password-less login using public-private key certificates. If you have different clients, you may have several different private keys. How can you manage them?

It was pointed out that ssh-agent and PuTTY’s Pagent can also be used to manage multiple private keys.

SSH has a per-user configuration file called ‘~/.ssh/config’ that it can use to select your private keys based on the remote user name and remote host by using wildcards. Let’s check out my ‘config’ file:

IdentityFile ~/.ssh/ids/%h/%r/id_rsa
IdentityFile ~/.ssh/ids/%h/%r/id_dsa
IdentityFile ~/.ssh/ids/%h/id_rsa
IdentityFile ~/.ssh/ids/%h/id_dsa
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/id_dsa

The percent-h and percent-r take the host and the remote user from your SSH user and hostname arguments. Consider this example command:

$ ssh remote_user@remote_hostname.example.com

From the example command, the SSH client would use the wildcards to seek the correct key to use:

~/.ssh/ids/remote_hostname.example.com/remote_user/

This means that if you had two private keys that you used to access two different servers, you would arrange them as follows. The first one is arranged as follows:

$ ls -l ~/.ssh/ids/remote.example.com/remote_user/
total 16
-rw-------  1 kelvin  staff  668 Mar 24 20:09 id_dsa
-rw-r--r--  1 kelvin  staff  610 Mar 24 20:09 id_dsa.pub
$ ssh remote_user@remote.example.com
[remote_user@remote ~]$

Our second example uses a simple hostname. If a remote user is not required, you can just use the hostname:

$ ls -l ~/.ssh/ids/webby.example.org/
total 16
-rw-------  1 kelvin  staff  668 Mar 24 20:09 id_rsa
-rw-r--r--  1 kelvin  staff  610 Mar 24 20:09 id_rsa.pub
$ ssh webby.example.org
[webby ~]$

For sure, these are totally contrived examples, but you can watch the cascade yourself by adding the verbosity flag(s) to your SSH client session (this one is my client’s WebFaction account):

Trinity:.ssh kelvin$ ssh -v user@user.webfactional.com
OpenSSH_5.2p1, OpenSSL 0.9.7l 28 Sep 2006
debug1: Reading configuration data /Users/kelvin/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to user.webfactional.com [192.168.0.254] port 22.
debug1: Connection established.
debug1: identity file /Users/kelvin/.ssh/ids/user.webfactional.com/user/id_rsa type -1
debug1: identity file /Users/kelvin/.ssh/ids/user.webfactional.com/user/id_dsa type 2
debug1: identity file /Users/kelvin/.ssh/ids/user.webfactional.com/id_rsa type -1
debug1: identity file /Users/kelvin/.ssh/ids/user.webfactional.com/id_dsa type -1
debug1: identity file /Users/kelvin/.ssh/id_rsa type 1
debug1: identity file /Users/kelvin/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'user.webfactional.com' is known and matches the RSA host key.
debug1: Found key in /Users/kelvin/.ssh/known_hosts:41
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/kelvin/.ssh/ids/user.webfactional.com/user/id_rsa
debug1: Offering public key: /Users/kelvin/.ssh/ids/user.webfactional.com/user/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen 433
debug1: read PEM private key done: type DSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
Last login: Thu Mar 31 22:31:08 2015 from 192.168.0.200
[user@web ~]$

Tags: , , , ,

MySQL-Python with Python for Mac and 64-bit MySQL errors

LONG_BIT errors getting you down? If you are building MySQL-Python with the DMG version of Python 2.5.4 then make sure that you have a 32-bit version of MySQL installed or else you will see a variation of this:

(visions)Trinity:envs kelvin$ easy_install -Z mysql_python
Searching for mysql-python
Reading http://pypi.python.org/simple/mysql_python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best match: MySQL-python 1.2.3
Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
Processing MySQL-python-1.2.3.tar.gz
Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /var/folders/L4/L4q9U6sBHceoN-EDstAkL++++TI/-Tmp-/easy_install-rniNnX/MySQL-python-1.2.3/egg-dist-tmp-4WCvXJ
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:57,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
In file included from _mysql.c:36:
/usr/local/mysql/include/my_config.h:1062:1: warning: "HAVE_WCSCOLL" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:721:1: warning: this is the location of the previous definition
In file included from _mysql.c:36:
/usr/local/mysql/include/my_config.h:1180:1: warning: "SIZEOF_LONG" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:811:1: warning: this is the location of the previous definition
In file included from _mysql.c:36:
/usr/local/mysql/include/my_config.h:1189:1: warning: "SIZEOF_PTHREAD_T" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:820:1: warning: this is the location of the previous definition
error: Setup script exited with error: command 'gcc' failed with exit status 1

If you check, you will find that SIZEOF_LONG is 4 and LONG_BIT is 64 (should be 32) if you are using the 32-bit version of Python 2.5.4 and you have the 64-bit version of MySQL Community Server installed. The pyport.h file will catch it and raise the error — thanks pyport!

The solution for me was to uninstall my 64-bit version of MySQL and install the 32-bit version which was way down on the list of installers. Another solution would be just to use MacPorts to build all your Python bits.

Once the offending version of MySQL was replaced, MySQL-Python installed with only a minor warning. It was immediately usable:

Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> MySQLdb.__version__
'1.2.3'
>>>

And if you are still running Python 2.5.4 try upgrading to Python 2.6.4

Tags: , ,

Install PHP 5.3.3 on Mac OS Leopard 10.5.8

My attempt at building and installing PHP 5.3.3 crashed and burned with the following error while building the MySQLi extension:

/bin/sh /Users/kelvin/phpsource/php-5.3.3/libtool --silent --preserve-dup-deps --mode=compile gcc  -Iext/mysqli/ -I/Users/kelvin/phpsource/php-5.3.3/ext/mysqli/ -DPHP_ATOM_INC -I/Users/kelvin/phpsource/php-5.3.3/include -I/Users/kelvin/phpsource/php-5.3.3/main -I/Users/kelvin/phpsource/php-5.3.3 -I/Users/kelvin/phpsource/php-5.3.3/ext/date/lib -I/Users/kelvin/phpsource/php-5.3.3/ext/ereg/regex -I/usr/local/php5/include/libxml2 -I/usr/local/php5/include -I/opt/local/include -I/usr/local/php5/include/freetype2 -I/Users/kelvin/phpsource/php-5.3.3/ext/mbstring/oniguruma -I/Users/kelvin/phpsource/php-5.3.3/ext/mbstring/libmbfl -I/Users/kelvin/phpsource/php-5.3.3/ext/mbstring/libmbfl/mbfl -I/usr/local/mysql/include/mysql -I/Users/kelvin/phpsource/php-5.3.3/ext/sqlite3/libsqlite -I/usr/local/pgsql/include -I/Users/kelvin/phpsource/php-5.3.3/TSRM -I/Users/kelvin/phpsource/php-5.3.3/Zend  -no-cpp-precomp  -I/usr/local/php5/include -g -O2 -fvisibility=hidden  -c /Users/kelvin/phpsource/php-5.3.3/ext/mysqli/mysqli.c -o ext/mysqli/mysqli.lo 
 In file included from /Users/kelvin/phpsource/php-5.3.3/ext/mysqli/php_mysqli_structs.h:57,
                  from /Users/kelvin/phpsource/php-5.3.3/ext/mysqli/mysqli.c:33:
 /usr/local/mysql/include/mysql/my_global.h:895: error: duplicate ‘unsigned’
 /usr/local/mysql/include/mysql/my_global.h:895: warning: useless type name in empty declaration
 make: *** [ext/mysqli/mysqli.lo] Error 1
Trinity:~ kelvin$

According to the PHP bug tracker, the problem is a bug that affects Snow Leopard and FreeBSD as well. The fix is pretty simple, either you can build PHP from the head of the trunk from Subversion, or you can replace php-5.3.3/ext/mysqli/php_mysqli_structs.h with this patched version or you can just open one file (php-5.3.3/ext/mysqli/php_mysqli_structs.h) in your text editor and fix it yourself:

Trinity:~ kelvin$ sudo vim /Users/kelvin/phpsource/php-5.3.3/ext/mysqli/php_mysqli_structs.h

Go to line 59 and insert the following:

59
60
61
#if defined(ulong) && !defined(HAVE_ULONG)
#define HAVE_ULONG
#endif

The patched section of the file will then read as follows:

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
  The libmysql headers (a PITA) also define it and there will be an warning.
  Undef it and later we might need to define it again.
*/
#ifdef HAVE_MBRLEN
#undef HAVE_MBRLEN
#define WE_HAD_MBRLEN
#endif
#ifdef HAVE_MBSTATE_T
#undef HAVE_MBSTATE_T
#define WE_HAD_MBSTATE_T
#endif
 
#if defined(ulong) && !defined(HAVE_ULONG)
#define HAVE_ULONG
#endif
 
#include <my_global.h>
 
#if !defined(HAVE_MBRLEN) && defined(WE_HAD_MBRLEN)
#define HAVE_MBRLEN 1
#endif
 
#if !defined(HAVE_MBSTATE_T) && defined(WE_HAD_MBSTATE_T)
#define HAVE_MBSTATE_T 1
#endif

The rest of the build and install was uneventful after patching php_mysqli_structs.h.

Tags: , ,

Running Cassandra 0.5.0 on Mac OS X Leopard 10.5.8

This is a short post showing you how to install the superdooper Key-Value Store Cassandra version 0.5.0 on a Macbook running OS X Leopard 10.5.8 (yeah I know, I should upgrade to Snow Leopard sometime). Cassandra 0.5 promises to be peppier than the 0.4 version and at this point it hasn’t been released yet, but I’m impatient, so I’m setting up a ‘one-node cluster’ for fun.

Cassandra 0.5.0 was released on 25 Jan 2010.

You will need to ensure that you are running Java 1.6. Since Java 1.5 is the default on Mac OS X, you need to set up a couple of environment variables. I just put the following into my .bash_profile file using vim.

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
export PATH=$JAVA_HOME/bin:$PATH

Now source the file (if you haven’t already done that) and examine your set-up.

Trinity:~ kelvin$ source .bash_profile
Trinity:~ kelvin$ env | grep JAVA_HOME
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
Trinity:~ kelvin$ java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-9M3125)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)
Trinity:~ kelvin$ xcodebuild -version
Xcode 3.1.2
Component versions: DevToolsCore-1148.0; DevToolsSupport-1102.0
BuildVersion: 9M2621

Yeah, my xcode is a bit old too. So, once that is done, download Cassandra. I am going to use the tag in the Subversion repository for the 0.5.0 release.

Trinity:code kelvin$ svn co https://svn.apache.org/repos/asf/incubator/cassandra/tags/cassandra-0.5.0/ cassandra-0.5.0

...svn key gibberish redacted...

A    cassandra-0.5.0/NOTICE.txt
 cassandra-0.5.0/src/java/org/apache/cassandra/io/StreamRequestVerbHandler.java
...checkout redacted...
A    cassandra-0.5.0/build.xml
 U   cassandra-0.5.0
Checked out revision 902040.
Trinity:code kelvin$ cd cassandra-0.5.0
Trinity:cassandra-0.5.0 kelvin$ pwd
/Users/kelvin/code/cassandra-0.5.0
Trinity:cassandra-0.5.0 kelvin$

Cassandra expects some folders to be available, so we will need to set them up (per the instructions in the README file). First of all, check the file conf/storage-conf.xml and make sure that these folders exist before you do anything else.


  <CommitLogDirectory>/var/lib/cassandra/commitlog</CommitLogDirectory>
  <DataFileDirectories>
      <DataFileDirectory>/var/lib/cassandra/data</DataFileDirectory>
  </DataFileDirectories>
  <CalloutLocation>/var/lib/cassandra/callouts</CalloutLocation>
  <StagingFileDirectory>/var/lib/cassandra/staging</StagingFileDirectory>

If they do not exist, you will have to make them (careful with the whoami command in backticks):

Trinity:cassandra-0.5.0 kelvin$ sudo mkdir -p /var/log/cassandra
Password:
Trinity:cassandra-0.5.0 kelvin$ sudo chown -R `whoami` /var/log/cassandra
Trinity:cassandra-0.5.0 kelvin$ sudo mkdir -p /var/lib/cassandra
Trinity:cassandra-0.5.0 kelvin$ sudo chown -R `whoami` /var/lib/cassandra

For logging, Cassandra expects that a system.log file is available. Check the conf/log4j.properties file to check where it expects a log file. It should be similar to this:

log4j.appender.R.File=/var/log/cassandra/system.log

When you start Cassandra for the first time it will start the log file.

I used ‘ant‘ to build Cassandra. Make sure that you are in the root of the Cassandra directory. I have a lot of crap in my Java classpath, so I will temporarily exclude it.

Trinity:cassandra-0.5.0 kelvin$ ant -noclasspath
Buildfile: build.xml

build-subprojects:

init:
    [mkdir] Created dir: /Users/kelvin/code/cassandra-0.5.0/build/classes
    [mkdir] Created dir: /Users/kelvin/code/cassandra-0.5.0/build/test/classes
    [mkdir] Created dir: /Users/kelvin/code/cassandra-0.5.0/src/gen-java

check-gen-cli-grammar:

gen-cli-grammar:
     [echo] Building Grammar /Users/kelvin/code/cassandra-0.5.0/src/java/org/apache/cassandra/cli/Cli.g  ....

build-project:
     [echo] apache-cassandra-incubating: /Users/kelvin/code/cassandra-0.5.0/build.xml
    [javac] Compiling 247 source files to /Users/kelvin/code/cassandra-0.5.0/build/classes
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.

build:

BUILD SUCCESSFUL
Total time: 13 seconds
Trinity:cassandra-0.5.0 kelvin$

Now the moment of truth!

Trinity:cassandra-0.5.0 kelvin$ bin/cassandra -f
Listening for transport dt_socket at address: 8888
INFO - Saved Token not found. Using 25907362644306974147256376871662350143
INFO - Starting up server gossip
INFO - Cassandra starting up...

Okay, Cassandra is now waiting for us to do something, so we can open up another Terminal window (Cmd+N) and try the test described in the README file:

Trinity:cassandra-0.5.0 kelvin$ bin/cassandra-cli --host localhost --port 9160
Connected to localhost/9160
Welcome to cassandra CLI.

Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
cassandra> set Keyspace1.Standard1['jsmith']['first'] = 'John'
Value inserted.
cassandra> set Keyspace1.Standard1['jsmith']['last'] = 'Smith'
Value inserted.
cassandra> set Keyspace1.Standard1['jsmith']['age'] = '42'
Value inserted.
cassandra> get Keyspace1.Standard1['jsmith']
=> (column=last, value=Smith, timestamp=1264159272089)
=> (column=first, value=John, timestamp=1264159260000)
=> (column=age, value=42, timestamp=1264159282593)
Returned 3 results.
cassandra>

Okay, we now have stored and retrieved some data. In the next installment I’ll try to get Thrift running!

Tags: , , , , , ,

Install PHP 5.2.12 on Mac OS 10.5.8 Leopard

PHP 5.2.12 has a bug that will stop your installation:

/bin/sh /Users/kelvin/phpsource/php-5.2.12/libtool --silent --preserve-dup-deps --mode=compile gcc  ...includes redacted...  -no-cpp-precomp  -I/usr/local/php5/include -g -O2  -c /Users/kelvin/phpsource/php-5.2.12/ext/standard/dns.c -o ext/standard/dns.lo 
In file included from /usr/include/arpa/nameser.h:59,
                 from /Users/kelvin/phpsource/php-5.2.12/ext/standard/dns.c:62:
/usr/include/arpa/nameser8_compat.h:304: error: conflicting types for ‘HEADER’
/usr/include/arpa/nameser_compat.h:99: error: previous declaration of ‘HEADER’ was here
make: *** [ext/standard/dns.lo] Error 1
Trinity:~ kelvin$ 

Two header files (nameser8_compat.h & nameser_compat.h) both try to define a struct named HEADER. No can do. According to the PHP bug tracker, “NEVER ever include nameser_compat.h, it’s included in various ways in different OSes by nameser.h if needed

Doh!

So how do we go about fixing this? The easiest thing to do is to install the older PHP 5.2.11 or the HEAD from the 5.2 branch. If you are adventurous or obsessive-compulsive you can also replace these two files with the patched copies:

  1. ~/php-5.2.12/configure.innotes
  2. ~/php-5.2.12/ext/standard/dns.cnotes

Tags: , , ,

Installing Google Go on Mac OS X Leopard

Google released a new programming language named GO that offers the benefits of a dynamic language like Python with the speed of a compiled language like C/C++. In this walkthrough, I’m going to be installing the Google Go programming language on my Mac.

To get started, make sure that you have Python and Mercurial installed on your Intel Mac (PowerPC is not supported at this point). Also make sure that you have XCode installed and that you are attached to the Internet (the test suite will need Internet access to run a few tests).

Trinity:~ kelvin$ python -V
Python 2.5.2
Trinity:~ kelvin$ hg version
Mercurial Distributed SCM (version 1.0.1)

Copyright (C) 2005-2008 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Trinity:~ kelvin$ xcodebuild -version
Xcode 3.1.2
Component versions: DevToolsCore-1148.0; DevToolsSupport-1102.0
BuildVersion: 9M2621
Trinity:~ kelvin$ uname -p
i386
Trinity:~ kelvin$

Okay, now we’re going to make some environment variables that Go will use to compile your code. In my home directory, I put the following variables into the ‘.bash_profile’ file:

# Google Go Lang Vars
export GOROOT=$HOME/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
export PATH=$GOBIN:$PATH

Now we make sure that the environment has the variables we just set up:

Trinity:~ kelvin$ source .bash_profile
Trinity:~ kelvin$ env | grep ^GO
GOBIN=/Users/kelvin/bin
GOARCH=386
GOROOT=/Users/kelvin/go
GOOS=darwin
Trinity:~ kelvin$

Make sure that your ‘~/go’ directory doesn’t exist since the next command will make it into a Mercurial repository. We will be creating the ‘~/bin’ directory after we create the repository.

Trinity:~ kelvin$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT
requesting all changes
adding changesets
adding manifests
adding file changes
added 3976 changesets with 16799 changes to 2931 files
updating working directory
1640 files updated, 0 files merged, 0 files removed, 0 files unresolved
Trinity:~ kelvin$ cd $GOROOT
Trinity:go kelvin$ ls
AUTHORS LICENSE doc include misc src
CONTRIBUTORS README favicon.ico lib pkg test
Trinity:go kelvin$ cd src/
Trinity:src kelvin$

Okay, so far we have set-up the environment and the respository. Now would be a good time to ensure the ‘~/bin’ folder actually exists. In many cases, it is already there. If it isn’t there, you need to create it and mark it executable (Hint: Try ‘mkdir ~/bin’ then ‘chmod 755 ~/bin’).

Trinity:src kelvin$ test -e ~/bin && echo 'bin exists'
bin exists
Trinity:src kelvin$

Okay, now we’re ready to build Go.

Trinity:src kelvin$ ./all.bash
rm -f *.o *.6 6.out lib9.a
rm -f bbuffered.o bfildes.o bflush.o bgetc.o bgetrune.o bgetd.o binit.o boffset.o bprint.o bputc.o bputrune.o brdline.o brdstr.o bread.o bseek.o bwrite.o *.6 6.out libbio.a
rm -f *.o *.so
.... holy crap there is a lot of output here...
./mkasmh.sh >386/asm.h.x
mv -f 386/asm.h.x 386/asm.h
8a 386/asm.s
8c -Idarwin -Idarwin/386 -wF cgocall.c
8c -Idarwin -Idarwin/386 -wF chan.c
8c -Idarwin -Idarwin/386 -wF 386/closure.c
8c -Idarwin -Idarwin/386 -wF float.c
8c -Idarwin -Idarwin/386 -wF hashmap.c
8c -Idarwin -Idarwin/386 -wF iface.c
quietgcc -o cgo2c cgo2c.c
./cgo2c malloc.cgo > malloc.c.tmp
mv -f malloc.c.tmp malloc.c
...Two peanuts were walking down the street. One was a salted...
8g -I_obj main.go
8l -L_obj -o ogle main.8

real 0m0.996s
user 0m0.831s
sys 0m0.148s

--- cd ../doc/progs

real 0m2.229s
user 0m1.714s
sys 0m0.431s

--- cd ../test/bench
fasta
reverse-complement
nbody
binary-tree
binary-tree-freelist
fannkuch
regex-dna
spectral-norm
k-nucleotide
mandelbrot
meteor-contest
pidigits
threadring
chameneosredux

--- cd ../test
0 known bugs; 0 unexpected bugs
Trinity:src kelvin$

Okay, so hopefully you now have a working copy of the Go programming language. You can try to find the executables on your system. Your compiler is ‘8g’ if for the i386 architecture.

Trinity:~ kelvin$ which 8g
/Users/kelvin/bin/8g
Trinity:~ kelvin$ which 8l
/Users/kelvin/bin/8l
Trinity:~ kelvin$ 8g
flags:
-I DIR search for packages in DIR
-d print declarations
-e no limit on number of errors printed
-f print stack frame structure
-h panic on an error
-k name specify package name
-o file specify output file
-S print the assembly language
-w print the parse tree after typing
-x print lex tokens
Trinity:~ kelvin$

Notice that ‘gccgo’ is not installed by default; if you want to try that out you need to install it separately. Try working through the examples!

Tags: , , , , ,

Installing Tokyo Cabinet and Tokyo Tyrant on MacOS X Leopard

If you’re interested in screaming fast, persistent key-value stores, you should consider Tokyo Cabinet. If you want to talk to your Tokyo Cabinet machine over a network, you will need Tokyo Tyrant. In this installation article I’m going to walk through the installation of Tokyo Cabinet version 1.4.23 and Tokyo Tyrant version 1.1.27 on MacOS X.

Tokyo Cabinet & Tokyo Tyrant in a Single Line

The easiest way to install both Tokyo Cabinet and Tokyo Tyrant is to use MacPorts.

Trinity:~ kelvin$ sudo port install tokyocabinet tokyotyrant
Password:
--->  Fetching tokyocabinet
--->  Attempting to fetch tokyocabinet-1.4.23.tar.gz from http://superb-west.dl.sourceforge.net/tokyocabinet
--->  Verifying checksum(s) for tokyocabinet
--->  Extracting tokyocabinet
--->  Configuring tokyocabinet
--->  Building tokyocabinet
--->  Staging tokyocabinet into destroot
--->  Installing tokyocabinet @1.4.23_0
--->  Activating tokyocabinet @1.4.23_0
--->  Cleaning tokyocabinet
--->  Fetching tokyotyrant
--->  Attempting to fetch tokyotyrant-1.1.27.tar.gz from http://superb-west.dl.sourceforge.net/tokyocabinet
--->  Verifying checksum(s) for tokyotyrant
--->  Extracting tokyotyrant
--->  Configuring tokyotyrant
--->  Building tokyotyrant
--->  Staging tokyotyrant into destroot
--->  Installing tokyotyrant @1.1.27_0
--->  Activating tokyotyrant @1.1.27_0
--->  Cleaning tokyotyrant
Trinity:~ kelvin$

So that was pretty easy. Now run the tests to check our installation.

Testing

Let’s see if the Tokyo Tyrant can be started. Once started, it can be stopped using Ctrl-C.

Trinity:~ kelvin$ ttserver
2009-06-01T18:32:43-08:00	SYSTEM	--------- logging started [13738] --------
2009-06-01T18:32:43-08:00	SYSTEM	server configuration: host=(any) port=1978
2009-06-01T18:32:43-08:00	SYSTEM	opening the database: *
2009-06-01T18:32:43-08:00	SYSTEM	service started: 13738
2009-06-01T18:32:43-08:00	INFO	timer thread 1 started
2009-06-01T18:32:43-08:00	INFO	worker thread 1 started
2009-06-01T18:32:43-08:00	INFO	worker thread 2 started
2009-06-01T18:32:43-08:00	INFO	worker thread 3 started
2009-06-01T18:32:43-08:00	INFO	worker thread 4 started
2009-06-01T18:32:43-08:00	INFO	worker thread 5 started
2009-06-01T18:32:43-08:00	INFO	worker thread 6 started
2009-06-01T18:32:43-08:00	INFO	worker thread 7 started
2009-06-01T18:32:43-08:00	INFO	worker thread 8 started
2009-06-01T18:32:43-08:00	SYSTEM	listening started
^C
2009-06-01T18:33:14-08:00	INFO	signal interruption
2009-06-01T18:33:14-08:00	SYSTEM	listening finished
2009-06-01T18:33:14-08:00	SYSTEM	closing the database
2009-06-01T18:33:14-08:00	INFO	worker thread 1 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 1 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 2 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 2 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 3 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 3 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 4 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 4 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 5 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 5 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 6 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 6 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 7 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 7 finished
2009-06-01T18:33:14-08:00	INFO	worker thread 8 was canceled
2009-06-01T18:33:14-08:00	INFO	worker thread 8 finished
2009-06-01T18:33:14-08:00	INFO	timer thread 1 was canceled
2009-06-01T18:33:14-08:00	INFO	timer thread 1 finished
2009-06-01T18:33:14-08:00	SYSTEM	service finished
2009-06-01T18:33:14-08:00	SYSTEM	--------- logging finished [13738] --------
Trinity:~ kelvin$

If you can start and stop your Tyrant then you are halfway there. Let’s try one more test using the testing program supplied. Our first command starts the server in the background (so we can do more work in a single terminal window) and returns a process id (13779 in the example). We will use the process id to stop the server later so make note of it. We will then use the tcrtest program to test it.

Trinity:~ kelvin$ ttserver 1>/dev/null &
[1] 13779
Trinity:~ kelvin$ tcrtest misc localhost 1000
<Miscellaneous Test>
  host=localhost  port=1978  cnum=1  tout=0  rnum=1000

writing:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
reading:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
random writing:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
word writing:
.................... (00000041)
random erasing:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
writing:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
erasing:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
random multi reading:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
script extension calling:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
checking versatile functions:
......................... (00000100)
......................... (00000200)
......................... (00000300)
......................... (00000400)
......................... (00000500)
......................... (00000600)
......................... (00000700)
......................... (00000800)
......................... (00000900)
......................... (00001000)
record number: 0
size: 262688
time: 1.700
ok

Trinity:~ kelvin$ kill 13779
Trinity:~ kelvin$

Tags: , , ,

Running Shindig on your Mac

If you run a social network, you really owe it to your users to investigate OpenSocial as a way of allowing your users to add third-party functionality to their profiles. Shindig (available in a PHP and a Java version) allows you to easily add this capability.

Mac OS X Leopard has Java 1.6 and Maven 2.0.6 installed. I had some build issues with the older Maven so I upgraded to 2.0.9. You also need to ensure that your JAVA_HOME variable is set. You can confirm this by typing the following commands in a terminal:

Trinity:shindig kelvin$ echo $JAVA_HOME
/Library/Java/Home
Trinity:shindig kelvin$ mvn -v
Maven version: 2.0.9
Java version: 1.6.0_07
OS name: "mac os x" version: "10.5.5" arch: "x86_64" Family: "mac"

Then download the code from the main repository:

Trinity:code kelvin$ mkdir shindig
Trinity:code kelvin$ svn co http://svn.apache.org/repos/asf/incubator/shindig/trunk/ ./shindig
A    shindig/NOTICE
A    shindig/java
A    shindig/java/social-api
A    shindig/java/social-api/src
A    shindig/java/social-api/src/test

...la dee da...

A    shindig/features/mocks/env.js
A    shindig/features/mocks/xhr.js
 U   shindig
Checked out revision 707938.

Okay, Shindig has now been downloaded. Let’s build it. You can try building it using ‘mvn clean install’ first and if you get any errors, try turning off the tests. Sometimes the tests can get out of sync with the code. I was able to build it without any problems.

Trinity:shindig kelvin$ mvn clean install
[INFO] Scanning for projects...
[INFO] Reactor build order: 
[INFO]   Apache Shindig Project
[INFO]   Apache Shindig Project Parent
[INFO]   Apache Shindig Common Code
[INFO]   Apache Shindig Gadget Renderer
[INFO]   Apache Shindig Social API
[INFO]   Apache Shindig Features
[INFO]   Apache Shindig Web App
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Shindig Project
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/kelvin/code/shindig/target
[INFO] [site:attach-descriptor]

...etc etc etc...

[INFO] [install:install]
[INFO] Installing /Users/kelvin/code/shindig/java/server/target/shindig-server-1-SNAPSHOT.war to /Users/kelvin/.m2/repository/org/apache/shindig/shindig-server/1-SNAPSHOT/shindig-server-1-SNAPSHOT.war
[INFO] Installing /Users/kelvin/code/shindig/java/server/target/shindig-server-1-SNAPSHOT-sources.jar to /Users/kelvin/.m2/repository/org/apache/shindig/shindig-server/1-SNAPSHOT/shindig-server-1-SNAPSHOT-sources.jar
[INFO] 
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Apache Shindig Project ................................ SUCCESS [6.196s]
[INFO] Apache Shindig Project Parent ......................... SUCCESS [0.531s]
[INFO] Apache Shindig Common Code ............................ SUCCESS [9.470s]
[INFO] Apache Shindig Gadget Renderer ........................ SUCCESS [25.571s]
[INFO] Apache Shindig Social API ............................. SUCCESS [11.381s]
[INFO] Apache Shindig Features ............................... SUCCESS [7.117s]
[INFO] Apache Shindig Web App ................................ SUCCESS [13.737s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 14 seconds
[INFO] Finished at: Sun Nov 09 10:43:56 PST 2008
[INFO] Final Memory: 51M/80M
[INFO] ------------------------------------------------------------------------

or if you want to skip the tests, try this…

Trinity:shindig kelvin$ mvn clean install -Dmaven.test.skip=true

Woot. Now let’s start it up. By default, the server will run on localhost port 8080.

Trinity:shindig kelvin$ mvn -Prun
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.1/maven-antrun-plugin-1.1.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin-parent/2.0.1/maven-plugin-parent-2.0.1.pom
7K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.1/maven-antrun-plugin-1.1.jar
11K downloaded
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Shindig Project
[INFO]    task-segment: [jetty:run-war]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run-war


...more more more...

[INFO] Starting jetty 6.1.9 ...
2008-11-09 10:47:45.790::INFO:  jetty-6.1.9
2008-11-09 10:47:45.812::INFO:  Extract jar:file:/Users/kelvin/code/shindig/java/server/target/shindig-server-1-SNAPSHOT.war!/ to /Users/kelvin/code/shindig/target/work/webapp
2008-11-09 10:47:47.372::INFO:  No Transaction manager found - if your webapp requires one, please configure one.
Nov 9, 2008 10:47:48 AM org.apache.shindig.common.JsonContainerConfig loadContainers
INFO: Loading resources from: containers/default/container.js
Nov 9, 2008 10:47:48 AM org.apache.shindig.common.JsonContainerConfig loadResources
INFO: Reading container config: containers/default/container.js
2008-11-09 10:47:48.313::INFO:  Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server

See if you can render anything by opening a web browser and putting the following into the address bar.

http://localhost:8080/gadgets/ifr?url=http://www.labpixies.com/campaigns/todo/todo.xml

If all went well, you should see the To Do list demo.

The To Do Shindig App

The To Do Shindig App

Tags: , ,

Does my Mac really love me?

I have a cute little white MacBook that I use to write my code (and to listen to Pandora Radio). It is even more adorable now that it has 4GB of RAM and a 200GB hard-drive spinning at 7200RPM. Anyway, this post isn’t about my adorable computer.

I’m doing some simple image manipulation in Python 2.5. It is really basic stuff which can be done easily in PHP by using the GD2 image manipulation library. In Python, I have found two options: Py-GD (GD2 wrapped in Python) and the Python Imaging Library (PIL). The Python Imaging Library looks richer. I really haven’t tried much at this point other than resize some avatars.

In order to install the aforementioned libraries, you need to install a bunch of common image manipulation libraries like GD, JPEG, etc. Mac is missing these libraries, so you have to install them yourself. I’m lazy, so I basically have a choice of installing these using MacPorts or Fink. I’ve sworn off Fink (use it for a while and let me know if you agree) so that leaves MacPorts.

So I installed all the dependencies to get PIL installed. This is what I see:

sh-3.2# python setup.py build_ext -i
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imagingtk' extension
creating build
creating build/temp.macosx-10.3-i386-2.5
creating build/temp.macosx-10.3-i386-2.5/Tk
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/opt/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Library/Frameworks/Python.framework/Versions/2.5/include -I/opt/local/include/freetype2/freetype -I/opt/local -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _imagingtk.c -o build/temp.macosx-10.3-i386-2.5/_imagingtk.o -framework Tcl -framework Tk
In file included from /usr/include/math.h:26,
                 from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h:231,
                 from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:57,
                 from _imagingtk.c:17:
/usr/include/architecture/ppc/math.h:675: warning: conflicting types for built-in function ‘scalb’
powerpc-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: Tcl: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: Tk: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tcl: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tk: linker input file unused because linking not done
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/opt/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Library/Frameworks/Python.framework/Versions/2.5/include -I/opt/local/include/freetype2/freetype -I/opt/local -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c Tk/tkImaging.c -o build/temp.macosx-10.3-i386-2.5/Tk/tkImaging.o -framework Tcl -framework Tk
In file included from /usr/include/math.h:26,
                 from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h:231,
                 from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:57,
                 from libImaging/ImPlatform.h:10,
                 from libImaging/Imaging.h:14,
                 from Tk/tkImaging.c:53:
/usr/include/architecture/ppc/math.h:675: warning: conflicting types for built-in function ‘scalb’
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tcl: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tk: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: Tcl: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
powerpc-apple-darwin9-gcc-4.0.1: Tk: linker input file unused because linking not done
gcc -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -bundle -undefined dynamic_lookup build/temp.macosx-10.3-i386-2.5/_imagingtk.o build/temp.macosx-10.3-i386-2.5/Tk/tkImaging.o -L/opt/local/lib -L/Library/Frameworks/Python.framework/Versions/2.5/lib -L/opt/local -L/usr/lib -o PIL/_imagingtk.so -framework Tcl -framework Tk
ld: in /opt/local/lib/libJPEG.dylib, file is not of required architecture for architecture ppc
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccptvQXL.out (No such file or directory)
error: command 'gcc' failed with exit status 1
sh-3.2# 

She would only say such things to me if she really loved me. So the problem is that my Big Fat Cupertino Python was compiled as a universal binary with all this useless gunk for Power PC (what the hell is that, like a Beta VCR or something??). Of course my MacPort binaries are svelt little things compiled for my Intel chip, so naturally we got architecture problems. My modern clashes with your baroque.

My solution was stop her from trying to compile using the PPC flag. Where the hell is that set? The Makefile!

sh-3.2# cd /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config/
sh-3.2# vi ./Makefile
sh-3.2# 

I changed these lines by removing the “arch ppc” flags from the BASECFLAGS and LDFLAGS (here is a patch):

sh-3.2# diff -urN ./Makefile.old ./Makefile
--- ./Makefile.old	2008-05-22 23:10:51.000000000 -0700
+++ ./Makefile	2008-05-22 23:11:51.000000000 -0700
@@ -57,13 +57,13 @@
 
 # Compiler options
 OPT=		-DNDEBUG -g -O3 
-BASECFLAGS=	-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic
+BASECFLAGS=	-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic
 CFLAGS=		$(BASECFLAGS) $(OPT) $(EXTRA_CFLAGS)
 # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
 # be able to build extension modules using the directories specified in the
 # environment variables
 CPPFLAGS=	-I. -IInclude -I$(srcdir)/Include 
-LDFLAGS=	-arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g 
+LDFLAGS=	-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g 
 LDLAST=		
 SGI_ABI=	
 CCSHARED=
sh-3.2# 

So I asked her again, if she still loved me:

sh-3.2# python setup.py clean
running clean
removing 'build/temp.macosx-10.3-i386-2.5' (and everything under it)
removing 'build'
sh-3.2# python setup.py build_ext -i
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imagingtk' extension
creating build
creating build/temp.macosx-10.3-i386-2.5
creating build/temp.macosx-10.3-i386-2.5/Tk
gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/opt/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Library/Frameworks/Python.framework/Versions/2.5/include -I/opt/local/include/freetype2/freetype -I/opt/local -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _imagingtk.c -o build/temp.macosx-10.3-i386-2.5/_imagingtk.o -framework Tcl -framework Tk
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tcl: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tk: linker input file unused because linking not done
gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/opt/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Library/Frameworks/Python.framework/Versions/2.5/include -I/opt/local/include/freetype2/freetype -I/opt/local -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c Tk/tkImaging.c -o build/temp.macosx-10.3-i386-2.5/Tk/tkImaging.o -framework Tcl -framework Tk
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tcl: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: -framework: linker input file unused because linking not done
i686-apple-darwin9-gcc-4.0.1: Tk: linker input file unused because linking not done
gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -bundle -undefined dynamic_lookup build/temp.macosx-10.3-i386-2.5/_imagingtk.o build/temp.macosx-10.3-i386-2.5/Tk/tkImaging.o -L/opt/local/lib -L/Library/Frameworks/Python.framework/Versions/2.5/lib -L/opt/local -L/usr/lib -o PIL/_imagingtk.so -framework Tcl -framework Tk
building '_imagingmath' extension
gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/opt/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Library/Frameworks/Python.framework/Versions/2.5/include -I/opt/local/include/freetype2/freetype -I/opt/local -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _imagingmath.c -o build/temp.macosx-10.3-i386-2.5/_imagingmath.o
gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -bundle -undefined dynamic_lookup build/temp.macosx-10.3-i386-2.5/_imagingmath.o -L/opt/local/lib -L/Library/Frameworks/Python.framework/Versions/2.5/lib -L/opt/local -L/usr/lib -o PIL/_imagingmath.so
--------------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version       1.1.6
platform      darwin 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
              [GCC 4.0.1 (Apple Computer, Inc. build 5363)]
--------------------------------------------------------------------
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--------------------------------------------------------------------
To check the build, run the selftest.py script.
sh-3.2# python selftest.py 
57 tests passed.
sh-3.2#


She loves me!

These instructions work with PIL 1.1.7 and the older PIL 1.1.6.

To complete the installation, install the objects using:

$ sudo python setup.py install

Tags: ,