Skip to content

Commit

Permalink
adoption of Python logging mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Oct 6, 2015
1 parent 8f4039f commit deb6d86
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 18 deletions.
24 changes: 24 additions & 0 deletions HDFCompass.py
Expand Up @@ -9,6 +9,30 @@
# distribution tree. If you do not have access to this file, you may #
# request a copy from help@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()
7 changes: 6 additions & 1 deletion hdf_compass/array_model/__init__.py
Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions hdf_compass/asc_model/__init__.py
Expand Up @@ -17,13 +17,18 @@
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
import linecache

import numpy as np

import logging
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())

from hdf_compass import compass_model


Expand Down
5 changes: 5 additions & 0 deletions hdf_compass/compass_model/__init__.py
Expand Up @@ -68,6 +68,11 @@ class MyHDF5Image(Image):
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

Expand Down
21 changes: 13 additions & 8 deletions hdf_compass/compass_viewer/__init__.py
Expand Up @@ -15,13 +15,18 @@
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
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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()

Expand Down
38 changes: 38 additions & 0 deletions hdf_compass/compass_viewer/__main__.py
@@ -0,0 +1,38 @@
##############################################################################
# Copyright by The HDF Group. #
# All rights reserved. #
# #
# This file is part of the HDF Compass Viewer. The full HDF Compass #
# copyright notice, including terms governing use, modification, and #
# terms governing use, modification, and redistribution, is contained in #
# the file COPYING, which can be found at the root of the source code #
# distribution tree. If you do not have access to this file, you may #
# request a copy from help@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 . import run

run()
4 changes: 4 additions & 0 deletions hdf_compass/compass_viewer/array/__init__.py
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions hdf_compass/compass_viewer/array/plot.py
Expand Up @@ -13,6 +13,7 @@
"""
Matplotlib window with toolbar.
"""
from __future__ import absolute_import, division, print_function, unicode_literals

import numpy as np
import wx
Expand All @@ -22,6 +23,9 @@
FigureCanvasWxAgg as FigCanvas, \
NavigationToolbar2WxAgg as NavigationToolbar

import logging
log = logging.getLogger(__name__)

from ..frame import BaseFrame


Expand All @@ -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
Expand Down Expand Up @@ -84,8 +87,8 @@ def draw_figure(self):
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)
Expand Down
6 changes: 5 additions & 1 deletion hdf_compass/compass_viewer/container/__init__.py
Expand Up @@ -17,9 +17,13 @@
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
Expand Down Expand Up @@ -196,7 +200,7 @@ def on_open(self, evt):
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:
Expand Down
4 changes: 4 additions & 0 deletions hdf_compass/compass_viewer/container/list.py
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions hdf_compass/compass_viewer/events.py
Expand Up @@ -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()


Expand Down
7 changes: 5 additions & 2 deletions hdf_compass/compass_viewer/frame.py
Expand Up @@ -17,14 +17,17 @@
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
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
Expand Down Expand Up @@ -390,7 +393,7 @@ def on_menu_reopen(self, evt):
# 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)

Expand Down
File renamed without changes
File renamed without changes
5 changes: 4 additions & 1 deletion hdf_compass/compass_viewer/image/__init__.py
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions hdf_compass/compass_viewer/info.py
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions hdf_compass/compass_viewer/keyvalue/__init__.py
Expand Up @@ -16,9 +16,13 @@
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


Expand Down
3 changes: 3 additions & 0 deletions hdf_compass/compass_viewer/platform.py
Expand Up @@ -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'
Expand Down

0 comments on commit deb6d86

Please sign in to comment.