From 08668bd968dacd9cf6f5219268ec5819eb4704bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Bigaret?=
 <sebastien.bigaret@telecom-bretagne.eu>
Date: Tue, 2 Nov 2010 11:14:25 +0100
Subject: [PATCH] 1st version of Praxis w/ a generic service allowing to
 execute any script.

A new type has been added for parameters'descriptions: TEXT.  It is
equivalent to STRING, with the only difference that it is displayed
using a text area in the dialog dedicated to programs' parameters,
instead of a simple text field.

A new service 'generic' has been added to project 'test' to
demonstrate the feature.
---
 data/dtd/program_description.dtd              |  2 +-
 .../configuration/platform/platform_test.brs  |  1 +
 projects/test/configuration/run_cfg/types.cfg |  3 +-
 .../server/resources.clientTree.xml           |  1 +
 .../descriptions/test___generic___1.0.xml     | 84 +++++++++++++++++++
 .../core/resource/ParameterDescription.java   |  3 +-
 .../praxis/core/workflow/Parameter.java       |  4 +-
 .../praxis/core/workflow/Program.java         |  3 +-
 .../execution/SimpleFormatterPlatform.java    |  2 +
 9 files changed, 97 insertions(+), 6 deletions(-)
 create mode 100644 projects/test/descriptions/test___generic___1.0.xml

diff --git a/data/dtd/program_description.dtd b/data/dtd/program_description.dtd
index 92ed1819..bd0050b2 100644
--- a/data/dtd/program_description.dtd
+++ b/data/dtd/program_description.dtd
@@ -35,7 +35,7 @@
 	ismandatory %boolean; #IMPLIED
 	ishidden %boolean; #IMPLIED
 	isexpert %boolean; #IMPLIED
-	type (command | code | input | output | input-directory | output-directory | int | float | string | boolean | enum | List ) #REQUIRED
+	type (command | code | input | output | input-directory | output-directory | int | float | string | text | boolean | enum | List ) #REQUIRED
 	create-directory %boolean;  #IMPLIED
 >
 
diff --git a/projects/test/configuration/platform/platform_test.brs b/projects/test/configuration/platform/platform_test.brs
index d3c7220b..58c7ed1c 100644
--- a/projects/test/configuration/platform/platform_test.brs
+++ b/projects/test/configuration/platform/platform_test.brs
@@ -7,5 +7,6 @@
                 <program id="test___cat_input_with_vdef___1.0"/>
                 <program id="test___sleep___1.0"/>
                 <program id="test___failure___1.0"/>
+                <program id="test___generic___1.0"/>
 	</programs>
 </platform>
diff --git a/projects/test/configuration/run_cfg/types.cfg b/projects/test/configuration/run_cfg/types.cfg
index ea998152..7571b94c 100644
--- a/projects/test/configuration/run_cfg/types.cfg
+++ b/projects/test/configuration/run_cfg/types.cfg
@@ -1,7 +1,6 @@
 application.id=test
-ALL=YELLOW
+ALL=BLACK
 OTHER=WHITE
-BANK=WHITE
 FILE=GREEN
 # Universal types can be connected to any type
 universal_types=ALL
diff --git a/projects/test/configuration/server/resources.clientTree.xml b/projects/test/configuration/server/resources.clientTree.xml
index 58c9590b..31c86b17 100644
--- a/projects/test/configuration/server/resources.clientTree.xml
+++ b/projects/test/configuration/server/resources.clientTree.xml
@@ -23,5 +23,6 @@
 		<resource name="test___cat_input_with_vdef___1.0" />
 		<resource name="test___sleep___1.0" />
 		<resource name="test___failure___1.0" />
+		<resource name="test___generic___1.0" />
 	</type>
 </resourcesTree>
