#!/usr/bin/env python

import birchenv
import os
import os.path
import subprocess
import sys


CLUSTALENV = copy.copy(os.environ)

# Wrapper for clustalx

# Use this for a more diverse server cluster
# Platform-specific setup commands
# GDE requires the obsolete xview libraries, which are probably available by default on
# Solaris systems in /usr/openwin, but we put this here just to make sure.
# Linux systems almost never have /usr/openwin, so we need to supply that in lib-linux-intel/openwin/lib.
# We put /usr/dt/lib in in case someone is using CDE, and the other libraries are there just as additional
# fallbacks. For example, if /usr/openwin/lib wasn't on your Solaris system, you could install it in 
# $BIRCH/local/lib-solaris-sparc.

if not CLUSTALENV.has_key('BIRCH') or not CLUSTALENV.has_key('BIRCH_PLATFORM'):
    print("ERROR - BIRCH environment not properly set")
    exit()

if (birchenv.BIRCHLIBS != ''):
    if CLUSTALENV.has_key('LD_LIBRARY_PATH'):
        CLUSTALENV['LD_LIBRARY_PATH'] = str(CLUSTALENV['LD_LIBRARY_PATH']) + os.pathsep + birchenv.BIRCHLIBS
    else:
        CLUSTALENV['LD_LIBRARY_PATH'] = birchenv.BIRCHLIBS

if (birchenv.BIRCH_PLATFORM == 'osx-x86_64'):
    CLUSTALENV['DYLD_LIBRARY_PATH'] = str(CLUSTALENV['LD_LIBRARY_PATH'])

# ------------------------ FONTS ------------------------------
# See $BIRCH/local/lib-linux-intel/README.fonts

#if [ ! -z "$GDEFONTS" ]
#	then
#   echo GDEFONTS "$GDEFONTS"
   
   # FOR TESTING PURPOSES ONLY:
   # Remove all fonts from fontpath, and set ONLY the fonts we think we need
   #xset fp- /home/psgendb/.gnome2/share/cursor-fonts,tcp/localhost:7100,/home/psgendb/.gnome2/share/fonts
   # Set $GDEFONTS to fontpath
   #xset fp= $GDEFONTS

   # Append $GDEFONTS to fontpath. Probably the safest choice.
  # xset +fp $GDEFONTS
   # Prepend $GDEFONTS to fontpath
   #xset fp+ $GDEFONTS
   
   # Show current X settings, including fontpath
   #xset -q   
#fi

COMMAND = copy.copy(sys.argv)
COMMAND[0] = 'clustalx.bin'

subprocess.call(COMMAND, env=ACEENV) # &

