Question

Shutdown Python Script - Runtime errors

  • 15 March 2013
  • 5 replies
  • 5 views

Hello:

 

 

I am trying to implement this portion of Python code on my shutdown script, but I don't get it to work:

 

 

import pyfme import fmeobjects import os import subprocess   logger = pyfme.FMELogfile() fmeExecutable = os.path.normpath(FME_MacroValues['FME_Executable']) workBench = os.path.normpath(FME_MacroValues['Workbench_To_Run'])   # update the File Change and Population logs if translation successful if str(FME_Status) == "True":   myWorkbench.updateFileChangeLog(FME_MacroValues['FMW'])   myWorkbench.updatePopulationLog(FME_FeaturesWritten)     # initiate materialized view refresh if changes to either source   if FME_TotalFeaturesWritten > 0:     logger.log('Updates detected, executing materialized view refresh script - ' + workBench)     args = [fmeExecutable, workBench]     p = subprocess.Popen(args)

 

 

-- Runtime errors:

 

 

FME_END_PYTHON: evaluating python script from string... Python Exception <KeyError>: 'FME_Executable' Error executing string `import pyfme import os import subprocess   I have seen several examples using  "fmeExecutable = os.path.normpath(FME_MacroValues['FME_Executable'])", which I think is causing the problem (as per the message), so I thought this would work...

 

 

Any ideas?

 

 

Thanks

 

 

Richard.

5 replies

Userlevel 4
Hi Richard,

 

 

write a shutdown script with the following Python code:

 

 

-----

 

import fmeobjects import pprint   pp = pprint.PrettyPrinter(indent=4) pp.pprint(FME_MacroValues)

 

-----

 

 

It will output all the possible dictionary keys available in FME_MacroValues to the log file. I suspect you will not find "FME_Executable" in there, but you might find another key that does about the same thing.

 

 

Also have a look here for more info.

 

 

David
Userlevel 4
Hi again,

 

 

one more thing: if you have copied this code from elsewhere, please note that it does not look complete at all. There are references to undefined objects (the class "myWorkbench" in particular) and I doubt you will get it to work unless you have a lot more code than what you posted.

 

 

It also seems that it references some workbench-specific user parameters (have you defined those?), such as "FME_Executable", "Workbench_To_Run" and "FMW".

 

 

What are you trying to accomplish? There might be a better way...

 

 

David
Thank you David!

 

 

That was a very useful code! Although it helped me get through other  problems there is no key to get the FME executable. I must indicate I am running the executables logged onto a Citrix Server, if that helps.

 

 

Any comment, will be much appreciated.

 

 

Thanks,

 

 

Richard.
Userlevel 4
Hi Richard,

 

 

good to hear you're on track. It is very possible that "FME_Executable" was defined as a user parameter (either private or published) in the workspace where you got your code.

 

 

If you have the original workspace available, I recommend you have a look there to see how it is defined. If not, you could just create a user parameter called "FME_Executable" and set it to the desired value, e.g. "C:/Program Files/FME/fme.exe"

 

 

David
Hi David:

 

 

Thank you so much, I found the solution. And yes, I created those values and the final script looks like this (at least works, although not very elegant).

 

 

I was incorporating this as part of the Python Shutdown script to execute upon succesful data load. The script calls another script, defined as "Workbench_To_Run". It does work now, and I am reviewing the results of the second script's run.

 

 

Code below:

 

 

import pyfme import os import subprocess   logger        = pyfme.FMELogfile() fmeExecutable = os.path.normpath(FME_MacroValues['FME_HOME'])+'\\FME.exe' workBench     = os.path.normpath(FME_MacroValues['Workbench_To_Run'])          # initiate materialized view refresh if changes to either source if FME_TotalFeaturesWritten > 0:   logger.log('Updates detected, executing materialized view refresh script - ' + workBench)   args = [fmeExecutable, workBench]   p = subprocess.Popen(args)

 

 

Thanks again!

 

 

Richard,

Reply