Skip to main content
Solved

Details needed to make Python shutdown script delete input file


Forum|alt.badge.img

Hi,

I have a workspace that uses the custom FeatureCounter followed by a TestFilter. If too many features for my conversion I port to a Terminator transformer.

Following termination I want to delete the input file as part of a Python Shutdown script. The path including filename are in a Published Parameter. Example: [source_file]: c:\\folder\\file.ext

I've looked at lots of info but my attempts produce errors or the file doesn't get deleted, or both.

Can someone with good experience with this provide details on all lines needed in the shutdown script (and if needed, any Python needed in the body of the workspace)?

Thanks!

Best answer by david_r

You can try the following in your shutdown script:

import fme
import os

if not fme.status:
    os.remove(fme.macroValues['source_file'])

This will delete the file referenced in the parameter "source_file" if the workspace failed, e.g. with a Terminator.

View original
Did this help you find an answer to your question?

2 replies

david_r
Evangelist
  • Best Answer
  • August 29, 2018

You can try the following in your shutdown script:

import fme
import os

if not fme.status:
    os.remove(fme.macroValues['source_file'])

This will delete the file referenced in the parameter "source_file" if the workspace failed, e.g. with a Terminator.


Forum|alt.badge.img
  • Author
  • August 29, 2018

Thanks @david_r, indeed that worked. Oddly I still got an error with your code. In the end, the issue had to do with the "type" of the published parameter that holds the filename (that parameter was created by someone else). So I re-created the parameter as a text type, and that made both the FeatureReader and the exit script Python happy. 

Below I'm including the error I got prior to re-creating the parameter, in case the same thing happens to anyone else. That issue with the parameter type took far too much time to track down, believing the problem had to do with a mistake in my use of the Python in the shutdown script.

FME_END_PYTHON: evaluating python script from string...
END - ProcessID: 16548, peak process memory usage185908 kB, current process memory usage82432 kB

Python Exception <WindowsError>: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'c:<backslash>folder<backslash>roger<backslash>file.ext'
Error executing string `import fme
import os
if not fme.status:
    os.remove(fme.macroValues['source_file'])
'
FME_END_PYTHON failed to execute provided script

Terminator_5: Termination Message: 'Translation Terminated due to too many features in file'
Program Terminating

Translation FAILED.

Thanks again.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings