[pytango] 306/483: final preparations for 8.1.1

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:53 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 c05f45b5b60f5881f673d108262c0e7f5b71203f
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Tue Nov 19 08:31:45 2013 +0000

    final preparations for 8.1.1
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@24256 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 src/boost/cpp/constants.cpp                   |   7 +-
 src/boost/python/__init__.py                  |   3 +-
 src/boost/python/attribute_proxy.py           |   2 +-
 src/boost/python/client.py                    |  18 +++
 src/boost/python/connection.py                |   2 +-
 src/boost/python/device_proxy.py              |   2 +-
 src/boost/python/futures.py                   |   3 +
 src/boost/python/gevent.py                    |   3 +
 src/boost/python/{tango_green.py => green.py} |   0
 src/boost/python/{hlapi.py => server.py}      | 184 ++++++++++++++++++++++++--
 src/boost/python/utils.py                     | 165 +++++------------------
 11 files changed, 235 insertions(+), 154 deletions(-)

diff --git a/src/boost/cpp/constants.cpp b/src/boost/cpp/constants.cpp
index f5c64de..8170acb 100644
--- a/src/boost/cpp/constants.cpp
+++ b/src/boost/cpp/constants.cpp
@@ -28,17 +28,12 @@ void export_constants()
 
 #ifdef DISABLE_PYTANGO_NUMPY
     consts_scope.attr("NUMPY_SUPPORT") = false;
+    consts_scope.attr("NUMPY_VERSION") = "0.0.0";
 #else
     consts_scope.attr("NUMPY_SUPPORT") = true;
-#endif
-
-#ifdef PYTANGO_NUMPY_VERSION
     consts_scope.attr("NUMPY_VERSION") = NPY_VERSION;
-#else
-    consts_scope.attr("NUMPY_VERSION") = "0.0.0";
 #endif
 
-
     consts_scope.attr("PY_MAJOR_VERSION") = PY_MAJOR_VERSION;
     consts_scope.attr("PY_MINOR_VERSION") = PY_MINOR_VERSION;
     consts_scope.attr("PY_MICRO_VERSION") = PY_MICRO_VERSION;
diff --git a/src/boost/python/__init__.py b/src/boost/python/__init__.py
index 01a8088..38a9163 100644
--- a/src/boost/python/__init__.py
+++ b/src/boost/python/__init__.py
@@ -173,8 +173,7 @@ from .globals import get_class, get_classes, get_cpp_class, get_cpp_classes, \
     delete_class_list, class_list, cpp_class_list, constructed_class
 from .utils import is_scalar_type, is_array_type, is_numerical_type, \
     is_int_type, is_float_type, obj_2_str, seqStr_2_obj
-from .utils import server_run
-from .tango_green import set_green_mode, get_green_mode
+from .green import set_green_mode, get_green_mode
 from .device_proxy import get_device_proxy
 from .tango_numpy import NumpyType, numpy_type, numpy_spectrum, numpy_image
 
diff --git a/src/boost/python/attribute_proxy.py b/src/boost/python/attribute_proxy.py
index f3d568e..f8461f9 100644
--- a/src/boost/python/attribute_proxy.py
+++ b/src/boost/python/attribute_proxy.py
@@ -27,7 +27,7 @@ from ._PyTango import StdStringVector, DbData, DbDatum, DeviceProxy
 from ._PyTango import __AttributeProxy as _AttributeProxy
 from .utils import seq_2_StdStringVector, seq_2_DbData, DbData_2_dict
 from .utils import is_pure_str, is_non_str_seq
-from .tango_green import result, submit, get_green_mode
+from .green import result, submit, get_green_mode
 
 
 def get_attribute_proxy(*args, **kwargs):
