Skip to main content
Solved

How can I script a connection parameter with python


dollargis
Contributor
Forum|alt.badge.img+1

In our environment workspace development and published server are on different systemes, therefore the workspaces have to use not-previously-known fme web connections for communication, especially submitting calls to child workspaces.

After some deliberation it seems that a scripted connection parameter that reads its value(s) from a configuration file would be the ideal solution to gain the necessary indepence of runtime environments.

I found https://knowledge.safe.com/articles/844/setting-up-a-workspace-to-deploy-in-production-sta.html and https://knowledge.safe.com/questions/4296/set-published-parameters-in-a-python-startup-scrip.html but cannot figure out how to use these techniques for a connection parameter

Best answer by nielsg

If you want to use a scripted parameter in combination with a config file, I would recommend the following:

FME Workbench:

  1. Create a subdirectory in the directory where your .fmw file is located. Call this subdirectory 'config'.
  2. Create a new file __init__.py in the config directory.
  3. Put the configuration parameters you need in the __init__.py file as key value pairs:
host_dev=http://fme-dev.com/
user_dev=admin
password_dev=admin


host_prod=http://fme-prod.com/
user_prod=admin
password_prod=admin
  1. In your FME Workspace, create a new Scripted (Python) parameter for each property from your config you need. Return the required value like this (host_dev in this case):
import config as conf
return conf.host_dev	

FME Server:

To be able to use your config file, you will need to upload the config to your FME Servers:

Upload the config-directory and the __init__.py file to resources/Engine/Plugins/python/python27

The result will be a 'config' directory inside the python27 directory.

With that done, your scripted parameters will read the config uploaded to the FME Server.

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

4 replies

lars_de_vries
Forum|alt.badge.img+10

Have you tried to manually create a Published Parameter of the type 'Scripted (Python)' and than to link it to your reader?


dollargis
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • July 9, 2018

@lars_de_vries: In my case I do not need it for a reader database name or password, but for a job submitter like here:

The variable $(SERVER_CONNECTION) is the one that should be scriptable.


nielsg
Contributor
Forum|alt.badge.img+2
  • Contributor
  • Best Answer
  • July 9, 2018

If you want to use a scripted parameter in combination with a config file, I would recommend the following:

FME Workbench:

  1. Create a subdirectory in the directory where your .fmw file is located. Call this subdirectory 'config'.
  2. Create a new file __init__.py in the config directory.
  3. Put the configuration parameters you need in the __init__.py file as key value pairs:
host_dev=http://fme-dev.com/
user_dev=admin
password_dev=admin


host_prod=http://fme-prod.com/
user_prod=admin
password_prod=admin
  1. In your FME Workspace, create a new Scripted (Python) parameter for each property from your config you need. Return the required value like this (host_dev in this case):
import config as conf
return conf.host_dev	

FME Server:

To be able to use your config file, you will need to upload the config to your FME Servers:

Upload the config-directory and the __init__.py file to resources/Engine/Plugins/python/python27

The result will be a 'config' directory inside the python27 directory.

With that done, your scripted parameters will read the config uploaded to the FME Server.


dollargis
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • July 10, 2018
nielsg wrote:

If you want to use a scripted parameter in combination with a config file, I would recommend the following:

FME Workbench:

  1. Create a subdirectory in the directory where your .fmw file is located. Call this subdirectory 'config'.
  2. Create a new file __init__.py in the config directory.
  3. Put the configuration parameters you need in the __init__.py file as key value pairs:
host_dev=http://fme-dev.com/
user_dev=admin
password_dev=admin


host_prod=http://fme-prod.com/
user_prod=admin
password_prod=admin
  1. In your FME Workspace, create a new Scripted (Python) parameter for each property from your config you need. Return the required value like this (host_dev in this case):
import config as conf
return conf.host_dev	

FME Server:

To be able to use your config file, you will need to upload the config to your FME Servers:

Upload the config-directory and the __init__.py file to resources/Engine/Plugins/python/python27

The result will be a 'config' directory inside the python27 directory.

With that done, your scripted parameters will read the config uploaded to the FME Server.

Thanks, @nielsg

 

This is the way I will go, refining it with ini-style config files. 

 

 

I was glad to find out that the fme-server-connections that are used by the FMEServerJobSubmitter can be coded as plain strings, assuming that such a connection is defined in the server environment. This alleviates my task tremendously.

 


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