Article
· May 31, 2023 6m read

Iris Interoperability Command Line Interface (iop)

I'm proud to announce the new release of iris-pex-embedded-python (v2.3.1) with a new command line interface.

This command line is called iop for Interoperability On Python.

First I would like to present in few words the project the main changes since the version 1.

A breif history of the project

Version 1.0 was a proof of concept to show how the interoperability framework of IRIS can be used with a python first approach while remaining compatible with any existing ObjectScript code.

What does it mean? It means that any python developer can use the IRIS interoperability framework without any knowledge of ObjectScript.

Example :

from grongier.pex import BusinessOperation

class MyBusinessOperation(BusinessOperation):

    def on_message(self, request):
        self.log.info("Received request")

Great, isn't it?

With version 1.1, I added the possibilty to register those python classes to IRIS with an helper function.

from grongier.pex import Utils

Utils.register_file("/src/MyBusinessOperation.py")

Version 2.0 was a major release because now you can install this project with pip.

pip install iris-pex-embedded-python

What's new in version 2.3.1

Version 2.3.1 is a major release because it introduces a new command line interface.

This command line interface can be used with this python project based on this module or maybe with projects that doesn't use this module.

Let me introduce it and explain why it can be used in non python projects.

The command line interface

The command line is part of this project, to install it you just have to install this project with pip.

pip install iris-pex-embedded-python

Then you can use the command line iop to start the interoperability framework.

iop

output :

usage: iop [-h] [-d DEFAULT] [-l] [-s START] [-k] [-S] [-r] [-M MIGRATE] [-e EXPORT] [-x] [-v] [-L]
optional arguments:
  -h, --help            display help and default production name
  -d DEFAULT, --default DEFAULT
                        set the default production
  -l, --lists           list productions
  -s START, --start START
                        start a production
  -k, --kill            kill a production (force stop)
  -S, --stop            stop a production
  -r, --restart         restart a production
  -M MIGRATE, --migrate MIGRATE
                        migrate production and classes with settings file
  -e EXPORT, --export EXPORT
                        export a production
  -x, --status          status a production
  -v, --version         display version
  -L, --log             display log

default production: UnitTest.Production

Let's go in few examples.

help

The help command display the help and the default production name.

iop -h

output :

usage: python3 -m grongier.pex [-h] [-d DEFAULT] [-l] [-s START] [-k] [-S] [-r] [-M MIGRATE] [-e EXPORT] [-x] [-v] [-L]
...
default production: PEX.Production

default

The default command set the default production.

With no argument, it display the default production.

iop -d

output :

default production: PEX.Production

With an argument, it set the default production.

iop -d PEX.Production

lists

The lists command list productions.

iop -l

output :

{
    "PEX.Production": {
        "Status": "Stopped",
        "LastStartTime": "2023-05-31 11:13:51.000",
        "LastStopTime": "2023-05-31 11:13:54.153",
        "AutoStart": 0
    }
}

start

The start command start a production.

To exit the command, you have to press CTRL+C.

iop -s PEX.Production

If no argument is given, the start command start the default production.

iop -s

output :

2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting production
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.FileOperation
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.EmailOperation
...

kill

The kill command kill a production (force stop).

Kill command is the same as stop command but with a force stop.

Kill command doesn't take an argument because only one production can be running.

iop -k 

stop

The stop command stop a production.

Stop command doesn't take an argument because only one production can be running.

iop -S 

restart

The restart command restart a production.

Restart command doesn't take an argument because only one production can be running.

iop -r 

migrate

The migrate command migrate a production and classes with settings file.

Migrate command must take the absolute path of the settings file.

Settings file must be in the same folder as the python code.

iop -M /tmp/settings.py

export

The export command export a production.

If no argument is given, the export command export the default production.

iop -e

If an argument is given, the export command export the production given in argument.

iop -e PEX.Production

output :

{
    "Production": {
        "@Name": "PEX.Production",
        "@TestingEnabled": "true",
        "@LogGeneralTraceEvents": "false",
        "Description": "",
        "ActorPoolSize": "2",
        "Item": [
            {
                "@Name": "Python.FileOperation",
                "@Category": "",
                "@ClassName": "Python.FileOperation",
                "@PoolSize": "1",
                "@Enabled": "true",
                "@Foreground": "false",
                "@Comment": "",
                "@LogTraceEvents": "true",
                "@Schedule": "",
                "Setting": [
                    {
                        "@Target": "Adapter",
                        "@Name": "Charset",
                        "#text": "utf-8"
                    },
                    {
                        "@Target": "Adapter",
                        "@Name": "FilePath",
                        "#text": "/irisdev/app/output/"
                    },
                    {
                        "@Target": "Host",
                        "@Name": "%settings",
                        "#text": "path=/irisdev/app/output/"
                    }
                ]
            }
        ]
    }
}

status

The status command status a production.

Status command doesn't take an argument because only one production can be running.

iop -x 

output :

{
    "Production": "PEX.Production",
    "Status": "stopped"
}

Status can be :
- stopped
- running
- suspended
- troubled

version

The version command display the version.

iop -v

output :

2.3.0

log

The log command display the log.

To exit the command, you have to press CTRL+C.

iop -L

output :

2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting production
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.FileOperation
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.EmailOperation
...

Can it be used outside of iris-pex-embedded-python project ?

That's your choice.

But, before you leave, let me tell why I think it can be used outside of iris-pex-embedded-python project.

First, because it can interact with production without the need to use an iris shell. That means it's easier to use in a script.

Secoud, because settings.py can be used to import production and classes with environment variables.

Here is an example of settings.py :

import os

PRODUCTIONS = [
        {
            'UnitTest.Production': {
                "Item": [
                    {
                        "@Name": "Python.FileOperation",
                        "@ClassName": "Python.FileOperation",
                        "Setting": {
                            "@Target": "Host",
                            "@Name": "%settings",
                            "#text": os.environ['SETTINGS']
                        }
                    }
                ]
            }
        } 
    ]

Pay attention to #text value. It's an environment variable. Neat, isn't it ?

Do you see yourself using this command line tool, worth it to keep developing it ?

Thanks for reading and your feedbacks are welcome.

Discussion (3)2
Log in or sign up to continue

Hi Evgeny,

Thanks for your feedback.

The -x option is for status, because -s is already used to start a production.

The -e option is for export, and the export can be imported with the -m option.
-m option stand for migrate, because I took the inspiration from the migrate command form django.

I hope it's more clear now.

But if you think, -i for import and -e for export is more clear, I can change it.
Same for -s and -x. What do you think can be short for status?

Hi @Guillaume Rongier !

Well explained. I just hope the UI be more intuitive - this pays a lot in the future for the better adoption of the tool.

I understand that there are not many letters in the alphabet and it can go to the end quickly. In this case I'd keep with what you think on one-letters and also introduce synonyms of fulltext with double --.e.g.

--import for import,

--export for export and 

--status for status.

This could help with readability in long scripts with cli or with documentation.