Exemplo n.º 1
0
 def __delitem__(self, path):
     test = self._node[datapath(path)]
     if owner(test) == self._codelet.path:
         del self._node[datapath(path)]
     else:
         raise ValueError("%s trying to remove data created by %s"
                          % (str(self._codelet.path), str(owner(test))))
Exemplo n.º 2
0
 def open_internal_file(self, path, mode='r', creator=None):
     # path is always relative to the root group
     if path.startswith('/'):
         path = path[1:]
     if not path.startswith('data/') \
        and not path.startswith('documentation/'):
         raise IOError((13, "Permission denied: '%s'" % path))
     if creator is None:
         creator = ExternalCode(self)
     if mode[0] in ['r', 'a']:
         ds = self.file[path]
     elif mode[0] == 'w':
         test = self.file.get(path, None)
         if test is not None:
             if not creator.owns(test):
                 raise ValueError("%s trying to overwrite data"
                                  " created by %s"
                                  % (creator.path, owner(test)))
             del self.file[path]
         ds = self.file.create_dataset(
                    path, shape = (0,), dtype = np.uint8,
                    chunks = (100,), maxshape = (None,))
     else:
         raise ValueError("unknown file mode %s" % mode)
     return InternalFile(ds, mode)
Exemplo n.º 3
0
 def _wrap_and_track_dependencies(self, node):
     ap_type = datatype(node)
     if ap_type == 'reference':
         from activepapers.storage import dereference
         paper, node = dereference(node)
         if isinstance(node, h5py.Group):
             node = DataGroup(paper, None, node, None, None)
         else:
             node = DatasetWrapper(None, node, None)
     else:
         if self._codelet is not None:
             if ap_type is not None and ap_type != "group":
                 self._codelet.add_dependency(node.name
                                              if self._data_item is None
                                              else self._data_item.name)
             codelet = owner(node)
             if codelet is not None \
                and datatype(self._node[codelet]) == "calclet":
                 self._codelet.add_dependency(codelet)
         if isinstance(node, h5py.Group):
             node = DataGroup(self._paper, self, node,
                              self._codelet, self._data_item)
         else:
             node = DatasetWrapper(self, node, self._codelet)
     return node
Exemplo n.º 4
0
 def open_internal_file(self, path, mode='r', encoding=None, creator=None):
     # path is always relative to the root group
     if path.startswith('/'):
         path = path[1:]
     if not path.startswith('data/') \
        and not path.startswith('documentation/'):
         raise IOError((13, "Permission denied: '%s'" % path))
     if creator is None:
         creator = ExternalCode(self)
     if mode[0] in ['r', 'a']:
         ds = self.file[path]
     elif mode[0] == 'w':
         test = self.file.get(path, None)
         if test is not None:
             if not creator.owns(test):
                 raise ValueError("%s trying to overwrite data"
                                  " created by %s" %
                                  (creator.path, owner(test)))
             del self.file[path]
         ds = self.file.create_dataset(path,
                                       shape=(0, ),
                                       dtype=np.uint8,
                                       chunks=(100, ),
                                       maxshape=(None, ))
     else:
         raise ValueError("unknown file mode %s" % mode)
     return InternalFile(ds, mode, encoding)
Exemplo n.º 5
0
 def owned(group):
     nodes = []
     for node in group.values():
         if owner(node) == codelet:
             nodes.append(node.name)
         elif isinstance(node, h5py.Group) \
            and datatype(node) != 'data':
             nodes.extend(owned(node))
     return nodes
Exemplo n.º 6
0
 def owned(group):
     nodes = []
     for node in group.values():
         if owner(node) == codelet:
             nodes.append(node.name)
         elif isinstance(node, h5py.Group) \
            and datatype(node) != 'data':
             nodes.extend(owned(node))
     return nodes
Exemplo n.º 7
0
 def __repr__(self):
     codelet = owner(self._node)
     if codelet is None:
         owned = ""
     else:
         owned = " generated by %s" % codelet
     items = list(self._node)
     if not items:
         lines = ["Empty group %s%s" % (self._node.name, owned)]
     else:
         lines = ["Group %s%s containing" % (self._node.name, owned)]
         lines.extend("   "+i for i in items)
     return "\n".join(lines)
Exemplo n.º 8
0
 def __repr__(self):
     codelet = owner(self._node)
     if codelet is None:
         owned = ""
     else:
         owned = " generated by %s" % codelet
     lines = ["Dataset %s%s" % (self._node.name, owned)]
     nelems = np.product(self._node.shape)
     if nelems < 100:
         lines.append(str(self._node[...]))
     else:
         lines.append("shape %s, dtype %s"
                      % (repr(self._node.shape), str(self._node.dtype)))
     return "\n".join(lines)
Exemplo n.º 9
0
 def replace_by_dummy(self, item_name):
     item = self.file[item_name]
     codelet = owner(item)
     assert codelet is not None
     dtype = datatype(item)
     mtime = mod_time(item)
     deps = item.attrs.get('ACTIVE_PAPER_DEPENDENCIES')
     del self.file[item_name]
     ds = self.file.create_dataset(item_name,
                                   data=np.zeros((), dtype=np.int))
     stamp(ds, dtype,
           dict(ACTIVE_PAPER_GENERATING_CODELET=codelet,
                ACTIVE_PAPER_DEPENDENCIES=list(deps)))
     timestamp(ds, mtime)
     ds.attrs['ACTIVE_PAPER_DUMMY_DATASET'] = True
Exemplo n.º 10
0
 def replace_by_dummy(self, item_name):
     item = self.file[item_name]
     codelet = owner(item)
     assert codelet is not None
     dtype = datatype(item)
     mtime = mod_time(item)
     deps = item.attrs.get('ACTIVE_PAPER_DEPENDENCIES')
     del self.file[item_name]
     ds = self.file.create_dataset(item_name,
                                   data=np.zeros((), dtype=np.int))
     stamp(ds, dtype,
           dict(ACTIVE_PAPER_GENERATING_CODELET=codelet,
                ACTIVE_PAPER_DEPENDENCIES=list(deps)))
     timestamp(ds, mtime)
     ds.attrs['ACTIVE_PAPER_DUMMY_DATASET'] = True
Exemplo n.º 11
0
 def owns(self, node):
     return owner(node) == self.path