.. _integrating:
Integrating the plug-in into Hydra Modeller
===========================================
Turning an app into a hydra modeller plugin requires creating an exe
of your code (see :ref:`creating_an_exe`), putting it into a pre-defined
folder structure (:see: `folder_structure`) along with a plugin xml.
.. _plugin_xml:
Plugin XML
----------
Hydra Modeller uses a plugin XML file to describe the required inputs to the
plugin as well as the icon it will use when displaying the button in the user
interface.
The main information in the XML file is as follows:
- The plugin name
- The plugin location (the location of the exe)
- The plugin description
- The epilog
- Icons (large (32x32px) and small (16x16 px))
- Mandatory arguments
- Non-Mandatory arguments
- Switches
For each argument, there are the following details. They should be familiar from
the arguments we defined in the plugin:
- The name that will be displayed in the UI (human readable)
- The switch (in our plugin, these would be '-n' and '-s')
- The argtype (string, integer etc. There are a few wildcards such as 'network', 'scenario' and 'template' which allow the UI to provide a drop-down rather than asking the
user to remember the ID of the network they are working on!
- The help is a string of text that is displayed when the user clicks on the argument in the UI
The Export JSON file is below in full. Notice that there is 1 switch defined.
This is here purely to show what a switch would look like and does not have
any reference to the code we have looked at until now.
.. code-block:: xml
Export JSON
ExportCSV.exe
Export a network saved in Hydra to a JSON file.
Written by Stephen Knox stephen.knox@manchester.ac.uk
(c) Copyright 20135, University of Manchester.
For more information visit www.hydra-network.com
icon16.png
icon32.png
Network ID
-n
N
network
The ID of the network to be exported
Scenario ID
-s
N
scenario
The ID of the scenario to be exported. If no
scenario is specified, all scenarios in the network will be
exported.
Target Dir
-d
N
string
The directory / folder you wish the file to export to. This defaults
to the Desktop.
Server URL
-u
N
string
The URL of the server to which this
plug-in connects.
Session ID
-c
N
string
The session ID for the connection. If not specified,
the plugin will try to connect based on the credentials it finds in config
Export as XML
-x
Export as an XML file instead of a JSON file.
All arguments are defined inside an `` tag, and must define
a `` That will be shown in the UI, `` (-n for network, for example),
`` which defines whether multiple of this argument can be provided,
`` which if set to 'Y' allows the user in the UI create a new network
`` which states the type of the argument, be it a date, string, integer
or even network or scenario. The latter options create a drop-down in the UI.
The `` tag allows users of the UI to see exactly what the argument is for.
An example of a full `` tag might be:
.. code-block:: xml
nodes
-n
Y
file
One or multiple files containing nodes and
attributes.
There are 3 types of category these args can be put into within the plugin xml. *mandatory*, *non-mandatory* and *switches*.
Mandatory inputs are must be included or the plugin will not even start. Normally
this will be a network ID, session ID, URL and any other necessary inputs.
Non-Mandatory inputs may be provided to the plugin to provide extra functionality, but
the plugin will still run without them. One example for an export plugin might
be to define a specific directory for export: 'export_dir=/tmp/'.
Switches arguments which do not require an input, but are simply 'on/off'. They
appear as check boxes in the UI.
Plugin XML example:
^^^^^^^^^^^^^^^^^^^
Click :download:`here ` for the plugin xsd file
Click :download:`here ` for a full example of the plugin xml
.. _folder_structure:
Folder Structure
----------------
There are 2 structures supported by Hydra Modeller.
If there is only one executable in the plugin, the the following structure
should be used::
MyPlugin
--> templates (optional)
--> template.xml
--> ExportJSON
--> ExportJSON.exe
--> plugin.xml
--> icon.png
or alternatively, if the plugin package contains more than 1 executable (import
and export, for example)::
MyPlugin
--> templates (optional)
--> template.xml
--> plugins
--> ExportJSON
--> ExportJSON.exe
--> plugin.xml
--> icon32.png
--> icon16.png
--> ImportJSON
--> ImportJSON.exe
--> plugin.xml
--> icon32.png
--> icon16.png
.. _session_and_url:
Session ID and Server URL
-------------------------
As Hydra apps connect to Hydra Platform via the same interface as the UI, they need to us the same credentials as the UI. To this end, all plugins should implement
two arguments, namely server_url (to tell the plugin where the server is) and session_id
to tell the server who is making the call. These two arguments should appear
in the non_mandatory_args section of the plugin.xml and look just like this:
.. code-block:: xml
server_url
-u
N
string
Specify the URL of the server to which this
plug-in connects.
session_id
-c
N
string
Specify the session ID for the connection. If not specified,
the plugin will try to connect based on the credentials it finds in config
.. _creating_an_exe:
Creating an executable of your code
-----------------------------------
.. _pyinstaller: https://github.com/pyinstaller/pyinstaller/wiki
Hydra Modeller is windows-based and so requires all its plugins to be executable
in windows. *This still means that plugins can be written in cross-platform languages
like python, java or ruby.*. Taking python as an example, the pyinstaller_ package
allows a python script to be turned into an exe by simply typing::
pyinstaller mypluginscript.py
Which produces a file called mypluginscript.exe
For more control, you can define a '.spec' file, which allows you to decide
what level of compression you want (more compression = less performance normally),
the name of the output file, whether it's a console application or not etc...