[pytango] 402/483: Expose TangoClassName and TangoClassClass to API. When classes parameter in run() is a sequence, allow for the item to be a sequence of <TangoClass, TangoClassClass>[, tango class name] (before it could only be a subclass of PyTango.server.Device)

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:15:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit e540735629edf5f249e93a4d12b1ff580e917380
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Thu Aug 28 13:21:33 2014 +0000

    Expose TangoClassName and TangoClassClass to API.
    When classes parameter in run() is a sequence, allow for the item to
    be a sequence of <TangoClass, TangoClassClass>[, tango class name]
    (before it could only be a subclass of PyTango.server.Device)
    
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@26363 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 src/boost/python/server.py | 151 +++++++++++++++++++--------------------------
 1 file changed, 65 insertions(+), 86 deletions(-)

diff --git a/src/boost/python/server.py b/src/boost/python/server.py
index 1538e03..8c6149b 100644
--- a/src/boost/python/server.py
+++ b/src/boost/python/server.py
@@ -301,9 +301,12 @@ def init_tango_device_klass(tango_device_klass, attrs=None, tango_class_name=Non
     tango_deviceclass_klass = create_tango_deviceclass_klass(tango_device_klass,
                                                              attrs=attrs)
     if tango_class_name is None:
-        tango_klass_name = klass_name
-    tango_device_klass._DeviceClass = tango_deviceclass_klass
-    tango_device_klass._DeviceClassName = tango_klass_name
+        if hasattr(tango_device_klass, "TangoClassName"):
+            tango_class_name = tango_device_klass.TangoClassName
+        else:
+            tango_class_name = klass_name
+    tango_device_klass.TangoClassClass = tango_deviceclass_klass
+    tango_device_klass.TangoClassName = tango_class_name
     tango_device_klass._api = API_VERSION
     return tango_device_klass
 
@@ -699,21 +702,30 @@ def __server_run(classes, args=None, msg_stream=sys.stdout, util=None,
 
     if is_seq(classes):
         for klass_info in classes:
-            if not hasattr(klass_info, '_api') or klass_info._api < 2:
-                raise Exception("When giving a single class, it must implement HLAPI (see PyTango.server)")
-            klass_klass = klass_info._DeviceClass
-            klass_name = klass_info._DeviceClassName
-            klass = klass_info
+            if is_seq(klass_info):
+                if len(klass_info) == 2:
+                    klass_klass, klass = klass_info
+                else:
+                    klass_klass, klass, klass_name = klass_info                
+            else:
+                if not hasattr(klass_info, '_api') or klass_info._api < 2:
+                    raise Exception("When giving a single class, it must implement HLAPI (see PyTango.server)")
+                klass_klass = klass_info.TangoClassClass
+                klass_name = klass_info.TangoClassName
+                klass = klass_info
             util.add_class(klass_klass, klass, klass_name)
     else:
         for klass_name, klass_info in classes.items():
-            if is_seq(klass_info):
-                klass_klass, klass = klass_info
+            if is_seq(klass_info)
+                if len(klass_info) == 2:
+                    klass_klass, klass = klass_info
+                else:
+                    klass_klass, klass, klass_name = klass_info
             else:
                 if not hasattr(klass_info, '_api') or klass_info._api < 2:
                     raise Exception("When giving a single class, it must implement HLAPI (see PyTango.server)")
-                klass_klass = klass_info._DeviceClass
-                klass_name = klass_info._DeviceClassName
+                klass_klass = klass_info.TangoClassClass
+                klass_name = klass_info.TangoClassName
                 klass = klass_info
             util.add_class(klass_klass, klass, klass_name)
 
@@ -734,18 +746,31 @@ def run(classes, args=None, msg_stream=sys.stdout,
     Provides a simple way to run a tango server. It handles exceptions
     by writting a message to the msg_stream.
 
-    The `classes` parameter can be either a sequence of :class:`~PyTango.server.Device`
-    classes or a dictionary where:
+    The `classes` parameter can be either a sequence of:
+
+    * :class:`~PyTango.server.Device` or
+    * a sequence of two elements :class:`~PyTango.DeviceClass` , :class:`~PyTango.DeviceImpl` or
+    * a sequence of three elements :class:`~PyTango.DeviceClass` , :class:`~PyTango.DeviceImpl`, tango class name (str)
+    
+    or a dictionary where:
 
     * key is the tango class name
     * value is either:
         * a :class:`~PyTango.server.Device` class or
-        * a sequence of two elements :class:`~PyTango.DeviceClass` , :class:`~PyTango.DeviceImpl`
+        * a sequence of two elements :class:`~PyTango.DeviceClass` , :class:`~PyTango.DeviceImpl` or
+        * a sequence of three elements :class:`~PyTango.DeviceClass` , :class:`~PyTango.DeviceImpl`, tango class name (str)        
 
     The optional `post_init_callback` can be a callable (without arguments)
     or a tuple where the first element is the callable, the second is a list
     of arguments(optional) and the third is a dictionary of keyword arguments
     (also optional).
+
+    .. note::
+       the order of registration of tango classes defines the order
+       tango uses to initialize the corresponding devices.
+       if using a dictionary as argument for classes be aware that the
+       order of registration becomes arbitrary. If you need a predefined
+       order use a sequence or an OrderedDict.
            
     Example 1: registering and running a PowerSupply inheriting from :class:`~PyTango.server.Device`::
        
@@ -759,16 +784,34 @@ def run(classes, args=None, msg_stream=sys.stdout,
     Example 2: registering and running a MyServer defined by tango classes 
     `MyServerClass` and `MyServer`::
        
-        import PyTango
+        from PyTango import Device_4Impl, DeviceClass
         from PyTango.server import run
     
-        class MyServer(PyTango.Device_4Impl):
+        class MyServer(Device_4Impl):
             pass
                
-        class MyServerClass(PyTango.DeviceClass):
+        class MyServerClass(DeviceClass):
             pass
        
-        run({"MyServer": (MyServerClass, MyServer)})
+        run({'MyServer': (MyServerClass, MyServer)})
+
+    Example 3: registering and running a MyServer defined by tango classes 
+    `MyServerClass` and `MyServer`::
+       
+        from PyTango import Device_4Impl, DeviceClass        
+        from PyTango.server import Device, DeviceMeta, run
+       
+        class PowerSupply(Device):
+            __metaclass__ = DeviceMeta
+               
+        class MyServer(Device_4Impl):
+            pass
+               
+        class MyServerClass(DeviceClass):
+            pass
+
+        run([PowerSupply, [MyServerClass, MyServer]])
+        # or: run({'MyServer': (MyServerClass, MyServer)})
        
     :param classes:
         a sequence of :class:`~PyTango.server.Device` classes or
@@ -800,6 +843,9 @@ def run(classes, args=None, msg_stream=sys.stdout,
        
     .. versionadded:: 8.1.2
 
+    .. versionchanged:: 8.1.4
+        when classes argument is a sequence, the items can also be
+        a sequence of <TangoClass, TangoClassClass>[, tango class name]
     """
     if msg_stream is None:
         write = lambda msg : None
@@ -827,73 +873,6 @@ def server_run(classes, args=None, msg_stream=sys.stdout,
     """
     Since PyTango 8.1.2 it is just an alias to
     :func:`~PyTango.server.run`. Use :func:`~PyTango.server.run` instead.
-
-    Provides a simple way to run a tango server. It handles exceptions
-    by writting a message to the msg_stream.
-
-    The `classes` parameter can be either a sequence of :class:`~PyTango.server.Device`
-    classes or a dictionary where:
-
-    * key is the tango class name
-    * value is either:
-        * a :class:`~PyTango.server.Device` class or
-        * a sequence of two elements :class:`~PyTango.DeviceClass` , :class:`~PyTango.DeviceImpl`
-
-    The optional `post_init_callback` can be a callable (without arguments)
-    or a tuple where the first element is the callable, the second is a list
-    of arguments(optional) and the third is a dictionary of keyword arguments
-    (also optional).
-           
-    Example 1: registering and running a PowerSupply inheriting from :class:`~PyTango.server.Device`::
-       
-        from PyTango.server import Device, DeviceMeta, run
-       
-        class PowerSupply(Device):
-            __metaclass__ = DeviceMeta
-               
-        run((PowerSupply,))
-           
-    Example 2: registering and running a MyServer defined by tango classes 
-    `MyServerClass` and `MyServer`::
-       
-        import PyTango
-        from PyTango.server import run
-    
-        class MyServer(PyTango.Device_4Impl):
-            pass
-               
-        class MyServerClass(PyTango.DeviceClass):
-            pass
-       
-        run({"MyServer": (MyServerClass, MyServer)})
-       
-    :param classes:
-        a sequence of :class:`~PyTango.server.Device` classes or
-        a dictionary where keyword is the tango class name and value is a 
-        sequence of Tango Device Class python class, and Tango Device python class
-    :type classes: sequence or dict
-       
-    :param args:
-        list of command line arguments [default: None, meaning use sys.argv]
-    :type args: list
-       
-    :param msg_stream:
-        stream where to put messages [default: sys.stdout]
-       
-    :param util:
-        PyTango Util object [default: None meaning create a Util instance]
-    :type util: :class:`~PyTango.Util`
-
-    :param event_loop: event_loop callable
-    :type event_loop: callable
-       
-    :param post_init_callback:
-        an optional callback that is executed between the calls Util.server_init
-        and Util.server_run
-    :type post_init_callback: callable or tuple (see description above)
-
-    :return: The Util singleton object
-    :rtype: :class:`~PyTango.Util`
        
     .. versionadded:: 8.0.0
        

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list