From c07dfdc4e43b86ef4782d9bd078c7d15061aaa9d Mon Sep 17 00:00:00 2001
From: Marcelo Vogel <mavogel@cern.ch>
Date: Tue, 27 Feb 2018 08:33:16 +0100
Subject: [PATCH] Add string substep argument

Former-commit-id: cbf41cd4d5e686e1254c566e1f9d2448d4ca0605
---
 Tools/PyJobTransforms/python/trfArgClasses.py | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/Tools/PyJobTransforms/python/trfArgClasses.py b/Tools/PyJobTransforms/python/trfArgClasses.py
index a3f961044c2..7ab4b9a53e9 100644
--- a/Tools/PyJobTransforms/python/trfArgClasses.py
+++ b/Tools/PyJobTransforms/python/trfArgClasses.py
@@ -1891,6 +1891,49 @@ class argSubstepList(argSubstep):
             subStepList = [(s[0], [s[1]]) for s in subStepList]
         return subStepList
 
+## @brief String substep argument
+class argSubstepString(argSubstep):
+
+    # Reset getter
+    @property
+    def value(self):
+        return self._value
+
+    @property
+    def prodsysDescription(self):
+        desc = {'type': 'substep', 'substeptype': 'str', 'separator': self._separator,
+                'default': self._defaultSubstep}
+        return desc
+
+    @value.setter
+    def value(self, value):
+        msg.debug('Attempting to set argSubstep from {0!s} (type {1}'.format(value, type(value)))
+        if value is None:
+            self._value = {}
+        elif isinstance(value, str):
+            self._value = {self._defaultSubstep: value}
+        elif isinstance(value, str):
+            subStepList = self._parseStringAsSubstep(value)
+            self._value = dict([(subStep[0], strToBool(subStep[1])) for subStep in subStepList])
+        elif isinstance(value, (list, tuple)):
+            # This is a list of strings to parse
+            self._value = {}
+            for item in value:
+                if not isinstance(item, str):
+                    raise trfExceptions.TransformArgException(trfExit.nameToCode('TRF_ARG_CONV_FAIL'), 'Failed to convert list item {0!s} to substep (should be a string)'.format(item))
+                subStepList = self._parseStringAsSubstep(item)
+                for subStep in subStepList:
+                    self._value[subStep[0]] = strToBool(subStep[1])
+        elif isinstance(value, dict):
+            for k, v in value.iteritems():
+                if not isinstance(k, str):
+                    raise trfExceptions.TransformArgException(trfExit.nameToCode('TRF_ARG_CONV_FAIL'), 'Dictionary key {0!s} for substep is not a string'.format(k))
+                if not isinstance(v, bool):
+                    raise trfExceptions.TransformArgException(trfExit.nameToCode('TRF_ARG_CONV_FAIL'), 'Dictionary value {0!s} for substep is not a bool'.format(v))
+            self._value = value
+        else:
+            raise trfExceptions.TransformArgException(trfExit.nameToCode('TRF_ARG_CONV_FAIL'), 'Setter value {0!s} (type {1}) for substep argument cannot be parsed'.format(value, type(value)))
+
 ## @brief Boolean substep argument
 class argSubstepBool(argSubstep):
     
-- 
GitLab