diff --git a/src/boost/python/client.py b/src/boost/python/client.py
new file mode 100644
index 0000000..de55252
--- /dev/null
+++ b/src/boost/python/client.py
@@ -0,0 +1,18 @@
+# ------------------------------------------------------------------------------
+# This file is part of PyTango (http://www.tinyurl.com/PyTango)
+#
+# Copyright 2006-2012 CELLS / ALBA Synchrotron, Bellaterra, Spain
+# Copyright 2013-2014 European Synchrotron Radiation Facility, Grenoble, France
+#
+# Distributed under the terms of the GNU Lesser General Public License,
+# either version 3 of the License, or (at your option) any later version.
+# See LICENSE.txt for more info.
+# ------------------------------------------------------------------------------
+
+"""High Level API for writting Tango clients"""
+
+from PyTango import DeviceProxy as Device
+from PyTango import AttributeProxy as Attribute
+from PyTango import Database
+from PyTango import Group
+from PyTango import DeviceAttribute
diff --git a/src/boost/python/connection.py b/src/boost/python/connection.py
index 6fef3ea..a576e3f 100644
--- a/src/boost/python/connection.py
+++ b/src/boost/python/connection.py
@@ -24,7 +24,7 @@ from ._PyTango import Connection, DeviceData, __CallBackAutoDie, CmdArgType, \
     DeviceProxy, Database, ExtractAs
 from .utils import document_method as __document_method
 from .utils import document_static_method as __document_static_method
-from .tango_green import green
+from .green import green
 
 
 def __CallBackAutoDie__cmd_ended_aux(self, fn):
diff --git a/src/boost/python/device_proxy.py b/src/boost/python/device_proxy.py
index 298112e..19223f8 100644
--- a/src/boost/python/device_proxy.py
+++ b/src/boost/python/device_proxy.py
@@ -31,7 +31,7 @@ from .utils import is_pure_str, is_non_str_seq, is_integer
 from .utils import seq_2_StdStringVector, StdStringVector_2_seq
 from .utils import seq_2_DbData, DbData_2_dict
 from .utils import document_method as __document_method
-from .tango_green import result, submit, green, get_green_mode
+from .green import result, submit, green, get_green_mode
 
 
 def get_device_proxy(*args, **kwargs):
diff --git a/src/boost/python/futures.py b/src/boost/python/futures.py
index 0b802b8..ad98474 100644
--- a/src/boost/python/futures.py
+++ b/src/boost/python/futures.py
@@ -101,6 +101,9 @@ AttributeProxy.__doc__ = """
     New in PyTango 8.1.0
 """
 
+Device = DeviceProxy
+Attribute = AttributeProxy
+
 del GreenMode
 del get_device_proxy
 del get_attribute_proxy
diff --git a/src/boost/python/gevent.py b/src/boost/python/gevent.py
index 3d5c0fd..b556318 100644
--- a/src/boost/python/gevent.py
+++ b/src/boost/python/gevent.py
@@ -101,6 +101,9 @@ AttributeProxy.__doc__ = """
     New in PyTango 8.1.0
 """
 
+Device = DeviceProxy
+Attribute = AttributeProxy
+
 del GreenMode
 del get_device_proxy
 del get_attribute_proxy
diff --git a/src/boost/python/tango_green.py b/src/boost/python/green.py
similarity index 100%
rename from src/boost/python/tango_green.py
rename to src/boost/python/green.py
diff --git a/src/boost/python/hlapi.py b/src/boost/python/server.py
similarity index 85%
rename from src/boost/python/hlapi.py
rename to src/boost/python/server.py
index 1fb02e9..508f331 100644
--- a/src/boost/python/hlapi.py
+++ b/src/boost/python/server.py
@@ -150,14 +150,17 @@ from __future__ import with_statement
 from __future__ import print_function
 
 __all__ = ["DeviceMeta", "Device", "LatestDeviceImpl", "attribute", "command",
-           "device_property", "class_property"]
+           "device_property", "class_property", "server_run"]
 
 import __builtin__
+import sys
 import inspect
 import functools
+import traceback
 
 from ._PyTango import DeviceImpl, Attribute, WAttribute, CmdArgType
 from ._PyTango import AttrDataFormat, AttrWriteType, DispLevel, constants
+from ._PyTango import DevFailed
 from .attr_data import AttrData
 from .device_class import DeviceClass
 from .utils import get_tango_device_classes, is_seq, is_non_str_seq
@@ -281,6 +284,7 @@ def set_complex_value(attr, value):
         else:
             attr.set_value(value)
 
