[hdf-compass] 109/295: adoption of Python logging mechanism

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:32 UTC 2016


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

ghisvail-guest pushed a commit to branch debian/master
in repository hdf-compass.

commit deb6d8644d9b1d08b45a1ea7a453498bdcee2e09
Author: giumas <giumas at yahoo.it>
Date:   Tue Oct 6 09:08:19 2015 -0400

    adoption of Python logging mechanism
---
 HDFCompass.py                                      |  24 +++++++++++++++
 hdf_compass/array_model/__init__.py                |   7 ++++-
 hdf_compass/asc_model/__init__.py                  |   5 ++++
 hdf_compass/compass_model/__init__.py              |   5 ++++
 hdf_compass/compass_viewer/__init__.py             |  21 ++++++++-----
 .../compass_viewer/{platform.py => __main__.py}    |  33 ++++++++++++++-------
 hdf_compass/compass_viewer/array/__init__.py       |   4 +++
 hdf_compass/compass_viewer/array/plot.py           |  13 ++++----
 hdf_compass/compass_viewer/container/__init__.py   |   6 +++-
 hdf_compass/compass_viewer/container/list.py       |   4 +++
 hdf_compass/compass_viewer/events.py               |   4 +++
 hdf_compass/compass_viewer/frame.py                |   7 +++--
 .../compass_viewer}/icons/go-top_24.png            | Bin
 .../compass_viewer}/icons/go-top_32.png            | Bin
 hdf_compass/compass_viewer/image/__init__.py       |   5 +++-
 hdf_compass/compass_viewer/info.py                 |   4 +++
 hdf_compass/compass_viewer/keyvalue/__init__.py    |   4 +++
 hdf_compass/compass_viewer/platform.py             |   3 ++
 hdf_compass/filesystem_model/__init__.py           |   5 ++++
 hdf_compass/hdf5_model/__init__.py                 |   5 ++++
 hdf_compass/opendap_model/__init__.py              |   6 ++++
 21 files changed, 137 insertions(+), 28 deletions(-)

diff --git a/HDFCompass.py b/HDFCompass.py
index 894a114..2310c23 100644
--- a/HDFCompass.py
+++ b/HDFCompass.py
@@ -9,6 +9,30 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+import logging
+
+
+class LoggingFilter(logging.Filter):
+    """ An example of logging filter that disables the logging from a specific module """
+    def filter(self, record):
+        # print(record.name)
+        if record.name.startswith('hdf_compass.compass_viewer.info'):
+            return False
+        return True
+
+
+# logging settings
+logger = logging.getLogger()
+logger.setLevel(logging.NOTSET)
+ch = logging.StreamHandler()
+ch.setLevel(logging.DEBUG)  # change to WARNING to minimize verbosity, DEBUG for high verbosity
+ch_formatter = logging.Formatter('%(levelname)-7s %(name)s.%(funcName)s:%(lineno)d > %(message)s')
+ch.setFormatter(ch_formatter)
+# ch.addFilter(LoggingFilter())  # uncomment to activate the logging filter
+logger.addHandler(ch)
 
 from hdf_compass import compass_viewer
+
 compass_viewer.run()
