[pytango] 95/483: prepare for multiple ipython version support

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:28 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 50522e562fc7e4645ad825a544c7a8b70130b901
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Fri Jan 27 16:43:55 2012 +0000

    prepare for multiple ipython version support
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@19097 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 PyTango/ipython/__init__.py                    |  47 ++------
 PyTango/ipython/common.py                      | 148 +++++++++++++++++++++++++
 PyTango/ipython/ipython_00_10/ipy_install.py   |  16 +--
 PyTango/ipython/ipython_00_10/ipy_utils.py     |  42 -------
 PyTango/ipython/ipython_00_10/ipython_00_10.py | 105 +++++++-----------
 PyTango/ipython/ipython_00_11/ipy_install.py   |  12 +-
 PyTango/ipython/ipython_00_11/ipython_00_11.py | 124 +++++++++------------
 PyTango/ipython/ipython_00_12/ipython_00_12.py |  57 +++-------
 8 files changed, 280 insertions(+), 271 deletions(-)

diff --git a/PyTango/ipython/__init__.py b/PyTango/ipython/__init__.py
index da3f699..47c0b1e 100644
--- a/PyTango/ipython/__init__.py
+++ b/PyTango/ipython/__init__.py
@@ -24,55 +24,22 @@
 __all__ = ["init_ipython", "install", "load_ipython_extension",
            "unload_ipython_extension", "load_config"]
 
-try:
-    import IPython
-    ipython = IPython
-except:
-    ipython = None
-
-def get_ipython_version():
-    """Returns the current IPython version"""
-    if ipython is None:return None
-    v = None
-    try:
-        try:
-            v = ipython.Release.version
-        except Exception:
-            try:
-                v = ipython.release.version
-            except Exception:
-                pass
-    except Exception:
-        pass
-    return v
-
-def get_ipython_version_list():
-    ipv_str = get_ipython_version()
-
-    if ipv_str is None:
-        ipv = [0, 0]
-    else:
-        ipv = []
-        for i in ipv_str.split(".")[:2]:
-            try:
-                i = int(i)
-            except:
-                i = 0
-            ipv.append(i)
-    return ipv
+from .common import get_python_version, get_python_version_number, \
+    get_ipython_version, get_ipython_version_list, \
+    get_ipython_version_number, get_pytango_version, get_pytango_version_number
 
 def default_init_ipython(ip, store=True, pytango=True, colors=True,
                          console=True, magic=True):
-    print "Unsupported IPython version (%s) for spock profile" \
+    print "Unsupported IPython version (%s) for tango profile" \
         % get_ipython_version()
     print "Supported IPython versions are: >= 0.10"
     print "Starting normal IPython console..."
 
 def default_install(ipydir=None, verbose=True):
-    print "Unsupported IPython version (%s) for spock profile" \
+    print "Unsupported IPython version (%s) for tango profile" \
         % get_ipython_version()
     print "Supported IPython versions are: 0.10 to 0.13"
-    print "Tango extension to IPyhon will NOT be installed."
+    print "Tango extension to IPython will NOT be installed."
 
 init_ipython = default_init_ipython
 install = default_install
@@ -92,7 +59,7 @@ elif ipv >= [0, 11] and ipv < [0, 12]:
     load_config = ipython_00_11.load_config
     load_ipython_extension = ipython_00_11.load_ipython_extension
     unload_ipython_extension = ipython_00_11.unload_ipython_extension
-elif ipv >= [0, 12] and ipv <= [0, 13]:
+elif ipv >= [0, 12] and ipv < [1, 0]:
     import ipython_00_12
     init_ipython = None
     install = ipython_00_12.install
