From e8fa01d92f8d85ae52c9171d156d66a9088e5bd2 Mon Sep 17 00:00:00 2001 From: Valerio Mariani <valerio.mariani@desy.de> Date: Sat, 30 Sep 2017 01:32:54 -0700 Subject: [PATCH] Added function to create soft links (Work by Tom Grant) --- cfel_cxi.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cfel_cxi.py b/cfel_cxi.py index ccb4beb..86b4983 100644 --- a/cfel_cxi.py +++ b/cfel_cxi.py @@ -287,7 +287,7 @@ class CXIWriter: """Writes a simple, non-stack entry in the file. Writes a simple, non-stack entry in the file, at the specified path. A simple entry can be written at all times, - before or after the stack initialization. THe user must provide a name that identifies the entry for further + before or after the stack initialization. The user must provide a name that identifies the entry for further operations (for example, creating a link). Args: @@ -384,6 +384,31 @@ class CXIWriter: self._fh[path] = link_target + + def create_softlink_to_group(self, group, path, overwrite=False): + """Creates a link to an HDF5 group. + + Creates a soft link to an HDF5 group (as opposed to a simple entry or stack). If a link or entry already exists at + the specified path, it is deleted and replaced only if the value of the overwrite parameter is True. + + Args: + + group (str): internal HDF5 path of the group to which the link points. + + path (str): path in the hdf5 where the link is created. + + overwrite (bool): if set to True, an entry already existing at the same location will be overwritten. If set + to False, an attempt to overwrite an entry will raise an error. + """ + + if path in self._fh: + if overwrite is True: + del (self._fh[path]) + else: + raise RuntimeError('Cannot create the link. An entry already exists at the specified path.') + + self._fh[path] = h5py.SoftLink(group) + def initialize_stacks(self): """Initializes the stacks. -- GitLab