Module SDK- Running a Python Script stored in a File

I am interested in running a Python Script which is stored in a file. As per feedback we need to use the Module SDK. The Python Script will have code to change the tag values.

Any suggestions on how to go about?

1st of all, why don’t you just write this as a gateway script or something? Why bother creating a module?

If you really want to write a module that adds a script to the scripting system though, feel free. To get started, download the SDK and read the developer’s guide.

Hi,

Once you sign up for the SDK you’ll have access to the module development forum, which I believe has a few posts about this. One useful resource is this blog dedicated to Ignition module programming: http://ignitionprogramming.blogspot.com/. In particular, this entry might be useful to you.

Regards,

I will clarify this requirement more clearly. There is a third-party system which will send Python script files to the Iginition Server. The Script file will have code/logic to read tag values and set some tags.
So as soon as the script file land on the Ignition Server in a share folder, in Ignition, we have to execute this script file.

We were thinking that we can write a gateway script that will run on a timer event and keep checking the shared folder for new script file. As soon as we find a new script file we should load the content of the file (Which will be a python script) and execute the same. But from your support team, we got a feedback that this is not possible currently in Ignition and we need to write a SDK module.

So my question was, which functions in the SDK will help me do realize the above functionality.

Best Regards
-Prasad

Hope I am making it clear that, new scripts will be sent by the Third-Party System time and again as script files and it is Ignitions job to execute this script.

Best Regards
-Prasad

Here is an idea,

read the file into a variable and then eval the variable. See here for python details.

This assumes that eval or exec are available in Jython 2.1 (or 2.5 if you want to wait for 7.4 (now in beta!))

Both are available.

I think exec would be closer to what you’d want. I don’t think eval would actually execute code.

Thanks for the suggestion. I just wanted to know why this wont work in the Gateway scripts?
Becuase going to the SDK to achieve this makes it more technical.

Best Regards
-Prasad

If it works in the playground, it’ll work everywhere. The gateway console may give you an idea on what’s going on in the script-- or what’s not going on as the case may be.

Also keep in mind that we’re at a python 2.1 implementation until Ignition 7.4 is official, so make sure the generated script isn’t using any “future functionality”. Believe me, that threw me for a loop a couple of times!


Hi Prasad,

Hope you got it working. Just wanted to point out the security danger in this approach to anyone following this thread. While this is certainly doable as Jordan has demonstrated above, you have to make really sure that the script you are running is coming from a trusted source. Because Jython will run whatever is in the script as the user that is running the gateway. If the gateway user is root, your whole system is at the mercy of whoever writes that script.

This is a very cool ability of Python, Perl, PHP and a number of other ‘scripting’ languages (I’ve used it myself in the past) but it’s also very dangerous if the correct safeguards are not in place.

Thanks guys for all your help.