diff --git a/PyTango/ipython/common.py b/PyTango/ipython/common.py
new file mode 100644
index 0000000..4f89348
--- /dev/null
+++ b/PyTango/ipython/common.py
@@ -0,0 +1,148 @@
+#!/usr/bin/env python
+
+################################################################################
+##
+## This file is part of PyTango, a python binding for Tango
+## 
+## http://www.tango-controls.org/static/PyTango/latest/doc/html/index.html
+##
+## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
+## 
+## PyTango is free software: you can redistribute it and/or modify
+## it under the terms of the GNU Lesser General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+## 
+## PyTango is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU Lesser General Public License for more details.
+## 
+## You should have received a copy of the GNU Lesser General Public License
+## along with PyTango.  If not, see <http://www.gnu.org/licenses/>.
+##
+################################################################################
+
+"""functions common (hopefully) to all ipython versions"""
+
+__all__ = ["translate_version_str2int", "translate_version_str2list",
+           "get_python_version", "get_python_version_number",
+           "get_ipython_version", "get_ipython_version_list",
+           "get_ipython_version_number",
+           "get_pytango_version", "get_pytango_version_number"]
+
+import sys
+import math
+
+def translate_version_str2int(version_str):
+    """Translates a version string in format 'x[.y[.z[...]]]' into a 000000 number"""
+    
+    parts = version_str.split('.')
+    i, v, l = 0, 0, len(parts)
+    if not l:
+        return v
+    while i<3:
+        try:
+            v += int(parts[i])*int(math.pow(10,(2-i)*2))
+            l -= 1
+            i += 1
+        except ValueError,ve:
+            return v
+        if not l: return v
+    return v
+    
+    try:
+        v += 10000*int(parts[0])
+        l -= 1
+    except ValueError,ve:
+        return v
+    if not l: return v
+    
+    try:
+        v += 100*int(parts[1])
+        l -= 1
+    except ValueError,ve:
+        return v
+    if not l: return v
+
+    try:
+        v += int(parts[0])
+        l -= 1
+    except ValueError,ve:
+        return v
+    if not l: return v
+
+def translate_version_str2list(version_str):
+    """Translates a version string in format 'x[.y[.z[...]]]' into a list of
+    numbers"""
+    if version_str is None:
+        ver = [0, 0]
+    else:
+        ver = []
+        for i in version_str.split(".")[:2]:
+            try:
+                i = int(i)
+            except:
+                i = 0
+            ver.append(i)
+    return ver
+
+#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+# Python utilities
+#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+
+def get_python_version():
+    return '.'.join(map(str, sys.version_info[:3]))
+
+def get_python_version_number():
+    pyver_str = get_python_version()
+    return translate_version_str2int(pyver_str)
+
+#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+# IPython utilities
+#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+
+def get_ipython_version():
+    """Returns the current IPython version"""
+    import IPython
+    v = None
+    try:
+        try:
+            v = IPython.Release.version
+        except Exception, e1:
+            try:
+                v = IPython.release.version
+            except Exception, e2:
+                pass
+    except Exception, e3:
+        pass
+    return v
+
+def get_ipython_version_list():
+    ipv_str = get_ipython_version()
+    return translate_version_str2list(ipv_str)
+
+def get_ipython_version_number():
+    """Returns the current IPython version number"""
+    ipyver_str = get_ipython_version()
+    if ipyver_str is None: return None
+    return translate_version_str2int(ipyver_str)
+
+#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+# PyTango utilities
+#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+
+def get_pytango_version():
+    try:
+        import PyTango
+    except:
+        return
+    try:
+        return PyTango.Release.version
+    except:
+        return '0.0.0'
+
+def get_pytango_version_number():
+    tgver_str = get_pytango_version()
+    if tgver_str is None: return None
+    return translate_version_str2int(tgver_str)
\ No newline at end of file
diff --git a/PyTango/ipython/ipython_00_10/ipy_install.py b/PyTango/ipython/ipython_00_10/ipy_install.py
index 8e4ae69..aa7e058 100644
--- a/PyTango/ipython/ipython_00_10/ipy_install.py
+++ b/PyTango/ipython/ipython_00_10/ipy_install.py
@@ -46,7 +46,7 @@ PyTango.ipython.init_ipython(ip)
 
 def install(ipydir=None,verbose=True):
     install_dir = ipydir or IPython.genutils.get_ipython_dir()
-    f_name = os.path.join(install_dir, 'ipy_profile_spock.py')
+    f_name = os.path.join(install_dir, 'ipy_profile_tango.py')
     if verbose:
         out = sys.stdout
     else:
@@ -61,7 +61,7 @@ def install(ipydir=None,verbose=True):
             return
     profile = __PROFILE.format(pytangover=PyTango.Release.version, ipyver=IPython.Release.version)
     
-    out.write("Installing spock extension to ipython... ")
+    out.write("Installing tango extension to ipython... ")
     out.flush()
     try:
         f = file(f_name, "w")
@@ -74,23 +74,23 @@ def install(ipydir=None,verbose=True):
     
     ipy_user_config = os.path.join(IPython.genutils.get_ipython_dir(), 'ipy_user_conf.py')
     out.write("""\
-To start spock simply type on the command line:
-%% ipython -p spock
+To start ipython with tango interface simply type on the command line:
+%% ipython -p tango
 
-If you want spock extension to be automaticaly active when you start ipython,
+If you want tango extension to be automaticaly active when you start ipython,
 edit your %s and add the line:
-import ipy_profile_spock
+import ipy_profile_tango
 
 Next time, just start ipython on the command line:
 %% ipython
 
-and your spock extension should be loaded automaticaly. Note that if you are also
+and your tango extension should be loaded automaticaly. Note that if you are also
 loading other extensions that, for example, overwrite the prompt, the prompt
 that will appear is the one from the last extension to be imported.
 
 For more information goto: http://www.tango-controls.org/static/PyTango/latest/doc/html/index.html
 
-Have fun with spock!
+Have fun with ITango!
 The PyTango team
     """ % (ipy_user_config,))
 
