[h5py] 66/455: Minor browse fixes

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 ef04428094ec702f524917089ef01064433ee000
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Fri Jul 4 06:40:44 2008 +0000

    Minor browse fixes
---
 h5py/browse.py | 71 +++++++++++++++++++++++++++++++++-------------------------
 h5py/h5g.pyx   |  2 +-
 setup.py       | 12 ++++++----
 3 files changed, 50 insertions(+), 35 deletions(-)

diff --git a/h5py/browse.py b/h5py/browse.py
index 61a5f29..cb8e011 100644
--- a/h5py/browse.py
+++ b/h5py/browse.py
@@ -11,13 +11,17 @@
 #-
 
 import cmd
+from getopt import gnu_getopt
 import os
-import posixpath
 from utils_hl import hbasename
+from posixpath import join, basename, dirname, normpath, isabs
 
 from h5py.highlevel import File, Group, Dataset, Datatype
 from h5py import h5g
 
+NAMES = {h5g.DATASET: "Dataset", h5g.GROUP: "Group", h5g.TYPE: "Named Type"}
+LS_FORMAT = " %-10s    %-10s"
+
 class _H5Browser(cmd.Cmd):
 
     """
@@ -71,15 +75,7 @@ class _H5Browser(cmd.Cmd):
         """ Correctly interpret the given path fragment, relative to the
             current path.
         """
-        apath = posixpath.join(self.path, path)
-        apath = posixpath.normpath(apath)
-        return apath
-
-    def get_candidates(path, criterion=lambda grp, name: True):
-        """ Get a list of candidates, in the group pointed to by
-            "path", which satisfy a particular criterion.
-        """
-        pass
+        return normpath(join(self.path,path))
 
     def do_exit(self, line):
         return True
@@ -94,12 +90,10 @@ class _H5Browser(cmd.Cmd):
         path = line.strip()
         if path == '': path = '/'
         path = self.abspath(path)
-        dname = posixpath.dirname(path)
-        bname = posixpath.basename(path)
-        print dname, bname
+        dname = dirname(path)
+        bname = basename(path)
         try:
-            pgrp = self.file[dname]
-            if bname != '' and not pgrp.id.get_objinfo(bname).type == h5g.GROUP:
+            if bname != '' and not self.file[dname].id.get_objinfo(bname).type == h5g.GROUP:
                 self._error('"%s" is not an HDF5 group' % bname)
             else:
                 self.path = path
@@ -108,30 +102,47 @@ class _H5Browser(cmd.Cmd):
 
     def complete_cd(self, text, line, begidx, endidx):
         text = text.strip()
-        grpname = posixpath.join(self.path,posixpath.dirname(text))
-        targetname = posixpath.basename(text)
-
-        try:
-            grp = self.file[grpname]
-            return [posixpath.join(grpname,x) for x in grp \
-                        if x.find(targetname) == 0 and \
-                        grp.id.get_objinfo(x).type == h5g.GROUP]
-        except:
-            return []
-
+        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 and \
+                    grp.id.get_objinfo(x).type == h5g.GROUP]
+        return rval
+    
     def do_ls(self, line):
         """ List contents of the specified group, or this one """
 
-        line = line.strip()
-        if line == '':
+        LONG_STYLE = False
+        try:
+            opts, args = gnu_getopt(line.split(), 'l')
+        except GetoptError, e:
+            self._error(e.msg.capitalize())
+            return
+
+        if '-l' in [ opt[0] for opt in opts]:
+            LONG_STYLE = True
+        if len(args) == 0:
             grpname = self.path
+        elif len(args) == 1:
+            grpname = self.abspath(args[0])
         else:
-            grpname = posixpath.join(self.path, line)
+            self._error("Too many arguments")
+            return
 
         try:
             grp = self.file[grpname]
+            if LONG_STYLE:
+                print LS_FORMAT % ("Name", "Type")
+                print LS_FORMAT % ("----", "----")
             for name in grp:
-                print name
+                typecode = grp.id.get_objinfo(name).type
+                pname = name if typecode != h5g.GROUP else name+'/'
+                if LONG_STYLE:
+                    print LS_FORMAT % (pname, NAMES[typecode])
+                else:
+                    print pname
         except:
             self._error('Can\'t list contents of group "%s"' % hbasename(grpname))
 
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index c12768a..561d59e 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -28,7 +28,7 @@ UNKNOWN  = H5G_UNKNOWN
 LINK     = H5G_LINK
 GROUP    = H5G_GROUP
 DATASET  = H5G_DATASET
-DATATYPE = H5G_TYPE
+TYPE = H5G_TYPE
 
 # Enumerated link types "H5G_link_t"
 LINK_ERROR = H5G_LINK_ERROR
diff --git a/setup.py b/setup.py
index 58d07fe..8f88295 100644
--- a/setup.py
+++ b/setup.py
@@ -188,11 +188,15 @@ DEF H5PY_DEBUG = %d
 DEF H5PY_API = "%d.%d"
 """ % (AUTO_HDR, API_VERS[0], API_VERS[1], DEBUG_LEVEL,API_VERS[0], API_VERS[1])
 
-cond_file = open(cond_path,'r')
-cond_present = cond_file.read()
-cond_file.close()
-if cond_present != cond:
+try:
+    cond_file = open(cond_path,'r')
+    cond_present = cond_file.read()
+    cond_file.close()
+    if cond_present != cond:
+        ENABLE_PYREX = True
+except IOError:
     ENABLE_PYREX = True
+    cond_present = ""
 
 # If for some reason the .c files are missing, Pyrex is required.
 if not all([os.path.exists(x+'.c') for x in pyrex_sources]):

-- 
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