Archive

Posts Tagged ‘apple’

MySQL v5.5 and Python

December 17th, 2010 3 comments

MySQL v5.5 is GA, but is it working with Python? Yes, it does. Below you’ll find some quick, small tests I did with MySQLdb, oursql and our own MySQL Connector/Python.

My desktop is a Mac, but when it works on that, I’m sure it works elsewhere too. If not, just let us know!

MySQL for Python (aka MySQLdb)

Installing MySQL v5.5.8 64-bit from tar ball on MacOS X 10.6, it compiled fine and the module loaded giving me the expected result:

>>> import MySQLdb
>>> cnx = MySQLdb.connect(user='root')
>>> cur = cnx.cursor()
>>> cur.execute("SELECT VERSION()")
1L
>>> print cur.fetchall()
(('5.5.8',),)

oursql

oursql is an alternative for MySQLdb. Both are using the MySQL C API and thus need to be compiled from source (if you don’t find binaries of course).

>>> import oursql
>>> cnx = oursql.connect(user='root')
>>> cur = cnx.cursor()
>>> cur.execute("SELECT VERSION()")
>>> print cur.fetchall()
[(u'5.5.8',)]

MySQL Connector/Python

Our own MySQL Connector/Python doesn’t need compiling and doesn’t need any MySQL software installed to be able to connect to a MySQL server. Current unittests run fine against MySQL v5.5.8.

>>> cnx = mysql.connector.connect(user='root')
>>> cur = cnx.cursor()
>>> cur.execute("SELECT VERSION()")
-1
>>> print cur.fetchall()
[(u'5.5.8',)]

Conclusion

One can’t really conclude anything with the simple tests above, but it looks like MySQL v5.5 will work fine with Python.

Tags: , ,

AppleScript exporting photos from Aperture

August 26th, 2010 No comments

The following AppleScript will:

  1. Prompt for a destination folder

  2. Ask for an album name, which will be a folder in destination folder
  3. Get currently selected photo(s) from Aperture
  4. Store the image files using the Image ID of Aperture
  5. Store some META information in a text file, with similar name as image file

The export format is PNG 1024x1024. I needed only that, so I hardcoded it.

Note dependencies: You need the renameFile, joinList and splitString functions found in earlier blog entries.

property defExportSetting : "PNG - Fit within 1024 x 1024"

on apertureExport(fldAlbum)
 tell application "Aperture"
  set imageSel to (get selection)
 end tell
 
 set out to {}
 repeat with img in imageSel
  tell application "Aperture"
   set kwList to (get id of every keyword of img)
   set imgDate to value of EXIF tag "ImageDate" of img
  end tell
  set imgId to id of img
  
  set imgName to name of img
  set imgTags to my joinList(kwList, ",")
  
  copy "Name: " & imgName to end of out
  copy "Tags: " & imgTags to end of out
  copy "ApertureId: " & imgId to end of out
  
  set dstFileMeta to (fldAlbum & imgId & ".meta") as string
 end repeat
 
 tell application "Aperture"
  set dstFile to (export imageSel using export setting defExportSetting to fldAlbum)
 end tell
 set dstFile to my renameFile(dstFile, imgId)
 copy "File: " & (POSIX path of dstFile) to end of out
 tell application "Finder"
 end tell
 
 set fp to open for access file dstFileMeta with write permission
 write (joinList of out given delimiter:return) to fp
 close access fp
 
end apertureExport

on run
 set dstFolder to (choose folder with prompt "Choose an destination") as text
 set dlgAlbum to display dialog "Album name" buttons {"OK", "Cancel"} default answer "Picture pool"
 
 set dstAlbum to (text returned of dlgAlbum) as text
 
 tell application "Finder"
  if not (exists alias (dstFolder & dstAlbum)) then
   make new folder at alias (dstFolder) with properties {name:dstAlbum}
  end if
 end tell
 set fldAlbum to (dstFolder & dstAlbum) as alias
 
 apertureExport(fldAlbum)