diff --git a/PyTango/ipython/ipython_00_10/ipy_utils.py b/PyTango/ipython/ipython_00_10/ipy_utils.py
deleted file mode 100644
index 5e0649f..0000000
--- a/PyTango/ipython/ipython_00_10/ipy_utils.py
+++ /dev/null
@@ -1,42 +0,0 @@
-################################################################################
-##
-## This file is part of PyTango, a python binding for Tango
-## 
-## http://www.tango-controls.org/static/PyTango/latest/doc/html/index.html
-##
-## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
-## 
-## PyTango is free software: you can redistribute it and/or modify
-## it under the terms of the GNU Lesser General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-## 
-## PyTango is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU Lesser General Public License for more details.
-## 
-## You should have received a copy of the GNU Lesser General Public License
-## along with PyTango.  If not, see <http://www.gnu.org/licenses/>.
-##
-################################################################################
-
-import os
-
-import IPython
-ipython = IPython
-
-def get_ipython_dir():
-    """Find the ipython local directory. Usually is <home>/.ipython"""
-    return ipython.iplib.get_ipython_dir()
-
-def get_ipython_profiles():
-    """Helper functions to find ipython profiles"""
-    ret = []
-    ipydir = get_ipython_dir()
-    if os.path.isdir(ipydir):
-        for i in os.listdir(ipydir):
-            if i.startswith("ipy_profile_") and i.endswith(".py") and \
-                os.path.isfile(i):
-                ret.append(i[len("ipy_profile_"):i.rfind(".")])
-    return ret
\ No newline at end of file
diff --git a/PyTango/ipython/ipython_00_10/ipython_00_10.py b/PyTango/ipython/ipython_00_10/ipython_00_10.py
index 89c72b4..b808674 100644
--- a/PyTango/ipython/ipython_00_10/ipython_00_10.py
+++ b/PyTango/ipython/ipython_00_10/ipython_00_10.py
@@ -42,10 +42,10 @@ import PyTango.utils
 
 _DB_SYMB = "db"
 _DFT_TANGO_HOST = None
-_SPOCK_STORE = "__spock_store"
+_TANGO_STORE = "__tango_store"
 _TANGO_ERR = "__tango_error"
-_SPOCK_ERR = "__spock_error"
-_spock_init = False
+_PYTHON_ERR = "__python_error"
+_tango_init = False
 
 _TG_EXCEPTIONS = PyTango.DevFailed, PyTango.CommunicationFailed, \
     PyTango.NamedDevFailed, PyTango.NamedDevFailedList, \
@@ -320,11 +320,11 @@ def magic_tango_error(self, parameter_s=''):
     print "Last tango error:"
     print err_info[1]
 
-def magic_spock_error(self, parameter_s=''):
-    """Displays detailed information about the last spock error"""
+def magic_python_error(self, parameter_s=''):
+    """Displays detailed information about the last python error"""
     
-    global _SPOCK_ERR
-    err_info = self.user_ns.get(_SPOCK_ERR)
+    global _PYTHON_ERR
+    err_info = self.user_ns.get(_PYTHON_ERR)
     if err_info is None:
         print "No error reported so far."
         return
@@ -340,7 +340,7 @@ def __get_event_log():
             import ipy_qt
             model = ipy_qt.EventLoggerTableModel(capacity=10000)
             _EVT_LOG = ipy_qt.EventLogger(model=model)
-            _EVT_LOG.setWindowTitle("Spock - Event Logger Table")
+            _EVT_LOG.setWindowTitle("ITango - Event Logger Table")
         else:
             import ipy_cli
             _EVT_LOG = ipy_cli.EventLogger(capacity=10000)
@@ -450,7 +450,7 @@ def get_device_map():
         - tango server name (full tango server name <name>/<instance>)
         - tango class name
         - DeviceProxy to the device or None if it hasn't been initialized yet
