Occasionally you want to automate recurring tasks in your Smallworld GIS installation. It may sound trivial, but there are a number of different ways this can be done, and not all are equally well suited …
Most frequently encountered, and seemingly the natural way, is to use input redirection onto the CLI of a session:
This looks good. Many command lines can be used that way, like the
*nix shells and tools, and emacs in batch mode. EOF on STDIN means
quit. But not for
sw_magik. And this “uncommon” behaviour can
cause problems. Amongst are the fact that you tend to not launch
sw_magik through the
gis.exe, and also there is the stuck process
in case of a traceback.
There is a better solution: the Tool Image. It is a lot more
convenient to have an image that, upon startup, does the task due, and
then terminates. Doing things at startup is accomplished by
specifying a startup proc when saving an image. Thus what you need is
_proc that executes your task.
1 2 3 4 5 6 7 8 9 10 11
Many “task scripts” can be converted into this structure easily. You could add command line options before saving the image, or use environment variables to control runtime behaviour.
An example minimal
gis_aliases entry for this image would look like:
and you start it like so:
The advantages of this approach are numerous. Personal gains include
reliable termination in case of an error, better environment control
through the use of
gis.exe and the enablement of continuous
integration for Smallworld GIS.
I wanted to share the approach. But this is just the start. The mechanics presented here can be extended in a million ways. You read about command line arguments and environment settings above, but really, in your tool image you can do anything Smallworld GIS can do.
Addendum January 2016
I found another and more general way of doing this: command line options. It is super simple - register the parameters, write a proc to evaluate these parameters, add that as a startup proc and optionally make the docs look nice. ¡mira!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
session_startup.magik is typically found in image modules. To get the help straight you can create a message for your option:
You can see the message by passing
-help to your image.
When started from
sw_magik.exe the session kindly throws and terminates in case of a traceback.