end run

This script is safe, but I don’t take any responsibility when it screws up you Aperture library. It shouldn’t really, I coded it on my main library: hardcore!

Splitting as string and joining a list using AppleScript

August 26th, 2010 3 comments

Two small helper AppleScript functions for joining a list and splitting a string given delimiter. Sure, quite an easy task, but it involves setting a global delimiter. Bit like FS in shell. I hope this helps a few folks out there starting out with AppleScript.

to joinList(aList, delimiter)
 set retVal to ""
 set prevDelimiter to AppleScript's text item delimiters
 set AppleScript's text item delimiters to delimiter
 set retVal to aList as string
 set AppleScript's text item delimiters to prevDelimiter
 return retVal
end joinList

to splitString(aString, delimiter)
 set retVal to {}
 set prevDelimiter to AppleScript's text item delimiters
 log delimiter
 set AppleScript's text item delimiters to {delimiter}
 set retVal to every text item of aString
 set AppleScript's text item delimiters to prevDelimiter
 return retVal
end splitString

Here a few lines showing how to use them:

set tmp to my splitString(oldAlias as text, ":")
set imgTags to my joinList(kwList, ",")

Again, no comments! Enjoy!

Renaming a file using AppleScript

August 26th, 2010 No comments

The following AppleScript function renames a file. If you thought this to be a simple thing, try to write it without looking here below. I spend a lot time on this, I might not even use it, but here it is for other mortals wishing to lose weight exercising AppleScript:

to renameFile(oldAlias, newFileName)
 tell application "Finder"
  set f to item (oldAlias as text)
  tell f
   set ext to its name extension
   set nFn to (newFileName & "." & ext)
   set its name to nFn
  end tell
 end tell
 set tmp to my splitString(oldAlias as text, ":")
 set the last item of tmp to nFn
 return my joinList(tmp, ":")
end renameFile

No comments in code, I do not want to spoil your fun!

I needed while writing an export script for Aperture. Here is how I used it after a photo was exported from Aperture:

tell application "Aperture"
 set dstFile to (export imageSel using export setting defExportSetting to fldAlbum)
end tell
set dstFile to my renameFile(dstFile, imgId)

Aperture: add tags to multiple shot but beware of Primary Only

May 16th, 2010 4 comments

To apply a keyword to all your selected images using Apple Aperture 3, make sure to turn off the Primary Only mode using either the Edit-Menu, or the button in the right bottom corner that says [1]. It should be unselected like in the screenshot here below.

You can then use whatever method to add keywords, e.g. using the Control Bar (press D) and its Keywords Controls (press shift D).

This has been bugging me for a week. Maybe I pushed the Primary Only button by mistake. Yes, you can do it using a batch change. But luckily, you don’t have to do the simplest thing the hardest way. Just, careful where you push!

MobileMe is still useless

May 2nd, 2010 No comments

Today I tried MobileMe again registring for the 60-day trial. I cancelled it 15 minutes later. Expensive and useless. If you ask 99 EUR per year for a service, you would imagine a personal domain for your e-mail. But no, Apple thinks it’s doing it correctly, but it’s laughable. I’m sure they don’t lack the tallent to do it, just the balls at management level.

Lets hope Apple puts it in soon, I might consider paying for it. It must be great to sync data over MobileMe because most other tools are just almost-working. Now it’s back to Google where all features are there (for ‘free’), but online..

I’m really pissed off, again, every year. Syncing contacts and calendars offline is a pain if you got a few Macs, iPhone and iPad. Nothing is working as it should, MobileMe would be great.

I’m getting tired of this: Apple has a brilliant OS, great hardware and some great software. But Apple just painfully blows it at service level.

MySQL 5.1.42 available for MacOS X 10.6 (Snow Leopard)

January 4th, 2010 No comments

