#!/usr/bin/python

# Below are required imports for the script to run
import os, sys

# The below few lines of code are to determine the OS of the machine that your running 
# this script from and then define the location of the Qube! API
if 'QBDIR' in os.environ:
	sys.path.append('%s/api/python' % os.environ['QBDIR']);
elif os.uname()[0] == 'Darwin':
	sys.path.append('/Applications/pfx/qube/api/python');
elif os.uname()[0] == 'Linux':
	sys.path.append('/usr/local/pfx/qube/api/python');
else:
	sys.path.append('c:/program files/pfx/qube/api/python');

# The below line of code is to import the above defined Qube! API
import qb

# Below is the main function to run in this script 
def main():
    # Below creates an empty dictionary to be filled by the following lines of code 
    job = {}
    # Below defines the name of the Qube! job 
    job['name'] = 'python test job'
    # Below defines how many Instances/subjobs the job is to spawn
    job['cpus'] = 1
    # Below defines the internal Qube! jobtype to be used to execute the job
    job['prototype'] = 'cmdline'
    
    # The below parameters are explained further in the "Job submission with job package explained" page
    package = {}
    job['package'] = package
    job['package']['cmdline'] = 'hostname'

    # Below creates an empty list filled by the following lines of code 
    listOfJobsToSubmit = []
    # Below evaluates the jobs to be submitted and adds the to the above list 
    listOfJobsToSubmit.append(job)

    # Below calls the list of jobs to be submitted and then prints the job IDs for each
    listOfSubmittedJobs = qb.submit(listOfJobsToSubmit)
    for job in listOfSubmittedJobs:
        print job['id']

# Below runs the "main" function 
if __name__ == "__main__":
    main()
    sys.exit(0)
