From b909272181642a44b7ab46a31f6894c2767040a1 Mon Sep 17 00:00:00 2001 From: John Evans Date: Thu, 25 Jul 2013 18:41:38 -0400 Subject: [PATCH] Added warning when neither library found, monkey-patched version. Did some things I'm not proud of... Should revisit this. --- glymur/lib/__init__.py | 1 - glymur/lib/config.py | 7 +++++++ glymur/lib/openjpeg.py | 4 +++- glymur/test/test_jp2k.py | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/glymur/lib/__init__.py b/glymur/lib/__init__.py index ebd4fa7..ba5915d 100644 --- a/glymur/lib/__init__.py +++ b/glymur/lib/__init__.py @@ -1,4 +1,3 @@ """This package organizes individual libraries employed by glymur.""" from . import openjp2 as _openjp2 from . import openjpeg as _openjpeg -#from . import test diff --git a/glymur/lib/config.py b/glymur/lib/config.py index c29579c..7fcaeb6 100644 --- a/glymur/lib/config.py +++ b/glymur/lib/config.py @@ -58,6 +58,9 @@ def load_openjpeg(libopenjpeg_path): 'bin', 'openjpeg.dll') if os.path.exists(path): libopenjpeg_path = path + else: + # No sense trying further on Linux + return None try: if os.name == "nt": @@ -124,6 +127,10 @@ def glymur_config(): libs = read_config_file() libopenjp2_handle = load_openjp2(libs['openjp2']) libopenjpeg_handle = load_openjpeg(libs['openjpeg']) + if libopenjp2_handle is None and libopenjpeg_handle is None: + msg = "Neither the openjp2 nor the openjpeg library could be loaded. " + msg += "Operating in severely degraded mode." + warnings.warn(msg, UserWarning) return libopenjp2_handle, libopenjpeg_handle diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py index 4f990df..56bdfd3 100644 --- a/glymur/lib/openjpeg.py +++ b/glymur/lib/openjpeg.py @@ -22,13 +22,15 @@ def version(): return library_version # Need to get the minor version, make sure we are at least at 1.4.x -#import pdb; pdb.set_trace() if OPENJPEG is not None: _MINOR = version().split('.')[1] else: # Does not really matter. But version should not be called if there is no # OpenJPEG library found. _MINOR = 0 + # Redefine version so that we can use it. + def version(): + return '0.0.0' class EventMgrType(ctypes.Structure): diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 43eaade..34d49a5 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -47,6 +47,9 @@ def load_tests(loader, tests, ignore): return tests +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and + glymur.lib.openjpeg.OPENJPEG is None, + "Missing openjp2 library.") class TestConfig(unittest.TestCase): def setUp(self):