diff --git a/projects/test/descriptions/test___generic___1.0.xml b/projects/test/descriptions/test___generic___1.0.xml
new file mode 100644
index 00000000..e16c2bc7
--- /dev/null
+++ b/projects/test/descriptions/test___generic___1.0.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE program_description PUBLIC "-//Telecom Bretagne/DTD XML Praxis Program Description 3.0//EN" "http://perso.telecom-bretagne.eu/~bigaret/praxis/dtd/program_description.dtd">
+
+<program_description export_date="2009-08-15 18:30" modification_date="2009-08-15 18:30">
+  <program provider="test" name="generic" version="1.0" />
+  <from desc_id="S9999" />
+  <description>A generic box allowing to execute commands and custom scripts
+  - The input file is named 'infile'.
+  - An output file should be written, named 'outfile'.
+  - The script, if used, will be written in a file named 'script' before the command-line is executed.
+  
+Example: a program reading the infile in python and numbering the lines
+  
+cmdline: 'python script infile outfile' (without the quotes)
+Use a script: Yes
+Script (until "# end"):
+import sys
+print "argv: ", sys.argv
+# here, sys.argv[0] is 'script'
+input=sys.argv[1]
+output=sys.argv[2]
+
+idx=0
+output=open(output, 'w')
+for line in open(input):
+  output.write("%i: %s"%(idx, line))
+  idx += 1
+
+output.close()
+# end
+
+Remarks:
+- the cmdline launches python on the script file:
+- the script reads its arguments from the command-line; another solution would be to hard-code the name "infile" and "outfile" in the script itself.
+</description>
+  <parameters>
+    <parameter id="generic_cmd" type="string">
+      <name>cmdline</name>
+      <description>Command-line</description>
+      <position>1</position>
+      <code>%s</code>
+      <vdef />
+    </parameter>
+    <parameter id="infile" ishidden="0" type="input">
+      <name>infile </name>
+      <description>Input data file</description>
+      <position>200</position>
+      <code />
+      <types>
+        <type>all</type>
+      </types>
+      <vdef>infile</vdef>
+    </parameter>
+    <parameter id="outfile" ishidden="0" type="output">
+      <name>outfile</name>
+      <description>Output data file</description>
+      <position>300</position>
+      <code />
+      <types>
+        <type>all</type>
+      </types>
+      <vdef>outfile</vdef>
+    </parameter>
+    <parameter id="provide_script" ishidden="0" type="boolean">
+      <name>Use a script? </name>
+      <indent>0</indent>
+      <description> Produce second output? </description>
+      <position>0</position>
+      <code />
+      <vdef>0</vdef>
+      <dep/>
+    </parameter>
+    <parameter id="script" ishidden="0" type="text">
+      <name>Script (put in file named: 'script')</name>
+      <indent>0</indent>
+      <description>The script to execute</description>
+      <position>0</position>
+      <code><![CDATA[cat >script<<EOF%n%s%nEOF%n]]></code>
+      <vdef></vdef>
+      <dep>(provide_script:value="1")</dep>
+    </parameter>
+  </parameters>
+</program_description>
+
diff --git a/src/eu/telecom_bretagne/praxis/core/resource/ParameterDescription.java b/src/eu/telecom_bretagne/praxis/core/resource/ParameterDescription.java
index 580dd71b..196f3a56 100644
--- a/src/eu/telecom_bretagne/praxis/core/resource/ParameterDescription.java
+++ b/src/eu/telecom_bretagne/praxis/core/resource/ParameterDescription.java
@@ -39,7 +39,7 @@ public class ParameterDescription implements Serializable
 
 	public enum ParameterType
 	{
-		COMMAND, CODE, INPUT, INPUT_DIRECTORY, OUTPUT, OUTPUT_DIRECTORY, ENUM, BOOLEAN, INT, FLOAT, STRING;
+		COMMAND, CODE, INPUT, INPUT_DIRECTORY, OUTPUT, OUTPUT_DIRECTORY, ENUM, BOOLEAN, INT, FLOAT, STRING, TEXT;
 
 		/**
 		 * Tells whether the type denotes an input parameter.
@@ -751,6 +751,7 @@ public class ParameterDescription implements Serializable
 			case OUTPUT:
 			case OUTPUT_DIRECTORY:
 			case STRING:
+			case TEXT:
 				default:
 				return data;
     	}
diff --git a/src/eu/telecom_bretagne/praxis/core/workflow/Parameter.java b/src/eu/telecom_bretagne/praxis/core/workflow/Parameter.java
index 6010c48e..c4f13632 100644
--- a/src/eu/telecom_bretagne/praxis/core/workflow/Parameter.java
+++ b/src/eu/telecom_bretagne/praxis/core/workflow/Parameter.java
@@ -58,7 +58,7 @@ public class Parameter implements Cloneable, PropertyChangeListener
 	protected Program program;
 	
 	/** Value for the parameter, only for {@link ParameterType#INT},
-	 * {@link ParameterType#FLOAT}, {@link ParameterType#STRING},
+	 * {@link ParameterType#FLOAT}, {@link ParameterType#STRING}, {@link ParameterType#TEXT},
 	 * and {@link ParameterType#BOOLEAN} parameters */
 	String data = null;
 	
@@ -120,6 +120,7 @@ public class Parameter implements Cloneable, PropertyChangeListener
 			case FLOAT:
 			case INT:
 			case STRING:
+			case TEXT:
 				data = xml.getChildText("data");
 				// TODO: check FLOAT, INT, peut-ĂȘtre pour tout le monde d'ailleurs (boolean, etc.)
 				break;
@@ -181,6 +182,7 @@ public class Parameter implements Cloneable, PropertyChangeListener
 				data = description.getVdef().equals("")?"0":description.getVdef();
 				break;
 			case STRING:
+			case TEXT:
 				data = description.getVdef();
 				break;
 			case ENUM:
diff --git a/src/eu/telecom_bretagne/praxis/core/workflow/Program.java b/src/eu/telecom_bretagne/praxis/core/workflow/Program.java
index 8f1bd6a7..87a9f209 100644
--- a/src/eu/telecom_bretagne/praxis/core/workflow/Program.java
+++ b/src/eu/telecom_bretagne/praxis/core/workflow/Program.java
@@ -587,7 +587,8 @@ public class Program
 				param.setItem(copied_param.getItem());
 			
 			if (parameterType.equals(ParameterType.INT) || parameterType.equals(ParameterType.FLOAT)
-			    || parameterType.equals(ParameterType.STRING) || parameterType.equals(ParameterType.BOOLEAN))
+			    || parameterType.equals(ParameterType.STRING) || parameterType.equals(ParameterType.TEXT)
+			    || parameterType.equals(ParameterType.BOOLEAN))
 			{
 				param.setData(copied_param.getData());
 			}
diff --git a/src/eu/telecom_bretagne/praxis/server/execution/SimpleFormatterPlatform.java b/src/eu/telecom_bretagne/praxis/server/execution/SimpleFormatterPlatform.java
index 1c843ff0..1afee662 100644
--- a/src/eu/telecom_bretagne/praxis/server/execution/SimpleFormatterPlatform.java
+++ b/src/eu/telecom_bretagne/praxis/server/execution/SimpleFormatterPlatform.java
@@ -435,6 +435,7 @@ public abstract class SimpleFormatterPlatform
 			case INT:
 			case FLOAT:
 			case STRING:
+			case TEXT:
 				return getCode_IntFloatString(parameter);
 			case OUTPUT:
 			case OUTPUT_DIRECTORY:
@@ -521,6 +522,7 @@ public abstract class SimpleFormatterPlatform
 	{
 		assert ((param.getDescription().getType().equals(ParameterType.INT))
 		        || (param.getDescription().getType().equals(ParameterType.STRING))
+		        || (param.getDescription().getType().equals(ParameterType.TEXT))
 		        || (param.getDescription().getType().equals(ParameterType.FLOAT)));
 		return String.format(param.getDescription().getValueTemplate(), param.getData(), param.getData());
 	}
-- 
GitLab