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

import sys

from  eTraveler.clientAPI.connection import Connection


myConn = Connection('jrb', 'Dev', prodServer=False, appSuffix='-jrb', debug=True)

rsp = {}
##htype='e2v-CCD'
htype='LCA-10307'
traveler='NCR'
##step = 'NCR_C_Final_disposition'
step = 'NCR_Approval'

print('Invoking getMissingSignatures with status puased or inProgress ')
#print 'htype=',htype, ' travelerName=',traveler, ' stepName=',step
#,' experimentSN=',eSN
try:
    #rsp = myConn.getMissingSignatures(activityStatus=["paused", "inProgress"])
    rsp = myConn.getMissingSignatures()


    print('Data returned for ',len(rsp), ' components')
    for esn in rsp:
        print('For component %s \n' % (esn))
        esnData = rsp[esn]
        for r in esnData:
            print('For run number=', r)
            
            runData = esnData[r]
            for k in runData:
                if k != 'steps':                
                    print(k,' : ', runData[k])
            steps = runData['steps']
            for s in steps:
                print('For stepName %s \n' % (s) )
                steprecords = steps[s]     # array of dicts
                for rec in steprecords:
                    # sreq is 
                    for field in rec:
                        print(field, ':', rec[field])
            
    sys.exit(0)
except Exception as msg:
    print('Operation failed with exception: ')
    print(msg)
    sys.exit(1)

