#!/usr/bin/env python

import sys
import os
import getopt
import isi.hw.hal as hal

def usage():
    print >> sys.stderr, "    usage: isi_run_script [-sdh] script args"
    print >> sys.stderr, ""
    print >> sys.stderr, "       -s: run the script on the storage node only"
    print >> sys.stderr, "       -d: run the script on the diskless node only"
    print >> sys.stderr, "       -h: help"
    sys.exit(0)

if __name__ == '__main__':
    try:
	opts, args = getopt.getopt(sys.argv[1:],'sd')
        if len(args) == 0: usage()

        run_on_dna = True
        run_on_storage = True
        for opt in opts:
            if opt[0] == '-h':
                usage()
            elif opt[0] == '-s':
                run_on_dna = False
            elif opt[0] == '-d':
                run_on_storage = False

        if not run_on_dna and not run_on_storage: usage()
        if (not run_on_dna and hal.isAcceleratorClass()) or \
               (not run_on_storage and hal.isStorageClass()):
            sys.exit(0)
        os.execvp(args[0], args)

    except:
        pass
