Skip to main content
Solved

How can I script a connection parameter with python

  • July 9, 2018
  • 4 replies
  • 95 views

dollargis
Contributor
Forum|alt.badge.img+6

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

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+6
  • 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+3
  • 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+6
  • Author
  • Contributor
  • July 10, 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.

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.