#!/usr/bin/python

# FIXME Need to handle the case when symlinks already exists

import os

theme_dir = os.path.expanduser('~/.themes/olpc/gtk-2.0')
engine_dir = os.path.expanduser('~/.gtk-2.0/engines')
src_dir = os.path.abspath(os.path.dirname(__file__))

if not os.path.exists(theme_dir):
	try:
		os.makedirs(theme_dir)
	except OSError, exc:
		if exc[0] == 17:   # File exists
			pass
	os.symlink(os.path.join(src_dir, 'gtk-engine/theme/gtkrc'),
			   os.path.join(theme_dir, 'gtkrc'))

engine_dest = os.path.join(engine_dir, 'libolpc.so')
if not os.path.exists(engine_dest):
	try:
		os.makedirs(engine_dir)
	except OSError, exc:
		if exc[0] == 17:   # File exists
			pass
	engine_src = os.path.join(src_dir, 'gtk-engine/src/.libs/libolpc.so')
	os.symlink(engine_src, engine_dest)

@@ -142,16 +142,63 @@
 k-2.0')%0A
+gtkrc_dest = os.path.join(theme_dir, 'gtkrc')%0A%0A
 engine_d
@@ -243,16 +243,70 @@
 gines')%0A
+engine_dest = os.path.join(engine_dir, 'libolpc.so')%0A%0A
 src_dir 
@@ -481,17 +481,71 @@
 %09%09%09pass%0A
-%09
+try:%0A%09os.unlink(gtkrc_dest)%0Aexcept OSError, exc:%0A%09pass%0A
 os.symli
@@ -599,102 +599,21 @@
 c'),
-%0A%09%09%09   os.path.join(theme_dir, 'gtkrc'))%0A%0Aengine_dest = os.path.join(engine_dir, 'libolpc.so')
+ gtkrc_dest)%0A
 %0Aif 
@@ -742,17 +742,16 @@
 %09%09%09pass%0A
-%09
 engine_s
@@ -812,17 +812,72 @@
 pc.so')%0A
-%09
+try:%0A%09os.unlink(engine_dest)%0Aexcept OSError, exc:%0A%09pass%0A
 os.symli

Deal with existing symlinks and add more error checking