A few days ago MySQL 5.1.42 got released and it is now available with builds for MacOS X 10.6 (Snow Leopard)! The download website doesn’t show it yet, but if you are burning to try, you can get it from the mirror-picking-website.

As usual, don’t forget to checkout the changelog before upgrading!

If you want to compile it yourself, and need a universal binary, you could try my previous blog entry «Building MySQL universal binaries using MacOS X 10.6 (Snow Leopard)».

Tags: , ,

Building MySQL universal binaries using MacOS X 10.6 (Snow Leopard)

December 31st, 2009 2 comments

On the eve of 2010.. and your boss wants to stick to these MacOS X 10.5 machines, too stubborn or chicken to upgrade. Some developers still have their old PowerBook laptops and they need MySQL flying on PowerPC machines. To top it all, one guy said he wanted to have 32 and 64-bit in one bite. *Sigh* .. But there is an easy way out! A universal binary!

This post shows you a way to create MySQL universal binaries using MacOS X 10.6 so you can run them on MacOS X 10.5/10.6 whether it is PowerPC or Intel, or 32bit or 64bit.

However, if you need libmysqld (Embedded MySQL), this post will not work for you.

Requirements:

  • You have MacOS X 10.6 with latest Xcode (fully) installed.
  • The MySQL source unpacked somewhere. Get it on the MySQL download website under Source Downloads, package named Compressed GNU TAR archive (tar.gz).
  • And some nerves for when the build process fails.

Most complete Universal Binary

First, here is away to build MySQL so it runs on MacOS X 10.5 Intel/PowerPC and 10.6 32 or 64-bit.

Here is the source of the build script names build.sh. Executed it while located inside the source directory of MySQL.

#!/bin/bash

SDK="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
SDKLIB="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
export MACOSX_DEPLOYMENT_TARGET="10.5"
PREFIX=/opt/mysql/mysql-5.1.42-universal-macosx-10.5

ARCH="-arch i386 -arch x86_64 -arch ppc"

export CFLAGS="-O2 -fPIC $ARCH $SDK"
export CXXFLAGS="-O2 -fPIC $ARCH $SDK"
export LDFLAGS="$ARCH $SDKLIB"

CC="/usr/bin/gcc-4.2"
CXX="/usr/bin/g++-4.2"
OBJC="/usr/bin/gcc-4.2"

INSTALL="/usr/bin/install -c"

./configure --prefix=$PREFIX \
--disable-dependency-tracking \
--mandir=$PREFIX/share/man --infodir=$PREFIX/share/info \
--localstatedir=$PREFIX/var/ --libdir=$PREFIX/lib \
--bindir=$PREFIX/bin --libexecdir=$PREFIX/bin \
--includedir=$PREFIX/include \
--datadir=$PREFIX/share/ --sysconfdir=$PREFIX/etc \
--with-extra-charsets=complex \
--with-mysqld-user=mysql \
--without-docs \
--with-plugins=all \
--enable-thread-safe-client --without-embedded-server \
--with-pic --with-libedit

if [ $? -eq 0 ]; then
    make clean
    time make -j 2
fi

Here is what file shows for the mysqld binary:

Black:mysql-5.1.42 geert$ file sql/mysqld
sql/mysqld: Mach-O universal binary with 3 architectures
sql/mysqld (for architecture i386): Mach-O executable i386
sql/mysqld (for architecture x86_64): Mach-O 64-bit executable x86_64
sql/mysqld (for architecture ppc7400): Mach-O executable ppc

These binaries were tested and work on MacOS X 10.6 Intel and MacOS X 10.5 PowerPC.

32/64-bit Universal binaries for MacOS X 10.6

Same as above, but with the following changes:

SDK="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
SDKLIB="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk"
export MACOSX_DEPLOYMENT_TARGET="10.6"
PREFIX=/opt/mysql/mysql-5.1.42-universal-macosx-10.6

Setting the above is probably not needed when you are already on a Mac running 10.6, but it doesn’t hurt to be explicit.

