[pytango] 122/483: changes for python 2.4; repr_html for IPython

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:31 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 f4420c836f7709706263ae8998f86662d863c915
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Mon Jun 18 10:24:43 2012 +0000

    changes for python 2.4; repr_html for IPython
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@20707 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 PyTango/device_class.py                        |  10 +++--
 PyTango/device_proxy.py                        |  51 +++++++++++++++++++------
 PyTango/ipython/ipython_00_11/ipy_install.py   |   2 -
 PyTango/ipython/ipython_00_11/ipython_00_11.py |  48 +++++++++++++----------
 PyTango/ipython/resource/door.png              | Bin 0 -> 65909 bytes
 PyTango/ipython/resource/macroserver.png       | Bin 0 -> 65909 bytes
 PyTango/ipython/resource/measurementgroup.png  | Bin 0 -> 65946 bytes
 PyTango/ipython/resource/pool.png              | Bin 0 -> 65909 bytes
 PyTango/utils.py                               |  22 ++++++-----
 9 files changed, 86 insertions(+), 47 deletions(-)

diff --git a/PyTango/device_class.py b/PyTango/device_class.py
index fd878b9..a8b5bc3 100644
--- a/PyTango/device_class.py
+++ b/PyTango/device_class.py
@@ -33,7 +33,7 @@ import types
 import operator
 
 from _PyTango import Except, DevFailed
-from _PyTango import _DeviceClass, Database
+from _PyTango import _DeviceClass
 from _PyTango import CmdArgType, DispLevel
 from _PyTango import UserDefaultAttrProp
 
@@ -67,7 +67,7 @@ class PropUtil:
     def __init__(self):
         self.db = None
         if Util._UseDb:
-            self.db = Database()
+            self.db = Util.instance().get_database()
 
     def set_default_property_values(self, dev_class, class_prop, dev_prop):
         """
@@ -293,7 +293,11 @@ class DeviceClass(_DeviceClass):
                                            self.device_property_list)
             pu.get_class_properties(self, self.class_property_list)
             for prop_name in self.class_property_list.keys():
-                setattr(self, prop_name, pu.get_property_values(prop_name, self.class_property_list))
+                if not hasattr(self, prop_name):
+                    setattr(self, prop_name, pu.get_property_values(prop_name,
+                            self.class_property_list))
+            if hasattr(self, 'write_class_property'):
+                self.write_class_property()
         except DevFailed, df:
             print("PyDS: %s: A Tango error occured in the constructor:" % name)
             Except.print_exception(df)
diff --git a/PyTango/device_proxy.py b/PyTango/device_proxy.py
index 661f365..397cd4c 100644
--- a/PyTango/device_proxy.py
+++ b/PyTango/device_proxy.py
@@ -25,8 +25,6 @@
 This is an internal PyTango module.
 """
 
-from __future__ import with_statement
-
 __all__ = []
 
 __docformat__ = "restructuredtext"
@@ -47,6 +45,17 @@ from PyTango.utils import seq_2_StdStringVector, StdStringVector_2_seq
 from PyTango.utils import seq_2_DbData, DbData_2_dict
 from utils import document_method as __document_method
 
+
+class __TangoInfo(object):
+    """Helper class for when DeviceProxy.info() is not available"""
+    
+    def __init__(self):
+        self.dev_class = self.dev_type = 'Device'
+        self.doc_url = 'http://www.esrf.fr/computing/cs/tango/tango_doc/ds_doc/'
+        self.server_host = 'Unknown'
+        self.server_id = 'Unknown'
+        self.server_version = 1
+
 #-------------------------------------------------------------------------------
 # Pythonic API: transform tango commands into methods and tango attributes into
 # class members
@@ -731,8 +740,10 @@ def __DeviceProxy__subscribe_event ( self, attr_name, event_type, cb_or_queuesiz
                     " callable object or an object with a 'push_event' method.")
 
     event_id = self.__subscribe_event(attr_name, event_type, cb, filters, stateless, extract_as)
-
-    with self.__get_event_map_lock():
+    
+    l = self.__get_event_map_lock()
+    l.acquire()
+    try:
         se = self.__get_event_map()
         evt_data = se.get(event_id)
         if evt_data is not None:
