Just to clarify. There is a tester and terminator if the 2 extracted values do not match the expected values and the error occurs if the terminator is hit. If the tests pass the workspace completes successfully.
Â
Â
I have just tried this with a python class as well:
Â
Â
class FileInfo(object):   def __init__(self):     pass    def input(self,feature):     try:       dir = FME_MacroValuesÂ'SourceDirectory']       fileName = FME_MacroValues 'SourceTileId']       file = dir + "\\\\" + fileName + ".TIF"             digest = hashlib.md5(open(file, 'rb').read()).hexdigest()             fileSize = os.path.getsize(file) >> 20             feature.setAttribute("actual_fileSize", fileSize)       feature.setAttribute("actual_md5", digest)             self.feature = feature      except:       print "Exception in user code:"       print '-'*60       traceback.print_exc(file=sys.stdout)       print '-'*60      def close(self):     self.pyoutput(self.feature)
Â
 and get:
Â
Â
Validation_Terminator: Aborting Translation as directed by mapping file. Message is 'Image md5 checksum does not match that supplied;'.
Aborting Translation as directed by mapping file. Message is '%0'.
PythonFactory failed to close properly
PythonFactory failed to close properly
A fatal error has occurred. Check the logfile above for details
Hi,
Â
Â
first of all, if you use a Python class definition, you probably want to output every feature that passes through, not just the last. Modify your code like this:
Â
Â
class FileInfo(object):   def __init__(self):     pass    def input(self,feature):     try:       dir = FME_MacroValuesÂ'SourceDirectory']       fileName = FME_MacroValues 'SourceTileId']       file = dir + "\\\\" + fileName + ".TIF"             digest = hashlib.md5(open(file, 'rb').read()).hexdigest()             fileSize = os.path.getsize(file) >> 20             feature.setAttribute("actual_fileSize", fileSize)       feature.setAttribute("actual_md5", digest)             self.pyoutput(feature)      except:       print "Exception in user code:"       print '-'*60       traceback.print_exc(file=sys.stdout)       print '-'*60      def close(self):     self.pyoutput(self.feature)
Â
Â
I also suspect that there might be a typo in your filesize calculation:
Â
  fileSize = os.path.getsize(file) >> 20
Â
Â
It should perhaps read:
Â
  fileSize = os.path.getsize(file) >> 0x20
Â
Â
This is to force a hexadecimal interpretation of the "20" literal. Although I'm not quite sure I understand why you shift the result to begin with... :-)
Â
Â
David
I shift the result to get an answer in MB as the min/max are defined in MB.
Â
Â
I made the changes you suggested and although I no longer get the errors above the output is not as expected.
Â
Â
To explain the flow further:
Â
1) code above is run to find md5 checksum and file size in MB
Â
2) 2 testers compare the result with expected values passed to the workspace and a string is generated on failure (using a string concatenator)
Â
3) A tester checks the existence of the above string and passes to a terminator if is found.
Â
Â
Now before adding this new validation check (others in the flow check image attributes) the output if tests failed included the messages from the terminator and the workspace failed. But for some reason with the python caller introduced I don't get a translation failure I get successful and the message isn't shown, even though the UI shows the process running to the terminator.
Ok solved this by moving the code to fetch md5 and file size to scripted parameters, then using these parameters in my testers.
Â
Â
Thanks for your help David
Â
Â
mark
Hi,
Â
Â
good to hear that you found a solution.
Â
Â
Just be aware that by shifting bytes is an integer operation, i.e. the result will 0 when the filesize is less than 1MB, etc.
Â
Â
If you need fractional filesizes, consider the formula
Â
  size_in_mb = size_in_bytes / float(2**20)
Â
Â
David