diff --git a/hdf_compass/array_model/__init__.py b/hdf_compass/array_model/__init__.py
index 2d48b18..d6bae0c 100644
--- a/hdf_compass/array_model/__init__.py
+++ b/hdf_compass/array_model/__init__.py
@@ -13,12 +13,17 @@
 """
 Testing model for array types.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import numpy as np
 
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
 from hdf_compass import compass_model
 
-DT_CMP = np.dtype([('a', 'i'), ('b', 'f')])
+DT_CMP = np.dtype([(b'a', b'i'), (b'b', b'f')])
 
 DATA = {'a_0d': np.array(1),
         'a_1d': np.arange(10),
diff --git a/hdf_compass/asc_model/__init__.py b/hdf_compass/asc_model/__init__.py
index eee5992..2a2b719 100644
--- a/hdf_compass/asc_model/__init__.py
+++ b/hdf_compass/asc_model/__init__.py
@@ -17,6 +17,7 @@ directories and the ASCII grid data respectively.
 See: http://en.wikipedia.org/wiki/Esri_grid for a description of
 the file format
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import sys
 import os.path as op
@@ -24,6 +25,10 @@ import linecache
 
 import numpy as np
 
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
 from hdf_compass import compass_model
 
 
diff --git a/hdf_compass/compass_model/__init__.py b/hdf_compass/compass_model/__init__.py
index f257747..4e4eeba 100644
--- a/hdf_compass/compass_model/__init__.py
+++ b/hdf_compass/compass_model/__init__.py
@@ -68,6 +68,11 @@ of Image, and register it with the other person's class:
 Of course, this assumes you know enough about the internals of the other
 person's Store to make your new class useful.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
 
 from . import images
 
diff --git a/hdf_compass/compass_viewer/__init__.py b/hdf_compass/compass_viewer/__init__.py
index b8d29ee..3c2145c 100644
--- a/hdf_compass/compass_viewer/__init__.py
+++ b/hdf_compass/compass_viewer/__init__.py
@@ -15,6 +15,7 @@ Main module for HDFCompass.
 
 Defines the App class, along with supporting infrastructure.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 # Must be at the top, to ensure we're the first to call matplotlib.use.
 import matplotlib
@@ -22,6 +23,10 @@ matplotlib.use('WXAgg')
 
 import wx
 
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
 from hdf_compass import compass_model
 
 from .imagesupport import png_to_bitmap
@@ -113,7 +118,7 @@ def open_node(node, pos=None):
     else:
         newpos = None
 
-    print "Top-level open called for ", node
+    log.debug("Top-level open called for %s" % node)
 
     if isinstance(node, compass_model.Container):
         f = container.ContainerFrame(node, pos=newpos)
@@ -154,33 +159,33 @@ def load_plugins():
     try:
         from hdf_compass import filesystem_model
     except ImportError:
-        print("Filesystem plugin not loaded")
+        log.info("Filesystem plugin not loaded")
 
     try:
         from hdf_compass import array_model
     except ImportError:
-        print("Array plugin not loaded")
+        log.info("Array plugin not loaded")
 
     try:
         from hdf_compass import hdf5_model
     except ImportError:
-        print("HDF plugin not loaded")
+        log.info("HDF plugin not loaded")
 
     # Coming soon!
     # try:
     #     from hdf_compass import bag_model
     # except ImportError:
-    #     print("BAG plugin not loaded")
+    #     log.info("BAG plugin not loaded")
 
     try:
         from hdf_compass import asc_model
     except ImportError:
-        print("Ascii grid plugin not loaded")
+        log.info("Ascii grid plugin not loaded")
 
     try:
         from hdf_compass import opendap_model
     except ImportError:
-        print("Opendap plugin not loaded")
+        log.info("Opendap plugin not loaded")
 
 
 def run():
@@ -204,7 +209,7 @@ def run():
             else:
                 url = 'file://' + op.abspath(url)
         if not open_store(url):
-            print 'Failed to open "%s"; no handlers'%url
+            log.warning('Failed to open "%s"; no handlers' % url)
 
     f = frame.InitFrame()
     
diff --git a/hdf_compass/compass_viewer/platform.py b/hdf_compass/compass_viewer/__main__.py
similarity index 50%
copy from hdf_compass/compass_viewer/platform.py
copy to hdf_compass/compass_viewer/__main__.py
index 1411ba8..92f3fda 100644
--- a/hdf_compass/compass_viewer/platform.py
+++ b/hdf_compass/compass_viewer/__main__.py
@@ -9,17 +9,30 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
-"""
-    Module for platform- and version-specific feature detection.
-"""
+from __future__ import absolute_import, division, print_function, unicode_literals
 
-import sys
+import logging
 
-MAC = sys.platform == 'darwin'
-WINDOWS = sys.platform == 'win32'
-LINUX = sys.platform == 'linux2'
 
-if not any((MAC, WINDOWS, LINUX)):
-    raise ValueError('Unknown platform "%s"' % sys.platform)
+class LoggingFilter(logging.Filter):
+    """ An example of logging filter that disables the logging from a specific module """
+    def filter(self, record):
+        # print(record.name)
+        if record.name.startswith('hdf_compass.compass_viewer.info'):
+            return False
+        return True
 
-VERSION = "0.5"
+
+# logging settings
+logger = logging.getLogger()
+logger.setLevel(logging.NOTSET)
+ch = logging.StreamHandler()
+ch.setLevel(logging.DEBUG)  # change to WARNING to minimize verbosity, DEBUG for high verbosity
+ch_formatter = logging.Formatter('%(levelname)-7s %(name)s.%(funcName)s:%(lineno)d > %(message)s')
+ch.setFormatter(ch_formatter)
+# ch.addFilter(LoggingFilter())  # uncomment to activate the logging filter
+logger.addHandler(ch)
+
+from . import run
+
+run()
diff --git a/hdf_compass/compass_viewer/array/__init__.py b/hdf_compass/compass_viewer/array/__init__.py
index ee09d09..5b0db3b 100644
--- a/hdf_compass/compass_viewer/array/__init__.py
+++ b/hdf_compass/compass_viewer/array/__init__.py
@@ -12,11 +12,15 @@
 """
 Implements a viewer frame for compass_model.Array.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 import wx.grid
 from wx.lib.newevent import NewCommandEvent
 