Need it for MacOS X 10.4?

I gave this a spin:

SDK="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
SDKLIB="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
export MACOSX_DEPLOYMENT_TARGET="10.4"
ARCH="-arch i386 -arch ppc"

But it failed with

/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25:
  error: stdarg.h: No such file or directory

.. but I lack intrest making stuff for MacOS X 10.4 (Tiger). Consider this your homework!

Tags: , , ,

If your AirPort magically doesn’t work anymore: check IPv6!

December 8th, 2009 2 comments

Today I finally found out why my iMac can’t communicate with the AirPort Express. For whatever reason, I disabled it, but IPv6 has to be On for the network interface you use to configure the AirPort! Either Automatically or Manually.

My old iMac G5 and MacBook Air were both still using IPv6, so no problem there. This bugged me for a long time and worked around it using the other machines.

There, PJ Harvey sounding great through the loudspeakers streamed from my shiny iMac. Woohoo!

Tags:

Mounting a MacOS X Disk Image at login

November 19th, 2009 No comments

Work says that we need to store sensitive data like email and customer files on some encrypted media. This is a good thing. My laptop has my home directory secured, but I don’t want to encrypt everything on my desktop. The solution to this is to create an encrypted Disk Image (using Disk Utility) and make Mail.app store my email there. This all works great!

The problem surfaced this week when I decided it would be good to shutdown my desktop to save energy (which I usually did, but I got sloppy). What happened? When Mac OS X shuts down, and there is still some application doing something with your opened Disk Image, it will not remove the mount-point, e.g. in my case /Volumes/FileVaultBlack. Later, if you open it again, Mac OS will create the directory /Volumes/FileVaultBlack 1 and use that as mount-point. The issue here is that I configured the AccountPath in Mail.app to a location in /Volumes/FileVaultBlock.. In mortals speech: “Email is broken”.

The solution is to mount the Disk Image when logging in using a predefined mounting point. This involves making a directory and creating an AppleScript application. So lets get busy!

First, eject the Disk Image using the Finder application. It will complain when applications still need it, so you have to make sure that nothing is accessing it.

Create the mountpoint. The idea is to create a directory in /Volumes/ (it doesn’t really matter where you do it, but I like to keep them in one place). I suggest opening Terminal for this and do the following:


shell> mkdir /Volumes/FileVaultBlack

You want to name it differently. I’m using the name of the Disk Image, just like MacOS would do when you double click the .dmg-file.

Open AppleScript Editor and save the following script into a file called, for example, FileVaultBlack_mountatlogin.


do shell script "hdiutil attach /Users/geert/FileVaultBlack.dmg -mountpoint /Volumes/FileVaultBlack"

The above script will execute the hdiutil command-line utility telling it to mount the given Disk Image (.dmg-file) on the give mount-point (the one we created earlier).

Test this script by pushing the Run-button in the AppleScript Editor and see whether your Disk Image is visible in Finder. If not, check the locations of both the Disk Image and the mount-point you gave in the script.

When you saved it, save it again as an application. Still within the AppleScript Editor do the following:

  1. Choose Save As from the File menu
  2. Save As: save it using slighly different name, for example MountFileVaultBlack
  3. File Format: Application
  4. You don’t have to check Run Only

We save it 2 times, once as a script, once as an application. This way, you can easily edit the script later, and save it again as an application. (I’m using different names because it’s less confusing when writing this post.)

Lets now add it to our Login Items:

  1. Open System Preferences and go to Accounts
  2. Make sure you choose My Account, i.e. your account, and go to Login Items
  3. Add an item to the list, clicking the +-sign
  4. Locate the application you created above, in our exampled named MountFileVaultBlack, and press Add.
  5. Check also the Hide option next to the new item.

That should be it. Log out and in and check if the Disk Image is mounting. There should be an icon happily jumping in the Dock while the mounting is on-going. Open Finder and see if your files are accessible.