#!/usr/bin/env python
import os
import sys
import commands
import time
import subprocess

pstr = commands.getstatusoutput('ps -fe')

#print "pstr = ",pstr

if not "JythonConsole" in pstr :
        print "Starting Jython console";
        subprocess.Popen(["gnome-terminal","--command=./org-lsst-ccs-subsystem-console/trunk/target/distribution/bin/CCSbootstrap.sh --app JythonConsole"]);

if not "TrendingIngestModule" in pstr :
        print "Starting trending persister";
        subprocess.Popen(["gnome-terminal","--command=./localdb/trendingPersister.sh localdb/testDb.properties"]);

if not "LocalRestServices" in pstr :
        print "Starting trending server";
        subprocess.Popen(["gnome-terminal","--command=./localdb/trendingServer.sh localdb/testDb.properties"]);

if not "-app ts" in pstr :
        print "Starting testand subsystem";
        subprocess.Popen(["gnome-terminal","--command=./org-lsst-ccs-subsystem-teststand/trunk/main/target/distribution/bin/ts_sim.sh"]);

time.sleep(2)

if not "archon" in pstr :
        print "Starting archon subsystem";
        subprocess.Popen(["gnome-terminal","--command=./org-lsst-ccs-subsystem-archon/trunk/main/target/distribution/bin/CCSbootstrap.sh --description ../etc/archonSim.groovy --configuration ../etc/archonSim.properties -D org.lsst.ccs.startInEngineeringMode=true --app archonSim"]);

time.sleep(5)

if (~("CCS-Console" in pstr)) :
        print "Starting teststand GUI subsystem";
        subprocess.Popen(["gnome-terminal","--command=./org-lsst-ccs-subsystem-teststand/trunk/gui/target/distribution/bin/tsJas.sh"]);