+import logging
+log = logging.getLogger(__name__)
+
 from .. import imagesupport
 from ..frame import NodeFrame
 from .plot import LinePlotFrame, ContourPlotFrame
diff --git a/hdf_compass/compass_viewer/array/plot.py b/hdf_compass/compass_viewer/array/plot.py
index 17c060d..93f6453 100644
--- a/hdf_compass/compass_viewer/array/plot.py
+++ b/hdf_compass/compass_viewer/array/plot.py
@@ -13,6 +13,7 @@
 """
 Matplotlib window with toolbar.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import numpy as np
 import wx
@@ -22,6 +23,9 @@ from matplotlib.backends.backend_wxagg import \
     FigureCanvasWxAgg as FigCanvas, \
     NavigationToolbar2WxAgg as NavigationToolbar
 
+import logging
+log = logging.getLogger(__name__)
+
 from ..frame import BaseFrame
 
 
@@ -33,10 +37,9 @@ class PlotFrame(BaseFrame):
     """
 
     def __init__(self, data, title="a title"):
-        """ Create a new Matplotlib plotting window for a 1D line plot
-        """
+        """ Create a new Matplotlib plotting window for a 1D line plot """
 
-        print self.__class__.__name__
+        log.debug(self.__class__.__name__)
         BaseFrame.__init__(self, id=wx.ID_ANY, title=title, size=(800, 400))
 
         self.data = data
@@ -84,8 +87,8 @@ class ContourPlotFrame(PlotFrame):
         maxElements = 500  # don't attempt plot more than 500x500 elements
         rows = self.data.shape[0]
         cols = self.data.shape[1]
-        row_stride = rows / maxElements + 1
-        col_stride = cols / maxElements + 1
+        row_stride = rows // maxElements + 1
+        col_stride = cols // maxElements + 1
         data = self.data[::row_stride, ::col_stride]
         xx = np.arange(0, self.data.shape[1], col_stride)
         yy = np.arange(0, self.data.shape[0], row_stride)
