I'm trying to add the zip file size to the data download service notification email. This is the method I'm using:
- Workspace writes the data to be downloaded and a json file containing the information elements I will use in the email.
- Python shutdown script gets the zip file size from the zip file and appends a 'zip_size' element to the json (this doesn't work)
- workspace published as a data download service with its own success topic and publisher. The publisher is set to access the info in the modified json file (set as 'Data to Post') when workspace published (this doesn't work)
This is my python shutdown script
import os import json import fme def sizeof_fmt(num, suffix='B'): for unit in ['','K','M','G','T','P','E','Z']: print "unit: {0} number: {1}".format(unit, num) if abs(num) < 1024.0: return "{number:.{digits}f} {u}{suff}".format(number=num, digits=1, u=unit, suff=suffix) num /= 1024.0 return "{number:.{digits}f} {u}{suff}".format(number=num, digits=1, u="Y", suff=suffix) logger = open(fme.logFileName,'a') # get required FME parameter values zipDir = fme.macroValues['FME_SERVER_DEST_DIR'] logger.write("Zip Directory: {0}".format(zipDir)) print "Zip Directory: {0}".format(zipDir) successJSON = fme.macroValues['success_json'] logger.write("Success Json File: {0}".format(successJSON)) print "Success Json File: {0}".format(successJSON) # get the data download zip file size osSize = sizeof_fmt(os.path.getsize(zipDir)) logger.write("Zip file size: {0}".format(osSize)) print "Zip file size: {0}".format(osSize) # modify the Success JSON with open(successJSON, 'r+') as outfile: data = json.load(outfile) # add ZIP_SIZE value data['zip_size'] = osSize outfile.seek(0) # reset file position to the beginning logger.write("Success JSON Content: {0}".format(data)) print data json.dump(data, outfile, indent=4, sort_keys=True) logger.write("Update to success JSON done") print "Update to success JSON done"
Note:
This is the 'success_json' parameter value from the job log file
`--success_json' `$(FME_MF_DIR)SuccessJSON\successJson.txt'
This is also from the log file
`-TEXTLINE_3_DATASET' `/data/fmeserver/DefaultResults/FME_252F7068_1440392215399_29199_nw/successJson.txt'
Is TEXTLINE_3_DATASET a parameter I can access in the shutdown script? Maybe I'm looking for the output text file in the wrong place.
Thanks
Rob