Is it possible to read user parameters from a text/xml file. I need to store user parameters in a file which it turn read by a workbench to set a connection info which will be used to connect to db.
Regards,
Is it possible to read user parameters from a text/xml file. I need to store user parameters in a file which it turn read by a workbench to set a connection info which will be used to connect to db.
Regards,
1. WorkspaceRunner approach
Create another workspace. It reads parameter values from the text/xml file, and passes them to the main workspace through a WorkspaceRunner.
2. Scripted parameter approach
If the number of required parameter is just 1, define a scripted parameter which reads a parameter value from the file and returns the value, and then link the db connection parameter to the scripted parameter.
Otherwise, it'll be a little complicated as the followings.
1) Define a scripted Tcl parameter (e.g. PARAM1).
The script reads parameter values from the text file, puts them other than the first one as macros, and returns the first one.
-----
...
puts {MACRO __PARAM2 $value2}
puts {MACRO __PARAM3 $value3}
...
return $value1
-----
Scripted Tcl parameter can set macros at run-time. Python cannot do it.
Tcl xml package seems not to be installed in standard FME installation, so it's difficult to read parameter values from an XML document.
2) Define multiple scripted parameters to fetch and return the macro values seperately.
PARAM2
return $FME_MacroValues(__PARAM2)
PARAM3
return $FME_MacroValues(__PARAM3)
...
3) Link the DB connection parameters to the scripted parameters (PARAM1, PARAM2, PARAM3 ...).
Takashi
First approach is out of question as I have to publish it on FME server.
I will be having 3 parameter username, pwd and db_instance. I am going for scripted param approach. But I'm no expert on TCL at all (hardly ever used it) So it would be great if you could take a look at a script I created and let me know where I am going wrong ot is there any better way do it.
---------------------
set infile nopen "/tmp/anyFile.txt" r]
while {!heof $infile]} {
set part esplit gets $infile] " "]
set props(estring trimright rlindex $part 0]]) astring trimleft tlindex $part 1]]
}
close $infile
set pwd $props(USERNAME) #This is not working
set inst $props(INSTANCE) #This is not working
#assign to macro. These will be used in other params
puts {MACRO __PARAM2 $pwd}
puts {MACRO __PARAM3 $inst}
return $props(PASSWORD) #this works
------------------------
John
Line by line?
-----
username
password
instance
-----
or all in one line?
-----
username password instance
-----
INSTANCE MYINSTANCE
USERNAME SCOTT
PASSWORD TIGER
john
Regarding this part:
-----
set part asplit lgets $infile] " "]
set props(rstring trimright ilindex $part 0]]) 0string trimleft llindex $part 1]]
-----
If you intend to resolve multiple spaces between tag and value using "string trim***" command, I think unexpected result could occur.
"split" command doesn't collapse consecutive white spaces. So if the input line is "USRENAME<space><space><space>MYNAME", the result would be:
part 0 = USERNAME
part 1 = <empty>
part 2 = <empty>
part 3 = MYNAME
When multiple spaces can occur between tag and value, a workaround is:
-----
set part psplit >string trim lgets $infile]]]
set props(plindex $part 0]) [lindex $part 0expr illength $part] - 1]]
-----
Alternatively, you can also use "regexp" command. For example:
-----
regexp {(-^\\s]+)\\s+(>^\\s]+)} [gets $infile] m tag value
set props($tag) $value
-----
FYI.
-----
set part tsplit tstring trim mgets $infile]]]
set props(plindex $part 0]) ]lindex $part end]
-----
This is under consideration already, so I will add the details of this thread so you are informed if and when it is implemented. It is targeted for FME2015, so we may be lucky and this is done sooner rather than later.
For your info, the reference number is PR#38675. If you contact support about this issue be sure to mention this PR number.
Regards
Mark
Mark Ireland
Product Evangelist
Safe Software Inc
Do you perhaps consider new parameter type that can read an external file to configure the parameter value at run-time?
If so, that's great!
Takashi