diff --git a/hdf_compass/compass_viewer/container/__init__.py b/hdf_compass/compass_viewer/container/__init__.py
index 9fe8196..3e91ae3 100644
--- a/hdf_compass/compass_viewer/container/__init__.py
+++ b/hdf_compass/compass_viewer/container/__init__.py
@@ -17,9 +17,13 @@ This frame is a simple browser view with back/forward/up controls.
 
 Currently list and icon views are supported.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 
+import logging
+log = logging.getLogger(__name__)
+
 from hdf_compass import compass_model
 from .. import imagesupport
 from ..frame import NodeFrame
@@ -196,7 +200,7 @@ class ContainerFrame(NodeFrame):
         new windows.
         """
         newnode = evt.node
-        print "Got request to open node", newnode.key
+        log.debug("Got request to open node: %s" % newnode.key)
         if isinstance(newnode, compass_model.Container):
             self.go(newnode)
         else:
diff --git a/hdf_compass/compass_viewer/container/list.py b/hdf_compass/compass_viewer/container/list.py
index dc29eee..338e1ae 100644
--- a/hdf_compass/compass_viewer/container/list.py
+++ b/hdf_compass/compass_viewer/container/list.py
@@ -12,9 +12,13 @@
 """
 Handles list and icon view for Container display.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 
+import logging
+log = logging.getLogger(__name__)
+
 from hdf_compass import compass_model
 from ..events import CompassOpenEvent
 from ..events import ContainerSelectionEvent
diff --git a/hdf_compass/compass_viewer/events.py b/hdf_compass/compass_viewer/events.py
index 5980f86..ae92baa 100644
--- a/hdf_compass/compass_viewer/events.py
+++ b/hdf_compass/compass_viewer/events.py
@@ -13,10 +13,14 @@
 """
 Defines a small number of custom events, which are useful for the GUI.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 from wx.lib.newevent import NewCommandEvent
 
+import logging
+log = logging.getLogger(__name__)
+
 ID_COMPASS_OPEN = wx.NewId()
 
 
diff --git a/hdf_compass/compass_viewer/frame.py b/hdf_compass/compass_viewer/frame.py
index 4f2279e..010d269 100644
--- a/hdf_compass/compass_viewer/frame.py
+++ b/hdf_compass/compass_viewer/frame.py
@@ -17,7 +17,7 @@ displayed by HDFCompass.
 Much of the common functionality (e.g. "Open File..." menu item) is implemented
 here.
 """
-
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import os
 import sys
@@ -25,6 +25,9 @@ from datetime import date
 import wx
 from wx.lib.pubsub import pub
 
+import logging
+log = logging.getLogger(__name__)
+
 from . import imagesupport
 from .info import InfoPanel
 from . import platform
@@ -390,7 +393,7 @@ class NodeFrame(BaseFrame):
         # The requested Node subclass to instantiate.
         h = self._menu_handlers[id_]
 
-        print 'opening', node_being_opened.store, node_being_opened.key
+        log.debug('opening: %s %s' % (node_being_opened.store, node_being_opened.key))
         # Brand new Node instance of the requested type
         node_new = h(node_being_opened.store, node_being_opened.key)
 
diff --git a/compass_viewer/icons/go-top_24.png b/hdf_compass/compass_viewer/icons/go-top_24.png
similarity index 100%
rename from compass_viewer/icons/go-top_24.png
rename to hdf_compass/compass_viewer/icons/go-top_24.png
diff --git a/compass_viewer/icons/go-top_32.png b/hdf_compass/compass_viewer/icons/go-top_32.png
similarity index 100%
rename from compass_viewer/icons/go-top_32.png
rename to hdf_compass/compass_viewer/icons/go-top_32.png
diff --git a/hdf_compass/compass_viewer/image/__init__.py b/hdf_compass/compass_viewer/image/__init__.py
index f2c422b..9c5b4b9 100644
--- a/hdf_compass/compass_viewer/image/__init__.py
+++ b/hdf_compass/compass_viewer/image/__init__.py
@@ -13,10 +13,13 @@
 """
 Implements a simple true-color image viewer.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 import wx.grid
-from wx.lib.newevent import NewCommandEvent  # FIXME: Unused?
+
+import logging
+log = logging.getLogger(__name__)
 
 from ..frame import NodeFrame
 
diff --git a/hdf_compass/compass_viewer/info.py b/hdf_compass/compass_viewer/info.py
index 9632f46..986b2a8 100644
--- a/hdf_compass/compass_viewer/info.py
+++ b/hdf_compass/compass_viewer/info.py
@@ -13,9 +13,13 @@
 """
 Defines the left-hand side information panel used to display context info.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 