-          (this last element is for internal spock usage only. If you need a 
+          (this last element is for internal tango usage only. If you need a 
            DeviceProxy to this device, create your own)"""
     db = __get_db()
     if db is None:
@@ -519,10 +519,10 @@ def __exc_handler(ip, etype, value, tb):
             print "Empty DevFailed"
         print "(For more detailed information type: tango_error)"
     else:
-        global _SPOCK_ERR
-        ip.user_ns[_SPOCK_ERR] = etype, value, tb
+        global _PYTHON_ERR
+        ip.user_ns[_PYTHON_ERR] = etype, value, tb
         print etype.__name__ + ": " + str(value)
-        print "(For more detailed information type: spock_error)"
+        print "(For more detailed information type: python_error)"
 
 def __get_default_tango_host():
     global _DFT_TANGO_HOST
@@ -609,7 +609,7 @@ def __completer_wrapper(f):
             return f(ip, evt)
         except Exception, e:
             print
-            print "An unexpected exception ocorred during Spock command completer."
+            print "An unexpected exception ocorred during ITango command completer."
             print "Please send a bug report to the PyTango team with the following informantion:"
             print IPython.ipapi.get().options.banner
             print 80*"-"
@@ -620,28 +620,6 @@ def __completer_wrapper(f):
             raise e
     return wrapper
 
-def __get_python_version():
-    return '.'.join(map(str,sys.version_info[:3]))
-
-def __get_ipython_version():
-    """Returns the current IPython version"""
-    v = None
-    try:
-        try:
-            v = IPython.Release.version
-        except Exception:
-            try:
-                v = IPython.release.version
-            except Exception:
-                pass
-    except Exception:
-        pass
-    return v
-
-def __get_pytango_version():
-    vi = PyTango.Release.version_info
-    return ".".join(map(str,vi[:3]))+vi[3]
-
 def __get_ipapi():
     return IPython.ipapi.get()
 
@@ -700,15 +678,15 @@ def __build_color_scheme(ip, name):
 
 def __set_store(ip, key=None, value=None):
     if key is not None:
-        spock_store = ip.user_ns.get(_SPOCK_STORE)
-        spock_store[key] = value
-    __store(ip, _SPOCK_STORE)
+        tango_store = ip.user_ns.get(_TANGO_STORE)
+        tango_store[key] = value
+    __store(ip, _TANGO_STORE)
 
 def __get_store(ip, key, nvalue=None):
-    spock_store = ip.user_ns.get(_SPOCK_STORE)
-    v = spock_store.get(key)
+    tango_store = ip.user_ns.get(_TANGO_STORE)
+    v = tango_store.get(key)
     if v is None and nvalue is not None:
-        spock_store[key] = nvalue
+        tango_store[key] = nvalue
         v = nvalue
     return v
 
@@ -846,8 +824,6 @@ def init_db(ip, parameter_s=''):
             c = DeviceClassCompleter(klass, devices)
             ip.set_hook('complete_command', c, re_key = ".*" + klass + "[^\w\.]+")
             exposed_klasses[klass] = PyTango.DeviceProxy
-        else:
-            print "Failed to add completer for DeviceClass",klass
     
     # expose classes no user namespace
     ip.to_user_ns(exposed_klasses)
@@ -895,43 +871,44 @@ def init_db(ip, parameter_s=''):
 def init_store(ip):
     # recover the environment
     ip.magic("store -r")
-    spock_store = ip.user_ns.get(_SPOCK_STORE)
+    tango_store = ip.user_ns.get(_TANGO_STORE)
     
-    if spock_store is None:
-        print "Initializing spock store (should only happen once)"
-        spock_store = {}
-        ip.to_user_ns( { _SPOCK_STORE : spock_store} )
-        __store(ip, _SPOCK_STORE)
+    if tango_store is None:
+        print "Initializing tango store (should only happen once)"
+        tango_store = {}
+        ip.to_user_ns( { _TANGO_STORE : tango_store} )
+        __store(ip, _TANGO_STORE)
         
 def init_console(ip):
+    import PyTango.ipython
     
     TermColors = IPython.ColorANSI.TermColors
     
-    d = { "version" : PyTango.Release.version,
-          "pyver" : __get_python_version(),
-          "ipyver" : __get_ipython_version(),
-          "pytangover" : __get_pytango_version() }
+    d = { "version" : PyTango.ipython.get_pytango_version(),
+          "pyver" : PyTango.ipython.get_python_version(),
+          "ipyver" : PyTango.ipython.get_ipython_version(),
+          "pytangover" : PyTango.ipython.get_pytango_version() }
     d.update(TermColors.__dict__)
 
     o = ip.options
 
     so = IPython.ipstruct.Struct(
-        spock_banner = """%(Blue)shint: Try typing: mydev = Device("%(LightBlue)s<tab>%(Normal)s\n""")
+        tango_banner = """%(Blue)shint: Try typing: mydev = Device("%(LightBlue)s<tab>%(Normal)s\n""")
 
-    so = ip.user_ns.get("spock_options", so)
+    so = ip.user_ns.get("tango_options", so)
     
     o.colors = "Tango"
