[h5py] 68/455: More HL tweaks
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.
commit 3d57cf4b6de667e68c968e4284ce7896b9a6a424
Author: andrewcollette <andrew.collette at gmail.com>
Date: Mon Jul 7 03:57:43 2008 +0000
More HL tweaks
---
h5py/browse.py | 39 +++++++++++++++++++++++++++++----------
h5py/highlevel.py | 35 +++++++++++++++++++++++++++--------
h5py/utils_hl.py | 15 +++++++++++++++
3 files changed, 71 insertions(+), 18 deletions(-)
diff --git a/h5py/browse.py b/h5py/browse.py
index 10e7088..1463f21 100644
--- a/h5py/browse.py
+++ b/h5py/browse.py
@@ -10,6 +10,11 @@
#
#-
+"""
+ Simple command-line browser program, designed to be called by a File
+ instance.
+"""
+
from cmd import Cmd
from posixpath import join, basename, dirname, normpath, isabs
from getopt import gnu_getopt, GetoptError
@@ -138,6 +143,29 @@ class _H5Browser(Cmd, object):
except:
raise CmdError('Can\'t list contents of group "%s"' % hbasename(grpname))
+ def do_info(self, line):
+
+ opts, args = gnu_getopt(shlex.split(line),'')
+
+ for arg in args:
+ name = self.abspath(arg)
+ try:
+ obj = self.file[name]
+ print obj.desc()
+ except:
+ raise CmdError("Can't get info on object \"%s\"" % hbasename(name))
+
+ def complete_info(self, text, line, begidx, endidx):
+ text = text.strip()
+ grpname = self.abspath(dirname(text))
+ targetname = basename(text)
+
+ grp = self.file[grpname]
+ rval = [join(grpname,x) for x in grp \
+ if x.find(targetname) == 0]
+ return rval
+
+
def do_import(self, line):
""" import name [as python_name]
import name1 name2 name3 name4 ...
@@ -165,7 +193,7 @@ class _H5Browser(Cmd, object):
try:
obj = self.file[hname]
except Exception, e:
- raise CmdError("Can't import %s: %s" % (name, e.args[0].splitlines()[0]))
+ raise CmdError("Can't import %s" % pyname)
if len(re.sub('[A-Za-z_][A-Za-z0-9_]*','',pyname)) != 0:
raise CmdError("%s is not a valid Python identifier" % pyname)
@@ -195,12 +223,3 @@ class _H5Browser(Cmd, object):
-
-
-
-
-
-
-
-
-
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index f180c60..1a8ba83 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -9,13 +9,13 @@
# $Date$
#
#-
-
+import os
import numpy
import inspect
from h5py import h5, h5f, h5g, h5s, h5t, h5d, h5a, h5p, h5z, h5i
from h5py.h5 import H5Error
-from utils_hl import slicer, hbasename
+from utils_hl import slicer, hbasename, strhdr, strlist
from browse import _H5Browser
try:
@@ -119,14 +119,32 @@ class Group(HLObject):
def __str__(self):
if self.id._valid:
- return 'Group "%s" (%d members): %s' % (hbasename(self.name),
- len(self), ', '.join(['"%s"' % name for name in self]))
+ return 'Group "%s" (%d members)' % (hbasename(self.name), len(self))
return "Closed group"
def iteritems(self):
for name in self:
yield (name, self[name])
+ def desc(self):
+ """ Extended description of this group, as a string.
+
+ print grp.desc() # contains newlines
+ """
+
+ outstr = 'Group "%s" in file "%s":' % \
+ (hbasename(h5i.get_name(self.id)), os.path.basename(h5f.get_name(self.id)))
+ outstr = strhdr(outstr)
+ infodct = {"Members": len(self)}
+ grpinfo = self.id.get_objinfo('.')
+ infodct["mtime"] = grpinfo.mtime
+ outstr += strlist([(name, infodct[name]) for name in ("Members", "mtime")])
+
+ cmnt = self.id.get_comment('.')
+ if cmnt != '':
+ outstr += '\nComment:\n'+cmnt
+ return outstr
+
class File(Group):
""" Represents an HDF5 file on disk.
@@ -186,7 +204,7 @@ class File(Group):
def close(self):
""" Close this HDF5 file. All open identifiers will become invalid.
"""
- self.id.close()
+ self.id._close()
self.fid.close()
def flush(self):
@@ -200,14 +218,15 @@ class File(Group):
return "Closed file (%s)" % self.name
def browse(self, dict=None):
- """ Browse this file. If no import dict is provided, will seize the
- caller's global dictionary.
+ """ Open a command line shell to browse this file. If dict is not
+ specified, any imported object will be placed in the caller's
+ global() dictionary.
"""
if dict is None:
dict = inspect.currentframe().f_back.f_globals
def gethist():
- rlhist = [readline.get_history_item(x) for x in xrange(readline.get_current_history_length())]
+ rlhist = [readline.get_history_item(x) for x in xrange(readline.get_current_history_length()+1)]
rlhist = [x for x in rlhist if x is not None]
return rlhist
diff --git a/h5py/utils_hl.py b/h5py/utils_hl.py
index 657f73c..7acfecb 100644
--- a/h5py/utils_hl.py
+++ b/h5py/utils_hl.py
@@ -115,3 +115,18 @@ def slicer(shape, args):
return (tuple(start), tuple(count), tuple(stride), tuple(names))
+def strhdr(line, char='-'):
+ """ Print a line followed by an ASCII-art underline """
+ return line + "\n%s\n" % (char*len(line))
+
+def strlist(lst, keywidth=10):
+ """ Print a list of (key: value) pairs, with column alignment. """
+ format = "%-"+str(keywidth)+"s %s\n"
+
+ outstr = ''
+ for key, val in lst:
+ outstr += format % (key+':',val)
+
+ return outstr
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git
More information about the debian-science-commits
mailing list