#!/usr/bin/env python
from __future__ import print_function
import sys

from  eTraveler.clientAPI.connection import Connection
from  eTraveler.clientAPI.connection import ETClientAPINoDataException

myConn = Connection('jrb', 'Prod', 
                    debug=True, prodServer=False, appSuffix='-jrb')
#myConn = Connection('jrb', 'Dev', localServer=True, debug=True)
#myConn = Connection('jrb', 'Raw', prodServer=True)
rsp = {}
try:
    htype = 'ITL-CCD'
    expSN = 'ITL-3800C-021'
    travelerName='SR-EOT-1'
    print("Calling getComponentRuns with htype=", htype, " id=",expSN, " travelerName=",travelerName)

    rsp = myConn.getComponentRuns(htype=htype, experimentSN=expSN,
                                  travelerName=travelerName,
                                  runStatus=['success'])

    for k in rsp:
      print("For run with rootActivityId=", k)
      runDict = rsp[k]
      for kk in runDict:	
        print('  Value for key ', kk, ' is ', runDict[kk])

    sys.exit(0)
except ETClientAPINoDataException as msg:
    print('No data exception: ',msg)
    sys.exit(1)
except Exception as msg:
    print('Operation failed with exception: ')
    print(msg)
    sys.exit(1)