-    o.prompt_in1 = "Spock <$DB_NAME> [\\#]: "
+    o.prompt_in1 = "ITango <$DB_NAME> [\\#]: "
     o.prompt_out = "Result [\\#]: "
     banner = """
-%(Purple)sSpock %(version)s%(Normal)s -- An interactive %(Purple)sTango%(Normal)s client.
+%(Purple)sITango %(version)s%(Normal)s -- An interactive %(Purple)sTango%(Normal)s client.
 
 Running on top of Python %(pyver)s, IPython %(ipyver)s and PyTango %(pytangover)s
 
-help      -> Spock's help system.
+help      -> ITango's help system.
 object?   -> Details about 'object'. ?object also works, ?? prints more.
 
-""" + so.spock_banner
+""" + so.tango_banner
     o.banner = banner % d
     if hasattr(o.banner, "format"):
         o.banner = o.banner.format(**d)
@@ -944,7 +921,7 @@ def init_magic(ip):
     __expose_magic(ip, "lsdevclass", magic_lsdevclass)
     __expose_magic(ip, "lsserv", magic_lsserv)
     __expose_magic(ip, "tango_error", magic_tango_error)
-    __expose_magic(ip, "spock_error", magic_spock_error)
+    __expose_magic(ip, "python_error", magic_python_error)
     __expose_magic(ip, "mon", magic_mon, __monitor_completer)
     #__expose_magic(ip, "umon", magic_umon, __monitor_completer)
     
@@ -980,10 +957,10 @@ def complete(text):
 def init_ipython(ip, store=True, pytango=True, colors=True, console=True, magic=True):
     
     if ip is None:
-        raise Exception("Spock's init_ipython must be called from inside IPython")
+        raise Exception("ITango's init_ipython must be called from inside IPython")
     
-    global _spock_init
-    if _spock_init is True: return
+    global _tango_init
+    if _tango_init is True: return
     
     #ip.IP._orig_complete = ip.IP.complete
     #ip.IP.complete = complete
@@ -995,4 +972,4 @@ def init_ipython(ip, store=True, pytango=True, colors=True, console=True, magic=
     if console: init_console(ip)
     if magic:   init_magic(ip)
     
-    _spock_init = True
+    _tango_init = True
diff --git a/PyTango/ipython/ipython_00_11/ipy_install.py b/PyTango/ipython/ipython_00_11/ipy_install.py
index 1bee65e..fe967af 100644
--- a/PyTango/ipython/ipython_00_11/ipy_install.py
+++ b/PyTango/ipython/ipython_00_11/ipy_install.py
@@ -51,7 +51,7 @@ PyTango.ipython.load_config(config)
 # Put any additional environment here
 """
 
-def install(ipydir=None, verbose=True, profile='spock'):
+def install(ipydir=None, verbose=True, profile='tango'):
     if verbose:
         out = sys.stdout
     else:
@@ -67,13 +67,13 @@ def install(ipydir=None, verbose=True, profile='spock'):
     abs_config_file_name = os.path.join(p_dir.location, config_file_name)
     create_config = True
     if os.path.isfile(abs_config_file_name):
