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

from  eTraveler.clientAPI.connection import Connection


myConn = Connection('jrb', 'Prod', prodServer=False, 
                    appSuffix="-jrb", debug=True)
#myConn = Connection('jrb', 'Dev', prodServer=True);

rsp = {}
htype='ITL-CCD'
traveler='SR-EOT-1'
step = 'read_noise'
hardwareLabels = ['SR_Grade:SR_SEN_Science', 'SR_Grade:SR_SEN_Reserve']

print('Invoking getFilepathsJH with arguments ')
print('htype=',htype, ' travelerName=',traveler, ' stepName=',step,' labels=',hardwareLabels)
try:
    rsp = myConn.getFilepathsJH(htype=htype, stepName=step,
                                travelerName=traveler,
                                hardwareLabels=hardwareLabels)

    for esn in rsp:
        print('For component %s \n' % (esn))
        esnData = rsp[esn]
        for k in esnData:
            if k != 'steps' and k != 'hardwareLabels':
                print(k,' : ', esnData[k])
        if 'hardwareLabels' in esnData:
            print('hardwareLabels:')
            for lbl in esnData['hardwareLabels']:
                print('  ',lbl)
        steps = esnData['steps']
        for s in steps:
            print('For stepName %s \n' % (s) )
            inforecords = steps[s]
            print('Record 0: ')
            for field in inforecords[0]:
                print(field, ':', inforecords[0][field])
            if len(inforecords) > 1:
                print('\nRecord 1: ')
                for field in inforecords[1]:
                    print(field, ':', inforecords[1][field])
    sys.exit(0)
except Exception as msg:
    print('Operation failed with exception: ')
    print(msg)
    sys.exit(1)