+            
 def check_tango_device_klass_attribute_read_method(tango_device_klass, method_name):
     """Checks if method given by it's name for the given DeviceImpl class has
     the correct signature. If a read/write method doesn't have a parameter
@@ -301,6 +305,7 @@ def check_tango_device_klass_attribute_read_method(tango_device_klass, method_na
         return ret
     setattr(tango_device_klass, method_name, read_attr)
 
+    
 def check_tango_device_klass_attribute_write_method(tango_device_klass, method_name):
     """Checks if method given by it's name for the given DeviceImpl class has
     the correct signature. If a read/write method doesn't have a parameter
@@ -319,6 +324,7 @@ def check_tango_device_klass_attribute_write_method(tango_device_klass, method_n
         return write_method(self, value)
     setattr(tango_device_klass, method_name, write_attr)
 
+    
 def check_tango_device_klass_attribute_methods(tango_device_klass, attr_data):
     """Checks if the read and write methods have the correct signature. If a 
     read/write method doesn't have a parameter (the traditional Attribute),
@@ -332,11 +338,37 @@ def check_tango_device_klass_attribute_methods(tango_device_klass, attr_data):
         check_tango_device_klass_attribute_read_method(tango_device_klass, attr_data.read_method_name)
     if attr_data.attr_write in (AttrWriteType.WRITE, AttrWriteType.READ_WRITE):
         check_tango_device_klass_attribute_write_method(tango_device_klass, attr_data.write_method_name)
+
+
+class _DeviceClass(DeviceClass):
+
+    def __init__(self, name):
+        DeviceClass.__init__(self, name)
+        self.set_type(name)
+
+    def dyn_attr(self, dev_list):
+        """Invoked to create dynamic attributes for the given devices.
+        Default implementation calls
+        :meth:`TT.initialize_dynamic_attributes` for each device
+    
+        :param dev_list: list of devices
+        :type dev_list: :class:`PyTango.DeviceImpl`"""
+
+        for dev in dev_list:
+            init_dyn_attrs = getattr(dev, "initialize_dynamic_attributes", None)
+            if init_dyn_attrs and callable(init_dyn_attrs):
+                try:
+                    init_dyn_attrs()
+                except Exception:
+                    import traceback
+                    dev.warn_stream("Failed to initialize dynamic attributes")
+                    dev.debug_stream("Details: " + traceback.format_exc())
+    
         
 def create_tango_deviceclass_klass(tango_device_klass, attrs=None):
     klass_name = tango_device_klass.__name__
     if not issubclass(tango_device_klass, (Device)):
-        msg = "{0} device must inherit from PyTango.hlapi.Device".format(klass_name)
+        msg = "{0} device must inherit from PyTango.server.Device".format(klass_name)
         raise Exception(msg)
     
     if attrs is None:
@@ -360,18 +392,14 @@ def create_tango_deviceclass_klass(tango_device_klass, attrs=None):
             if hasattr(attr_obj, "__tango_command__"):
                 cmd_name, cmd_info = attr_obj.__tango_command__
                 cmd_list[cmd_name] = cmd_info
-            
-    devclass_name = klass_name + "Class"
     
-    def device_class_constructor(self, name):
-        DeviceClass.__init__(self, name)
-        self.set_type(name)
+    devclass_name = klass_name + "Class"
     
     devclass_attrs = dict(class_property_list=class_property_list,
                           device_property_list=device_property_list,
                           cmd_list=cmd_list, attr_list=attr_list)
-    devclass_attrs['__init__'] = device_class_constructor
-    return type(devclass_name, (DeviceClass,), devclass_attrs)
+    return type(devclass_name, (_DeviceClass,), devclass_attrs)
+
 
 def init_tango_device_klass(tango_device_klass, attrs=None, tango_class_name=None):
     klass_name = tango_device_klass.__name__
@@ -384,6 +412,7 @@ def init_tango_device_klass(tango_device_klass, attrs=None, tango_class_name=Non
     tango_device_klass._api = API_VERSION
     return tango_device_klass
 
+
 def create_tango_device_klass(name, bases, attrs):
     klass_name = name
 
@@ -391,7 +420,8 @@ def create_tango_device_klass(name, bases, attrs):
     klass = LatestDeviceImplMeta(klass_name, bases, attrs)
     init_tango_device_klass(klass, attrs)
     return klass
-    
+
+
 def DeviceMeta(name, bases, attrs):
     """The :py:data:`metaclass` callable for :class:`Device`. Every subclass of
     :class:`Device` must have associated this metaclass to itself in order to
@@ -399,14 +429,14 @@ def DeviceMeta(name, bases, attrs):
     
     Example (python 2.x)::
     
-        from PyTango.hlapi import Device, DeviceMeta
+        from PyTango.server import Device, DeviceMeta
 
         class PowerSupply(Device):
             __metaclass__ = DeviceMeta
 
     Example (python 3.x)::
     
-        from PyTango.hlapi import Device, DeviceMeta
+        from PyTango.server import Device, DeviceMeta
 
         class PowerSupply(Device, metaclass=DeviceMeta):
             pass
@@ -647,3 +677,133 @@ class device_property(_property):
 
 class class_property(_property):
     pass
+
+
+def __server_run(classes, args=None, msg_stream=sys.stdout, util=None,
+                 event_loop=None):
+    import PyTango
+    if msg_stream is None:
+        import io
+        msg_stream = io.BytesIO()
+
+    if args is None:
+        args = sys.argv
+
+    if util is None:
+        util = PyTango.Util(args)
+
+    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
+            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
+            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_info
+            util.add_class(klass_klass, klass, klass_name)
+    u_instance = PyTango.Util.instance()
+    if event_loop is not None:
+        u_instance.server_set_event_loop(event_loop)
+    u_instance.server_init()
+    msg_stream.write("Ready to accept request\n")
+    u_instance.server_run()
+    return util
+
+
+def server_run(classes, args=None, msg_stream=sys.stdout,
+               verbose=False, util=None, event_loop=None):
+    """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 a sequence of two elements :class:`~PyTango.DeviceClass`, :class:`~PyTango.DeviceImpl`
+           
+       Example 1: registering and running a PowerSupply inheriting from :class:`~PyTango.server.Device`::
+       
+           from PyTango import server_run
+           from PyTango.server import Device, DeviceMeta
+       
+           class PowerSupply(Device):
+               __metaclass__ = DeviceMeta
+               
+           server_run((PowerSupply,))
+           
+       Example 2: registering and running a MyServer defined by tango classes 
+       `MyServerClass` and `MyServer`::
+       
+           import PyTango
+
+           class MyServer(PyTango.Device_4Impl):
+               pass
+               
+           class MyServerClass(PyTango.DeviceClass):
+               pass
+       
+           PyTango.server_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
+       
+       :return: The Util singleton object
+       :rtype: :class:`~PyTango.Util`
+       
+       .. versionadded:: 8.0.0
+       
+       .. versionchanged:: 8.0.3
+           Added `util` keyword parameter.
+           Returns util object
+
+       .. versionchanged:: 8.1.1
+           Changed default msg_stream from *stderr* to *stdout*
+           Added `event_loop` keyword parameter.
+           Returns util object"""
+
+    if msg_stream is None:
+        import io
+        msg_stream = io.BytesIO()
+    write = msg_stream.write
+    try:
+        return __server_run(classes, args=args, util=util, event_loop=event_loop)
+    except KeyboardInterrupt:
+        write("Exiting: Keyboard interrupt\n")
+    except DevFailed as df:
+        write("Exiting: Server exited with PyTango.DevFailed:\n" + str(df) + "\n")
+        if verbose:
+            write(traceback.format_exc())
+    except Exception as e:
+        write("Exiting: Server exited with unforseen exception:\n" + str(e) + "\n")
+        if verbose:
+            write(traceback.format_exc())
+    write("\nExited\n")
diff --git a/src/boost/python/utils.py b/src/boost/python/utils.py
index b834e6d..ca72698 100644
--- a/src/boost/python/utils.py
+++ b/src/boost/python/utils.py
@@ -24,7 +24,6 @@ __all__ = [ "is_pure_str", "is_seq", "is_non_str_seq", "is_integer",
             "document_method", "document_static_method", "document_enum",
             "CaselessList", "CaselessDict", "EventCallBack", "get_home",
             "from_version_str_to_hex_str", "from_version_str_to_int",
-            "server_run",
             "seq_2_StdStringVector", "StdStringVector_2_seq" ]
 
 __docformat__ = "restructuredtext"
@@ -32,7 +31,6 @@ __docformat__ = "restructuredtext"
 import os
 import sys
 import numbers
-import traceback
 import collections
 
 from ._PyTango import StdStringVector, StdDoubleVector, \
@@ -92,6 +90,7 @@ _scalar_to_array_type = {
 
 __device_classes = None
 
+
 def get_tango_device_classes():
     global __device_classes
     if __device_classes is None:
@@ -139,21 +138,27 @@ __int_klasses = tuple(__int_klasses)
 __number_klasses = tuple(__number_klasses)
 __seq_klasses = tuple(__seq_klasses)
 
+
 def is_pure_str(obj):
     return isinstance(obj , __str_klasses)
 
+
 def is_seq(obj):
     return isinstance(obj, __seq_klasses)
 
+
 def is_non_str_seq(obj):
     return is_seq(obj) and not is_pure_str(obj)
 
+
 def is_integer(obj):
     return isinstance(obj, __int_klasses)
 
+
 def is_number(obj):
     return isinstance(obj, __number_klasses)
 
+
 def is_scalar(tg_type):
     """Tells if the given tango type is a scalar
     
@@ -183,6 +188,7 @@ def is_array(tg_type):
 
 is_array_type = is_array
 
+
 def is_numerical(tg_type, inc_array=False):
     """Tells if the given tango type is numerical
     
@@ -204,6 +210,7 @@ def is_numerical(tg_type, inc_array=False):
 
 is_numerical_type = is_numerical
 
+
 def is_int(tg_type, inc_array=False):
     """Tells if the given tango type is integer
     
@@ -225,6 +232,7 @@ def is_int(tg_type, inc_array=False):
 
 is_int_type = is_int
 
+
 def is_float(tg_type, inc_array=False):
     """Tells if the given tango type is float
     
@@ -246,6 +254,7 @@ def is_float(tg_type, inc_array=False):
 
 is_float_type = is_float
 
+
 def is_bool(tg_type, inc_array=False):
     """Tells if the given tango type is boolean
     
@@ -288,6 +297,7 @@ def is_str(tg_type, inc_array=False):
 
 is_str_type = is_str
 
+
 def is_bin(tg_type, inc_array=False):
     """Tells if the given tango type is binary
     
@@ -305,6 +315,7 @@ def is_bin(tg_type, inc_array=False):
 
 is_bin_type = is_bin
 
+
 def seq_2_StdStringVector(seq, vec=None):
     """Converts a python sequence<str> object to a :class:`PyTango.StdStringVector`
         
@@ -325,6 +336,7 @@ def seq_2_StdStringVector(seq, vec=None):
         vec.append(str(e))
     return vec
 
+
 def StdStringVector_2_seq(vec, seq=None):
     """Converts a :class:`PyTango.StdStringVector` to a python sequence<str>
         
@@ -342,6 +354,7 @@ def StdStringVector_2_seq(vec, seq=None):
         seq.append(str(e))
     return seq
 
+
 def seq_2_StdDoubleVector(seq, vec=None):
     """Converts a python sequence<float> object to a :class:`PyTango.StdDoubleVector`
         
@@ -362,6 +375,7 @@ def seq_2_StdDoubleVector(seq, vec=None):
         vec.append(str(e))
     return vec
 
+
 def StdDoubleVector_2_seq(vec, seq=None):
     """Converts a :class:`PyTango.StdDoubleVector` to a python sequence<float>
         
@@ -378,6 +392,7 @@ def StdDoubleVector_2_seq(vec, seq=None):
     for e in vec: seq.append(float(e))
     return seq
 
+
 def seq_2_DbDevInfos(seq, vec=None):
     """Converts a python sequence<DbDevInfo> object to a :class:`PyTango.DbDevInfos`
         
@@ -397,6 +412,7 @@ def seq_2_DbDevInfos(seq, vec=None):
     for e in seq: vec.append(e)
     return vec
 
+
 def seq_2_DbDevExportInfos(seq, vec=None):
     """Converts a python sequence<DbDevExportInfo> object to a :class:`PyTango.DbDevExportInfos`
         
@@ -416,6 +432,7 @@ def seq_2_DbDevExportInfos(seq, vec=None):
     for e in seq: vec.append(e)
     return vec
 
+
 def seq_2_DbData(seq, vec=None):
     """Converts a python sequence<DbDatum> object to a :class:`PyTango.DbData`
         
@@ -435,6 +452,7 @@ def seq_2_DbData(seq, vec=None):
     for e in seq: vec.append(e)
     return vec
 
+
 def DbData_2_dict(db_data, d=None):
     if d is None: d = {}
     if not isinstance(db_data, DbData):
@@ -443,6 +461,7 @@ def DbData_2_dict(db_data, d=None):
         d[db_datum.name] = db_datum.value_string
     return d
 
+
 def seqStr_2_obj(seq, tg_type, tg_format=None):
     """Translates a sequence<str> to a sequence of objects of give type and format
     
@@ -459,6 +478,7 @@ def seqStr_2_obj(seq, tg_type, tg_format=None):
         return _seqStr_2_obj_from_type_format(seq, tg_type, tg_format)
     return _seqStr_2_obj_from_type(seq, tg_type)
 
+
 def _seqStr_2_obj_from_type(seq, tg_type):
 
     if is_pure_str(seq):
@@ -506,6 +526,7 @@ def _seqStr_2_obj_from_type(seq, tg_type):
 
     return []
 
+
 def _seqStr_2_obj_from_type_format(seq, tg_type, tg_format):
     if tg_format == AttrDataFormat.SCALAR:
         return _seqStr_2_obj_from_type(tg_type, seq)
@@ -538,9 +559,11 @@ def _seqStr_2_obj_from_type_format(seq, tg_type, tg_format):
     #UNKNOWN_FORMAT
     return _seqStr_2_obj_from_type(tg_type, seq)
 
+
 def scalar_to_array_type(dtype):
     return _scalar_to_array_type[dtype]
 
+
 def obj_2_str(obj, tg_type):
     """Converts a python object into a string according to the given tango type
     
@@ -572,6 +595,7 @@ def __get_meth_func(klass, method_name):
         func = meth.im_func
     return meth, func
 
+
 def copy_doc(klass, fnname):
     """Copies documentation string of a method from the super class into the
     rewritten method of the given class"""
@@ -579,6 +603,7 @@ def copy_doc(klass, fnname):
     meth, func = __get_meth_func(klass, fnname)
     func.__doc__ = base_func.__doc__
 
+    
 def document_method(klass, method_name, d, add=True):
     meth, func = __get_meth_func(klass, method_name)
     if add:
@@ -594,6 +619,7 @@ def document_method(klass, method_name, d, add=True):
         except AttributeError:
             pass
 
+        
 def document_static_method(klass, method_name, d, add=True):
     meth, func = __get_meth_func(klass, method_name)
     if add:
@@ -603,6 +629,7 @@ def document_static_method(klass, method_name, d, add=True):
             return
     meth.__doc__ = d
 
+    
 def document_enum(klass, enum_name, desc, append=True):
     # derived = type(base)('derived', (base,), {'__doc__': 'desc'})
 
@@ -620,6 +647,7 @@ def document_enum(klass, enum_name, desc, append=True):
     # Replace the original enum type with the new one
     setattr(klass, enum_name, derived)
 
+    
 class CaselessList(list):
     """A case insensitive lists that has some caseless methods. Only allows 
     strings as list members. Most methods that would normally return a list, 
@@ -1034,6 +1062,7 @@ class EventCallBack(object):
         elif isinstance(evt, DataReadyEventData):
             return ""
 
+        
 def get_home():
     """
     Find user's home directory if possible. Otherwise raise error.
@@ -1060,6 +1089,7 @@ def get_home():
     else:
         raise RuntimeError('please define environment variable $HOME')
 
+    
 def _get_env_var(env_var_name):
     """
     Returns the value for the given environment name
@@ -1104,142 +1134,15 @@ def _get_env_var(env_var_name):
         if key == env_var_name:
             return val
 
+        
 def from_version_str_to_hex_str(version_str):
     v = map(int, version_str.split('.'));
     return "0x%02d%02d%02d00" % (v[0], v[1], v[2])
 
+
 def from_version_str_to_int(version_str):
     return int(from_version_str_to_hex_str(version_str, 16))
 
-def __server_run(classes, args=None, msg_stream=sys.stdout, util=None,
-                 event_loop=None):
-    import PyTango
-    if msg_stream is None:
-        import io
-        msg_stream = io.BytesIO()
-
-    if args is None:
-        args = sys.argv
-
-    if util is None:
-        util = PyTango.Util(args)
-
-    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.hlapi)")
-            klass_klass = klass_info._DeviceClass
-            klass_name = klass_info._DeviceClassName
-            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
-            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.hlapi)")
-                klass_klass = klass_info._DeviceClass
-                klass_name = klass_info._DeviceClassName
-                klass = klass_info
-            util.add_class(klass_klass, klass, klass_name)
-    u_instance = PyTango.Util.instance()
-    if event_loop is not None:
-        u_instance.server_set_event_loop(event_loop)
-    u_instance.server_init()
-    msg_stream.write("Ready to accept request\n")
-    u_instance.server_run()
-    return util
-
-def server_run(classes, args=None, msg_stream=sys.stdout,
-               verbose=False, util=None, event_loop=None):
-    """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.hlapi.Device`
-       classes or a dictionary where:
-       
-       * key is the tango class name
-       * value is either:
-           #. a :class:`~PyTango.hlapi.Device` class or
-           #. a a sequence of two elements :class:`~PyTango.DeviceClass`, :class:`~PyTango.DeviceImpl`
-           
-       Example 1: registering and running a PowerSupply inheriting from :class:`~PyTango.hlapi.Device`::
-       
-           from PyTango import server_run
-           from PyTango.hlapi import Device, DeviceMeta
-       
-           class PowerSupply(Device):
-               __metaclass__ = DeviceMeta
-               
-           server_run((PowerSupply,))
-           
-       Example 2: registering and running a MyServer defined by tango classes 
-       `MyServerClass` and `MyServer`::
-       
-           import PyTango
-
-           class MyServer(PyTango.Device_4Impl):
-               pass
-               
-           class MyServerClass(PyTango.DeviceClass):
-               pass
-       
-           PyTango.server_run({"MyServer": (MyServerClass, MyServer)})
-       
-       :param classes:
-           a sequence of :class:`~PyTango.hlapi.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
-       
-       :return: The Util singleton object
-       :rtype: :class:`~PyTango.Util`
-       
-       .. versionadded:: 8.0.0
-       
-       .. versionchanged:: 8.0.3
-           Added `util` keyword parameter.
-           Returns util object
-
-       .. versionchanged:: 8.1.1
-           Changed default msg_stream from *stderr* to *stdout*
-           Added `event_loop` keyword parameter.
-           Returns util object"""
-
-    if msg_stream is None:
-        import io
-        msg_stream = io.BytesIO()
-    write = msg_stream.write
-    try:
-        return __server_run(classes, args=args, util=util, event_loop=event_loop)
-        write("Exiting:\n")
-    except KeyboardInterrupt:
-        write("Exiting: Keyboard interrupt\n")
-    except DevFailed as df:
-        write("Exiting: Server exited with PyTango.DevFailed:\n" + str(df) + "\n")
-        if verbose:
-            write(traceback.format_exc())
-    except Exception as e:
-        write("Exiting: Server exited with unforseen exception:\n" + str(e) + "\n")
-        if verbose:
-            write(traceback.format_exc())
-    write("\nExited\n")
-
 
 def info():
     import PyTango.constants

-- 
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