Ejemplo n.º 1
0
 def __init__(self,
              parent_node,
              path="/",
              nxclass="NXCollection",
              attrs={}):
     self.root_node = self if parent_node is None else parent_node.root_node
     if path.startswith("/"):
         # absolute path
         self.path = path
     else:
         # relative
         self.path = os.path.join(parent_node.path, path)
     self.os_path = parent_node.os_path
     preexisting = os.path.exists(
         os.path.join(self.os_path, self.path.lstrip("/")))
     if not preexisting:
         os.mkdir(os.path.join(self.os_path, self.path.lstrip("/")))
         attrs['NX_class'] = nxclass.encode('UTF-8')
     #print "making things: ", os.path.join(self.os_path, self.path.lstrip("/"))
     self.attrs = JSONBackedDict(
         os.path.join(self.os_path, self.path.lstrip("/"),
                      self._attrs_filename))
     self.attrs.update(attrs)
     self.fields = JSONBackedDict(
         os.path.join(self.os_path, self.path.lstrip("/"),
                      self._fields_filename))
Ejemplo n.º 2
0
 def makeAttrs(self):
     if self.root.readonly:
         return json.loads(
             self.root.open(self.path + self._attrs_suffix, "r").read())
     else:
         return JSONBackedDict(
             os.path.join(self.os_path,
                          self.path.lstrip("/") + self._attrs_suffix))