Commits

Ginés Martínez Sánchez committed 04c56f4 Draft

created add_gconfig(), to chain gconfigs

Comments (0)

Files changed (2)

ginsfsm/gconfig.py

     """ Raised when something is a parameter is not validated."""
 
 
+def add_gconfig(gconfig, new_gconfig):
+    """ Add to gconfing a new_gconfig """
+    if new_gconfig is None:
+        return gconfig
+
+    if gconfig is not None:
+        if isinstance(gconfig, (list, tuple)):
+            gconfig = list(gconfig)
+            gconfig.append(new_gconfig)
+        else:
+            gconfig = [gconfig, new_gconfig]
+    else:
+        gconfig = [new_gconfig]
+    return gconfig
+
+
 class GConfig(object):
     """Global configuration system.
 
     EventNotAcceptedError,  # made it import available
     StateError,  # made it import available
     MachineError,  # made it import available
-    )
+)
 
-from ginsfsm.gconfig import GConfig
+from ginsfsm.gconfig import (
+    GConfig,
+    add_gconfig,
+)
 
 
 class ParentError(Exception):
         self._dl_subscriptions = set()      # uauuu, how many fans!!
         self._some_subscriptions = False
 
-        if gconfig is not None:
-            if isinstance(gconfig, (list, tuple)):
-                gconfig = list(gconfig)
-                gconfig.append(GOBJ_GCONFIG)
-            else:
-                gconfig = [gconfig, GOBJ_GCONFIG]
-        else:
-            gconfig = [GOBJ_GCONFIG]
+        gconfig = add_gconfig(gconfig, GOBJ_GCONFIG)
         GConfig.__init__(self, gconfig)
 
     def __str__(self):