@@ -742,6 +753,8 @@ def __DeviceProxy__subscribe_event ( self, attr_name, event_type, cb_or_queuesiz
                    (self, attr_name, event_type, event_id, evt_data[2], evt_data[1])
             Except.throw_exception("Py_InternalError", desc, "DeviceProxy.subscribe_event")
         se[event_id] = (cb, event_type, attr_name)
+    finally:
+        l.release()
     return event_id
 
 def __DeviceProxy__unsubscribe_event(self, event_id):
@@ -760,18 +773,26 @@ def __DeviceProxy__unsubscribe_event(self, event_id):
 
         Throws     : EventSystemFailed
     """
-    with self.__get_event_map_lock():
+    l = self.__get_event_map_lock()
+    l.acquire()
+    try:
         se = self.__get_event_map()
         if event_id not in se:
             raise IndexError("This device proxy does not own this subscription " + str(event_id))
         del se[event_id]
+    finally:
+        l.release()
     self.__unsubscribe_event(event_id)
 
 def __DeviceProxy__unsubscribe_event_all(self):
-    with self.__get_event_map_lock():
+    l = self.__get_event_map_lock()
+    l.acquire()
+    try:
         se = self.__get_event_map()
         event_ids = se.keys()
         se.clear()
+    finally:
+        l.release()
     for event_id in event_ids:
         self.__unsubscribe_event(event_id)
 
@@ -837,14 +858,19 @@ def __DeviceProxy__get_events(self, event_id, callback=None, extract_as=ExtractA
     else:
         raise TypeError("Parameter 'callback' should be None, a callable object or an object with a 'push_event' method.")
 
-def __DeviceProxy__str(self):
-    if not hasattr(self, '_dev_class'):
+def __DeviceProxy___get_info_(self):
+    """Protected method that gets device info once and stores it in cache"""
+    if not hasattr(self, '_dev_info'):
         try:
-            self.__dict__["_dev_class"] = self.info().dev_class
+            self.__dict__["_dev_info"] = self.info()
         except:
-            return "DeviceProxy(%s)" % self.dev_name()
-    return "%s(%s)" % (self._dev_class, self.dev_name())
+            return __TangoInfo()
+    return self._dev_info
     
+def __DeviceProxy__str(self):
+    info = self._get_info_()
+    return "%s(%s)" % (info.dev_class, self.dev_name())
+
 def __init_DeviceProxy():
     DeviceProxy.__getattr__ = __DeviceProxy__getattr
     DeviceProxy.__setattr__ = __DeviceProxy__setattr
@@ -882,7 +908,10 @@ def __init_DeviceProxy():
     DeviceProxy.get_events = __DeviceProxy__get_events
     DeviceProxy.__str__ = __DeviceProxy__str
     DeviceProxy.__repr__ = __DeviceProxy__str
+    
+    DeviceProxy._get_info_ = __DeviceProxy___get_info_
 
+    
 def __doc_DeviceProxy():
     def document_method(method_name, desc, append=True):
         return __document_method(DeviceProxy, method_name, desc, append)
diff --git a/PyTango/ipython/ipython_00_11/ipy_install.py b/PyTango/ipython/ipython_00_11/ipy_install.py
index 0fb5d63..e873fd2 100644
--- a/PyTango/ipython/ipython_00_11/ipy_install.py
+++ b/PyTango/ipython/ipython_00_11/ipy_install.py
@@ -23,8 +23,6 @@
 ##
 ################################################################################
 
-from __future__ import with_statement
-
 import sys
 import os
 import StringIO
diff --git a/PyTango/ipython/ipython_00_11/ipython_00_11.py b/PyTango/ipython/ipython_00_11/ipython_00_11.py
index c147b42..40120ac 100644
--- a/PyTango/ipython/ipython_00_11/ipython_00_11.py
+++ b/PyTango/ipython/ipython_00_11/ipython_00_11.py
@@ -838,7 +838,7 @@ __DEV_HTML_TEMPLATE = """\
     <td>Name:</td><td><b>{name}</b></td></tr>
 <tr><td>Alias:</td><td>{alias}</td></tr>
 <tr><td>Database:</td><td>{database}</td></tr>
-<tr><td>Device class:</td><td>{dev_class}</td></tr>
+<tr><td>Type:</td><td>{dev_class}</td></tr>
 <tr><td>Server:</td><td>{server_id}</td></tr>
 <tr><td>Server host:</td><td>{server_host}</td></tr>
 <tr><td>Documentation:</td><td><a target="_blank" href="{doc_url}">{doc_url}</a></td></tr>
@@ -864,11 +864,35 @@ class __TangoInfo(object):
             self.dev_class = self.dev_type = klass
         except:
             self.dev_class = self.dev_type = 'Device'
-        self.doc_url = 'http://www.esrf.fr/computing/cs/tango/tango_doc/ds_doc/'
+        self.doc_url = 'http://www.esrf.eu/computing/cs/tango/tango_doc/ds_doc/index.html'
         self.server_host = 'Unknown'
         self.server_id = 'Unknown'
         self.server_version = 1
 
+def __get_device_icon(dev_proxy, klass="Device"):
+    icon_prop = "__icon"
+    db = dev_proxy.get_device_db()
+    try:
+        icon_filename = dev_proxy.get_property(icon_prop)[icon_prop]
+        if icon_filename:
+            icon_filename = icon_filename[0]
+        else:
+            icon_filename = db.get_class_property(klass, icon_prop)[icon_prop]
+            if icon_filename:
+                icon_filename = icon_filename[0]
+            else:            
+                icon_filename = klass.lower() + os.path.extsep + "png"
+    except:
+        icon_filename = klass.lower() + os.path.extsep + "png"
+    
+    if os.path.isabs(icon_filename):
+        icon = icon_filename
+    else:
+        icon = os.path.join(__RES_DIR, icon_filename)
+    if not os.path.isfile(icon):
+        icon = os.path.join(__RES_DIR, "device.png")
+    return icon
+
 def display_deviceproxy_html(dev_proxy):
     """displayhook function for PyTango.DeviceProxy, rendered as HTML"""
     try:
@@ -899,25 +923,7 @@ def display_deviceproxy_html(dev_proxy):
     except ValueError:
         fmt["doc_url"] = doc_url
 
-    icon_prop = "__icon"
-    klass = info.dev_class
-        
-    try:
-        icon_filename = dev_proxy.get_property(icon_prop)[icon_prop]
-        if icon_filename:
-            icon_filename = icon_filename[0]
-        else:
-            icon_filename = db.get_class_property(klass, icon_prop)[icon_prop]
-            if icon_filename:
-                icon_filename = icon_filename[0]
-            else:            
-                icon_filename = klass.lower() + os.path.extsep + "png"
-    except:
-        icon_filename = klass.lower() + os.path.extsep + "png"
-    icon = os.path.join(__RES_DIR, icon_filename)
-    if not os.path.isfile(icon):
-        icon = os.path.join(__RES_DIR, "device.png")
-    fmt['icon'] =  icon
+    fmt['icon'] = __get_device_icon(dev_proxy, info.dev_class)
 
     return __DEV_HTML_TEMPLATE.format(**fmt)
 
diff --git a/PyTango/ipython/resource/door.png b/PyTango/ipython/resource/door.png
new file mode 100644
index 0000000..3233a88
Binary files /dev/null and b/PyTango/ipython/resource/door.png differ
diff --git a/PyTango/ipython/resource/macroserver.png b/PyTango/ipython/resource/macroserver.png
new file mode 100644
index 0000000..28946e0
Binary files /dev/null and b/PyTango/ipython/resource/macroserver.png differ
diff --git a/PyTango/ipython/resource/measurementgroup.png b/PyTango/ipython/resource/measurementgroup.png
new file mode 100644
index 0000000..406ea78
Binary files /dev/null and b/PyTango/ipython/resource/measurementgroup.png differ
diff --git a/PyTango/ipython/resource/pool.png b/PyTango/ipython/resource/pool.png
new file mode 100644
index 0000000..8c40239
Binary files /dev/null and b/PyTango/ipython/resource/pool.png differ
diff --git a/PyTango/utils.py b/PyTango/utils.py
index fe0248b..9736d0f 100644
--- a/PyTango/utils.py
+++ b/PyTango/utils.py
@@ -25,8 +25,6 @@
 This is an internal PyTango module.
 """
 
-from __future__ import with_statement
-
 __all__ = [ "is_scalar_type", "is_array_type", "is_numerical_type", 
             "is_int_type", "is_float_type", "obj_2_str", "seqStr_2_obj",
             "document_method", "document_static_method", "document_enum",
@@ -712,9 +710,13 @@ __NOTIFD_FACTORY_PREFIX = "notifd/factory/"
 
 def notifd2db(notifd_ior_file=__DEFAULT_FACT_IOR_FILE, files=None, host=None, out=sys.stdout):
     ior_string = ""
-    with file(notifd_ior_file) as ior_file:
+    ior_file = None
+    try:
+        ior_file = file(notifd_ior_file)
         ior_string = ior_file.read()
-    
+    finally:
+        if ior_file is not None:
+            ior_file.close()
     if files is None:
         return _notifd2db_real_db(ior_string, host=host, out=out)
     else:
@@ -723,12 +725,12 @@ def notifd2db(notifd_ior_file=__DEFAULT_FACT_IOR_FILE, files=None, host=None, ou
 def _notifd2db_file_db(ior_string, files, out=sys.stdout):
     raise RuntimeError("Not implemented yet")
 
-    print >>out, "going to export notification service event factory to " \
-                 "device server property file(s) ..."
-    for f in files:
-        with file(f, "w"):
-            pass
-    return
+    #print >>out, "going to export notification service event factory to " \
+    #             "device server property file(s) ..."
+    #for f in files:
+    #    with file(f, "w"):
+    #        pass
+    #return
 
 def _notifd2db_real_db(ior_string, host=None, out=sys.stdout):
     import PyTango

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