From: W. Trevor King Date: Fri, 16 Mar 2012 12:57:41 +0000 (-0400) Subject: Improve prettyprint message for empty HDF5 files. X-Git-Tag: v0.2~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=817c8deb7eb977590cf15ede319661db0dd4026d;p=h5config.git Improve prettyprint message for empty HDF5 files. --- diff --git a/h5config/storage/hdf5.py b/h5config/storage/hdf5.py index 34f4fae..6af6b2d 100644 --- a/h5config/storage/hdf5.py +++ b/h5config/storage/hdf5.py @@ -18,6 +18,7 @@ """HDF5 backend implementation """ +import os.path as _os_path import types as _types import h5py as _h5py @@ -32,9 +33,16 @@ def pprint_HDF5(*args, **kwargs): print pformat_HDF5(*args, **kwargs) def pformat_HDF5(filename, group='/'): - with _h5py.File(filename, 'r') as f: - cwg = f[group] - ret = '\n'.join(_pformat_hdf5(cwg)) + try: + with _h5py.File(filename, 'r') as f: + cwg = f[group] + ret = '\n'.join(_pformat_hdf5(cwg)) + except IOError, e: + if 'unable to open' in e.message: + if _os_path.getsize(filename) == 0: + return 'EMPTY' + return None + raise return ret def _pformat_hdf5(cwg, depth=0):