Skip to content

Commit f76a283

Browse files
committed
Cleanup: Use file references whenever appropriate
- Removed hacky parent traversal for getting root objects like the top level metadata container. - Removed H5Group utility functions that are now obsolete. - Containers that need to do a search from the root object to delete objects now use the file reference.
1 parent 2fc194e commit f76a283

File tree

3 files changed

+4
-76
lines changed

3 files changed

+4
-76
lines changed

nixio/container.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ def __delitem__(self, item):
5757
self._itemclass.__name__)
5858
)
5959

60-
root = self._backend.h5root
61-
if not root:
62-
root = self._parent._h5group
63-
root.delete_all([item.id])
60+
self._file._h5group.delete_all([item.id])
6461

6562
def __iter__(self):
6663
for group in self._backend:
@@ -122,8 +119,7 @@ def __delitem__(self, item):
122119
# the root block
123120
secids = [s.id for s in item.find_sections()]
124121

125-
root = self._backend.file
126-
root.delete_all(secids)
122+
self._file._h5group.delete_all(secids)
127123

128124

129125
class SourceContainer(Container):
@@ -146,9 +142,7 @@ def __delitem__(self, item):
146142
# the root block
147143
srcids = [s.id for s in item.find_sources()]
148144
srcids.append(item.id)
149-
150-
root = self._backend.h5root
151-
root.delete_all(srcids)
145+
self._file._h5group.delete_all(srcids)
152146

153147

154148
class LinkContainer(Container):

nixio/hdf5/h5group.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
from .h5dataset import H5DataSet
1414
from ..datatype import DataType
15-
from ..block import Block
16-
from ..section import Section
1715

1816
from .. import util
19-
from ..exceptions import InvalidEntity
2017

2118

2219
class H5Group(object):
@@ -297,56 +294,6 @@ def change_id(_, igrp):
297294
g.visititems(change_id)
298295
return g
299296

300-
@property
301-
def file(self):
302-
"""
303-
An H5Group object which represents the file root.
304-
305-
:return: H5Group at '/'
306-
"""
307-
return H5Group(self.group.file, "/", create=False)
308-
309-
@property
310-
def h5root(self):
311-
"""
312-
Returns the H5Group of the Block or top-level Section which contains
313-
this object. Returns None if requested on the file root '/' or the
314-
/data or /metadata groups.
315-
316-
:return: Top level object containing this group (H5Group)
317-
"""
318-
pathparts = self.group.name.split("/")
319-
if len(pathparts) == 3:
320-
return self
321-
if self.group.name == "/":
322-
return None
323-
if len(pathparts) == 2:
324-
return None
325-
326-
return self.parent.h5root
327-
328-
@property
329-
def root(self):
330-
"""
331-
Returns the Block or top-level Section which contains this object.
332-
Returns None if requested on the file root '/' or the /data or
333-
/metadata groups.
334-
335-
:return: Top level object containing this group (Block or Section)
336-
"""
337-
h5root = self.h5root
338-
if h5root is None:
339-
return None
340-
topgroup = self.group.name.split("/")[1]
341-
if topgroup == "data":
342-
cls = Block
343-
return cls(h5root.parent, h5root)
344-
elif topgroup == "metadata":
345-
cls = Section
346-
return cls(h5root.parent, h5root)
347-
else:
348-
raise InvalidEntity
349-
350297
@property
351298
def parent(self):
352299
return self.create_from_h5obj(self._parent)

nixio/section.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,8 @@ def parent(self):
293293
"""
294294
if self._sec_parent is not None:
295295
return self._sec_parent
296-
rootmd = self._h5group.file.open_group("metadata")
297296
# BFS
298-
sections = [Section(self.file, None, sg) for sg in rootmd]
297+
sections = list(self.file.sections)
299298
if self in sections:
300299
# Top-level section
301300
return None
@@ -309,18 +308,6 @@ def parent(self):
309308

310309
return None
311310

312-
@property
313-
def file(self):
314-
"""
315-
Root file object.
316-
317-
:type: File
318-
"""
319-
par = self._parent
320-
while isinstance(par, Entity):
321-
par = par._parent
322-
return par
323-
324311
@property
325312
def referring_objects(self):
326313
objs = []

0 commit comments

Comments
 (0)