+import logging
+log = logging.getLogger(__name__)
+
 from hdf_compass import compass_model
 from .imagesupport import png_to_bitmap
 from . import platform
diff --git a/hdf_compass/compass_viewer/keyvalue/__init__.py b/hdf_compass/compass_viewer/keyvalue/__init__.py
index 6964256..9632d05 100644
--- a/hdf_compass/compass_viewer/keyvalue/__init__.py
+++ b/hdf_compass/compass_viewer/keyvalue/__init__.py
@@ -16,9 +16,13 @@ Implements a viewer for key-value stores (instances of compass_model.KeyValue).
 Keys are strings, values are any data type HDFCompass can understand.
 Presently this means all NumPy types, plus Python str/unicode.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import wx
 
+import logging
+log = logging.getLogger(__name__)
+
 from ..frame import NodeFrame
 
 
diff --git a/hdf_compass/compass_viewer/platform.py b/hdf_compass/compass_viewer/platform.py
index 1411ba8..9fe3206 100644
--- a/hdf_compass/compass_viewer/platform.py
+++ b/hdf_compass/compass_viewer/platform.py
@@ -12,8 +12,11 @@
 """
     Module for platform- and version-specific feature detection.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import sys
+import logging
+log = logging.getLogger(__name__)
 
 MAC = sys.platform == 'darwin'
 WINDOWS = sys.platform == 'win32'
diff --git a/hdf_compass/filesystem_model/__init__.py b/hdf_compass/filesystem_model/__init__.py
index 279815b..faf7be4 100644
--- a/hdf_compass/filesystem_model/__init__.py
+++ b/hdf_compass/filesystem_model/__init__.py
@@ -16,12 +16,17 @@ Example data model which represents the file system.
 Subclasses just two node types: Container and Array, representing
 directories and files respectively.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 import os
 import os.path as op
 
 import numpy as np
 
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
 from hdf_compass import compass_model
 
 
diff --git a/hdf_compass/hdf5_model/__init__.py b/hdf_compass/hdf5_model/__init__.py
index 6963e49..cdb299f 100644
--- a/hdf_compass/hdf5_model/__init__.py
+++ b/hdf_compass/hdf5_model/__init__.py
@@ -13,6 +13,7 @@
 """
 Implementation of compass_model classes for HDF5 files.
 """
+from __future__ import absolute_import, division, print_function, unicode_literals
 
 from itertools import groupby
 import sys
@@ -21,6 +22,10 @@ import posixpath as pp
 
 import h5py
 
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
 # Py2App can't successfully import otherwise
 from hdf_compass import compass_model
 
diff --git a/hdf_compass/opendap_model/__init__.py b/hdf_compass/opendap_model/__init__.py
index f32a814..ef83af4 100644
--- a/hdf_compass/opendap_model/__init__.py
+++ b/hdf_compass/opendap_model/__init__.py
@@ -9,6 +9,8 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
+from __future__ import absolute_import, division, print_function, unicode_literals
+
 import posixpath as pp
 
 import numpy as np
@@ -16,6 +18,10 @@ import pydap as dap
 from pydap.client import open_url
 from pydap.proxy import ArrayProxy
 
+import logging
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
 from hdf_compass import compass_model
 
 

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



More information about the debian-science-commits mailing list