-        create_config = ask_yes_no("Spock configuration file already exists. "\
+        create_config = ask_yes_no("Tango configuration file already exists. "\
                                    "Do you wish to replace it?", default='y')
     
     if not create_config:
         return
 
-    out.write("Installing spock extension to ipython... ")
+    out.write("Installing tango extension to ipython... ")
     out.flush()
 
     profile = __PROFILE.format(pytangover=PyTango.Release.version,
@@ -83,13 +83,13 @@ def install(ipydir=None, verbose=True, profile='spock'):
         f.close()
     out.write("[DONE]\n\n")
     out.write("""\
-To start spock simply type on the command line:
-%% ipython --profile=spock
+To start ipython with tango interface simply type on the command line:
+%% ipython --profile=tango
 
 For more information goto:
 http://www.tango-controls.org/static/PyTango/latest/doc/html/
 
-Have fun with spock!
+Have fun with ITango!
 The PyTango team
 """)
     
diff --git a/PyTango/ipython/ipython_00_11/ipython_00_11.py b/PyTango/ipython/ipython_00_11/ipython_00_11.py
index 360f9be..cd9f208 100644
--- a/PyTango/ipython/ipython_00_11/ipython_00_11.py
+++ b/PyTango/ipython/ipython_00_11/ipython_00_11.py
@@ -50,10 +50,10 @@ _TG_EXCEPTIONS = PyTango.DevFailed, PyTango.CommunicationFailed, \
 
 _DB_SYMB = "db"
 _DFT_TANGO_HOST = None
-_SPOCK_STORE = "__spock_store"
+_TANGO_STORE = "__tango_store"
 _TANGO_ERR = "__tango_error"
-_SPOCK_ERR = "__spock_error"
-_spock_init = False
+_PYTHON_ERR = "__python_error"
+_tango_init = False
 
 class DeviceClassCompleter(object):
     """Completer class that returns the list of devices of some class when
@@ -322,11 +322,11 @@ def magic_tango_error(self, parameter_s=''):
     print "Last tango error:"
     print err_info[1]
 
-def magic_spock_error(self, parameter_s=''):
-    """Displays detailed information about the last spock error"""
+def magic_python_error(self, parameter_s=''):
+    """Displays detailed information about the last python error"""
     
-    global _SPOCK_ERR
-    err_info = self.user_ns.get(_SPOCK_ERR)
+    global _PYTHON_ERR
+    err_info = self.user_ns.get(_PYTHON_ERR)
     if err_info is None:
         print "No error reported so far."
         return
@@ -342,7 +342,7 @@ def __get_event_log():
             import ipy_qt
             model = ipy_qt.EventLoggerTableModel(capacity=10000)
             _EVT_LOG = ipy_qt.EventLogger(model=model)
-            _EVT_LOG.setWindowTitle("Spock - Event Logger Table")
+            _EVT_LOG.setWindowTitle("ITango - Event Logger Table")
         else:
             import ipy_cli
             _EVT_LOG = ipy_cli.EventLogger(capacity=10000)
@@ -445,7 +445,7 @@ def get_device_map():
         - tango server name (full tango server name <name>/<instance>)
         - tango class name
         - DeviceProxy to the device or None if it hasn't been initialized yet
-          (this last element is for internal spock usage only. If you need a 
+          (this last element is for internal tango usage only. If you need a 
            DeviceProxy to this device, create your own)"""
     db = __get_db()
     if db is None:
@@ -514,10 +514,10 @@ def __exc_handler(ip, etype, value, tb, tb_offset=None):
             print "Empty DevFailed"
         print "(For more detailed information type: tango_error)"
     else:
-        global _SPOCK_ERR
-        ip.user_ns[_SPOCK_ERR] = etype, value, tb, tb_offset
+        global _PYTHON_ERR
+        ip.user_ns[_PYTHON_ERR] = etype, value, tb, tb_offset
         print etype.__name__ + ": " + str(value)
-        print "(For more detailed information type: spock_error)"
+        print "(For more detailed information type: python_error)"
 
 def __get_default_tango_host():
     global _DFT_TANGO_HOST
@@ -606,7 +606,7 @@ def __completer_wrapper(f):
             return f(ip, evt)
         except Exception, e:
             print
-            print "An unexpected exception ocorred during Spock command completer."
+            print "An unexpected exception ocorred during ITango command completer."
             print "Please send a bug report to the PyTango team with the following information:"
             print 80*"-"
             print "Completer:",__get_obj_name(f)
@@ -617,26 +617,6 @@ def __completer_wrapper(f):
             raise e
     return wrapper
 
-def __get_python_version():
-    return '.'.join(map(str,sys.version_info[:3]))
-
-def __get_ipython_version():
-    """Returns the current IPython version"""
-    import IPython
-    v = "<Unknown>"
-    try:
-        v = IPython.release.version
-    except Exception:
-        pass
-    return v
-
-def __get_pytango_version():
-    vi = PyTango.Release.version_info
-    return ".".join(map(str,vi[:3]))+vi[3]
-
-def __get_ipapi():
-    return ipapi.get()
-
 def __expose_magic(ip, name, fn, completer_func=None):
     ip.define_magic(name, fn)
     
@@ -650,7 +630,6 @@ def __unexpose_magic(ip, name):
     delattr(ip, 'magic_' + name)
 
 def __build_color_scheme(ip, name):
-
     import IPython.Prompts
     import IPython.PyColorize
     import IPython.excolors
@@ -693,27 +672,24 @@ def __build_color_scheme(ip, name):
 
 def __set_store(ip, key=None, value=None):
     if key is not None:
-        spock_store = ip.user_ns.get(_SPOCK_STORE)
-        spock_store[key] = value
-    __store(ip, _SPOCK_STORE)
+        tango_store = ip.user_ns.get(_TANGO_STORE)
+        tango_store[key] = value
+    __store(ip, _TANGO_STORE)
 
 def __get_store(ip, key, nvalue=None):
-    # ipython 0.11 doesn't have 'store' magic command so...
-    spock_store = ip.user_ns.get(_SPOCK_STORE)
-    if spock_store is None:
-        ip.user_ns[_SPOCK_STORE] = spock_store = {}
-    v = spock_store.get(key)
+    tango_store = ip.user_ns.get(_TANGO_STORE)
+    if tango_store is None:
+        ip.user_ns[_TANGO_STORE] = tango_store = {}
+    v = tango_store.get(key)
     if v is None and nvalue is not None:
-        spock_store[key] = nvalue
+        tango_store[key] = nvalue
         v = nvalue
     return v
 
 def __store(ip, var):
     # this executes the magic command store which prints a lot of info. So, first
-    # we hide the standard output 
-    # ipython 0.11 doesn't have 'store' magic command so...
-    return
-
+    # we hide the standard output
+    
     stdout = sys.stdout
     try:
         sys.stdout = StringIO.StringIO()
@@ -803,13 +779,13 @@ def init_db(ip, parameter_s=''):
     exposed_klasses = {}
     excluded_klasses = "DServer",
     for klass, devices in klass_dict.items():
-        if klass in excluded_klasses: continue
-        if not ip.user_ns.has_key(klass) or klass in old_junk:
+        if klass in excluded_klasses:
+            continue
+        exists = ip.user_ns.has_key(klass)
+        if not exists or klass in old_junk:
             c = DeviceClassCompleter(klass, devices)
             ip.set_hook('complete_command', c, re_key = ".*" + klass + "[^\w\.]+")
             exposed_klasses[klass] = PyTango.DeviceProxy
-        else:
-            print "Failed to add completer for DeviceClass",klass
     
     # expose classes no user namespace
     ip.user_ns.update(exposed_klasses)
@@ -859,7 +835,7 @@ def init_magic(ip):
     __expose_magic(ip, "lsdevclass", magic_lsdevclass)
     __expose_magic(ip, "lsserv", magic_lsserv)
     __expose_magic(ip, "tango_error", magic_tango_error)
-    __expose_magic(ip, "spock_error", magic_spock_error)
+    __expose_magic(ip, "python_error", magic_python_error)
     __expose_magic(ip, "mon", magic_mon, __monitor_completer)
     #__expose_magic(ip, "umon", magic_umon, __monitor_completer)
     
@@ -898,8 +874,13 @@ def init_ipython(ip=None, store=True, pytango=True, colors=True, console=True,
     if ip is None:
         ip = ipapi.get()
     
-    global _spock_init
-    if _spock_init is True: return
+    global _tango_init
+    if _tango_init is True: return
+    
+    # 0.11 doesn't have store magic command so we ignore any store atempts
+    if 'store' not in ip.lsmagic():
+        global __store
+        __store = lambda a, b : None
     
     if pytango:
         init_pytango(ip)
@@ -909,21 +890,22 @@ def init_ipython(ip=None, store=True, pytango=True, colors=True, console=True,
     if magic:
         init_magic(ip)
     
-    _spock_init = True
+    _tango_init = True
 
 def load_config(config):
-    
+    import PyTango.ipython
     import IPython.utils.coloransi
-    d = { "version" : PyTango.Release.version,
-          "pyver" : __get_python_version(),
-          "ipyver" : __get_ipython_version(),
-          "pytangover" : __get_pytango_version() }
+    
+    d = { "version" : PyTango.ipython.get_pytango_version(),
+          "pyver" : PyTango.ipython.get_python_version(),
+          "ipyver" : PyTango.ipython.get_ipython_version(),
+          "pytangover" : PyTango.ipython.get_pytango_version(), }
     d.update(IPython.utils.coloransi.TermColors.__dict__)
 
     so = Struct(
-        spock_banner="""%(Blue)shint: Try typing: mydev = Device("%(LightBlue)s<tab>%(Normal)s""")
+        tango_banner="""%(Blue)shint: Try typing: mydev = Device("%(LightBlue)s<tab>%(Normal)s""")
 
-    so = config.get("spock_options", so)
+    so = config.get("tango_options", so)
 
     # ------------------------------------
     # Application
@@ -936,7 +918,7 @@ def load_config(config):
     # ------------------------------------
     i_shell = config.InteractiveShell
     i_shell.colors = 'Linux'
-    i_shell.prompt_in1 = 'Spock <$DB_NAME> [\\#]: '
+    i_shell.prompt_in1 = 'ITango <$DB_NAME> [\\#]: '
     i_shell.prompt_out = 'Result [\\#]: '
     
     # ------------------------------------
@@ -960,8 +942,8 @@ def load_config(config):
     # ------------------------------------
     #kernel_app = config.IPKernelApp
     ipython_widget = config.IPythonWidget
-    ipython_widget.in_prompt  = 'Spock [<span class="in-prompt-number">%i</span>]: '
-    ipython_widget.out_prompt = '  Out [<span class="out-prompt-number">%i</span>]: '
+    ipython_widget.in_prompt  = 'ITango [<span class="in-prompt-number">%i</span>]: '
+    ipython_widget.out_prompt = '   Out [<span class="out-prompt-number">%i</span>]: '
     
     #zmq_i_shell = config.ZMQInteractiveShell
     
@@ -970,22 +952,20 @@ def load_config(config):
     # ------------------------------------
     term_i_shell = config.TerminalInteractiveShell
     banner = """\
-%(Purple)sSpock %(version)s%(Normal)s -- An interactive %(Purple)sTango%(Normal)s client.
+%(Purple)sITango %(version)s%(Normal)s -- An interactive %(Purple)sTango%(Normal)s client.
 
 Running on top of Python %(pyver)s, IPython %(ipyver)s and PyTango %(pytangover)s
 
-help      -> Spock's help system.
+help      -> ITango's help system.
 object?   -> Details about 'object'. ?object also works, ?? prints more.
 """
     
     banner = banner % d
     banner = banner.format(**d)
-    spock_banner = so.spock_banner % d
-    spock_banner = spock_banner.format(**d)
+    tango_banner = so.tango_banner % d
+    tango_banner = tango_banner.format(**d)
     term_i_shell.banner1 = banner
-    term_i_shell.banner2 = spock_banner
-        
-    
+    term_i_shell.banner2 = tango_banner
 
 def load_ipython_extension(ipython):
     # The ``ipython`` argument is the currently active
diff --git a/PyTango/ipython/ipython_00_12/ipython_00_12.py b/PyTango/ipython/ipython_00_12/ipython_00_12.py
index 3f731e0..6321580 100644
--- a/PyTango/ipython/ipython_00_12/ipython_00_12.py
+++ b/PyTango/ipython/ipython_00_12/ipython_00_12.py
@@ -27,41 +27,22 @@
 
 __all__ = ["load_config"]
 
-import sys
-import PyTango
-
 from IPython.utils.ipstruct import Struct
-from IPython.utils.coloransi import TermColors
-
-def __get_python_version():
-    return '.'.join(map(str,sys.version_info[:3]))
-
-def __get_ipython_version():
-    """Returns the current IPython version"""
-    import IPython
-    v = "<Unknown>"
-    try:
-        v = IPython.release.version
-    except Exception:
-        pass
-    return v
-
-def __get_pytango_version():
-    vi = PyTango.Release.version_info
-    return ".".join(map(str,vi[:3]))+vi[3]
-
+from  IPython.utils.coloransi import TermColors
 
 def load_config(config):
-    d = { "version" : PyTango.Release.version,
-          "pyver" : __get_python_version(),
-          "ipyver" : __get_ipython_version(),
-          "pytangover" : __get_pytango_version() }
+    import PyTango.ipython
+    
+    d = { "version" : PyTango.ipython.get_pytango_version(),
+          "pyver" : PyTango.ipython.get_python_version(),
+          "ipyver" : PyTango.ipython.get_ipython_version(),
+          "pytangover" : PyTango.ipython.get_pytango_version(), }
     d.update(TermColors.__dict__)
 
     so = Struct(
-        spock_banner="""%(Blue)shint: Try typing: mydev = Device("%(LightBlue)s<tab>%(Normal)s""")
+        tango_banner="""%(Blue)shint: Try typing: mydev = Device("%(LightBlue)s<tab>%(Normal)s""")
 
-    so = config.get("spock_options", so)
+    so = config.get("tango_options", so)
 
     # ------------------------------------
     # Application
@@ -74,14 +55,12 @@ def load_config(config):
     # ------------------------------------
     i_shell = config.InteractiveShell
     i_shell.colors = 'Linux'
-    #i_shell.prompt_in1 = 'Spock <$DB_NAME> [\\#]: '
-    #i_shell.prompt_out = 'Result [\\#]: '
     
     # ------------------------------------
     # PromptManager
     # ------------------------------------
     prompt = config.PromptManager
-    prompt.in_template = 'Spock {DB_NAME} [\\#]: '
+    prompt.in_template = 'ITango {DB_NAME} [\\#]: '
     #prompt.in2_template = 
     prompt.out_template = 'Result [\\#]: '
     
@@ -92,6 +71,7 @@ def load_config(config):
     extensions = getattr(i_shell_app, 'extensions', [])
     extensions.append('PyTango.ipython')
     i_shell_app.extensions = extensions
+    i_shell_app.ignore_old_config=True
     
     # ------------------------------------
     # TerminalIPythonApp: options for the IPython terminal (and not Qt Console)
@@ -106,8 +86,8 @@ def load_config(config):
     # ------------------------------------
     #kernel_app = config.IPKernelApp
     ipython_widget = config.IPythonWidget
-    ipython_widget.in_prompt  = 'Spock [<span class="in-prompt-number">%i</span>]: '
-    ipython_widget.out_prompt = '  Out [<span class="out-prompt-number">%i</span>]: '
+    ipython_widget.in_prompt  = 'ITango [<span class="in-prompt-number">%i</span>]: '
+    ipython_widget.out_prompt = '   Out [<span class="out-prompt-number">%i</span>]: '
     
     #zmq_i_shell = config.ZMQInteractiveShell
     
@@ -116,18 +96,17 @@ def load_config(config):
     # ------------------------------------
     term_i_shell = config.TerminalInteractiveShell
     banner = """\
-%(Purple)sSpock %(version)s%(Normal)s -- An interactive %(Purple)sTango%(Normal)s client.
+%(Purple)sITango %(version)s%(Normal)s -- An interactive %(Purple)sTango%(Normal)s client.
 
 Running on top of Python %(pyver)s, IPython %(ipyver)s and PyTango %(pytangover)s
 
-help      -> Spock's help system.
+help      -> ITango's help system.
 object?   -> Details about 'object'. ?object also works, ?? prints more.
 """
     
     banner = banner % d
     banner = banner.format(**d)
-    spock_banner = so.spock_banner % d
-    spock_banner = spock_banner.format(**d)
+    tango_banner = so.tango_banner % d
+    tango_banner = tango_banner.format(**d)
     term_i_shell.banner1 = banner
-    term_i_shell.banner2 = spock_banner
-
+    term_i_shell.banner2 = tango_banner
\ No newline at end of file

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