def __init__(self, filename, mode="r", timestamp=None, creator=None, compression=zipfile.ZIP_DEFLATED, attrs={}, **kw): fn = tempfile.mkdtemp() self.os_path = fn self.root_node = self self.filename = filename self.mode = mode self.compression = compression file_exists = os.path.exists(filename) if file_exists and (mode == "a" or mode == "r"): zipfile.ZipFile(filename).extractall(self.os_path) Node.__init__(self, parent_node=self, path="/") if mode == "a" or mode == "w": #os.mkdir(os.path.join(self.os_path, self.path.lstrip("/"))) if timestamp is None: timestr = iso8601.now() else: # If given a time string, check that it is valid try: timestamp = iso8601.parse_date(timestamp) except TypeError: pass timestr = iso8601.format_date(timestamp) attrs['NX_class'] = 'NXroot' attrs['file_name'] = filename attrs['file_time'] = timestr attrs['NeXus_version'] = __version__ if creator is not None: attrs['creator'] = creator self.attrs.update(attrs) self.attrs._write()
def __init__(self, filename, mode, timestamp=None, creator=None, compression=zipfile.ZIP_DEFLATED, rootpath=None, attrs={}, **kw): fn = tempfile.mkdtemp() # os.close(fd) # to be opened by name self.fn = fn self.filename = filename self.mode = mode self.compression = compression if rootpath is None: rootpath = filename.split('.')[0] self.path = rootpath preexisting = os.path.exists(os.path.join(self.fn, self.path)) if (mode == "a" and not preexisting) or mode == "w": os.mkdir(os.path.join(self.fn, self.path)) if timestamp is None: timestr = iso8601.now() else: # If given a time string, check that it is valid try: timestamp = iso8601.parse_date(timestamp) except TypeError: pass timestr = iso8601.format_date(timestamp) attrs['NX_class'] = 'NXroot' attrs['file_name'] = filename attrs['file_time'] = timestr attrs['NeXus_version'] = __version__ if creator is not None: attrs['creator'] = creator self.attrs = attrs
def __init__(self, filename, mode="r", timestamp=None, creator=None, compression=zipfile.ZIP_DEFLATED, attrs={}, os_path=None, **kw): self.readonly = (mode == "r") Node.__init__(self, parent_node=None, path="/") if self.readonly: self.zipfile = zipfile.ZipFile(filename) self.attrs = self.makeAttrs() self.filename = filename self.mode = mode self.compression = compression file_exists = os.path.exists(filename) if not self.readonly: if os_path is None: fn = tempfile.mkdtemp() self.os_path = fn else: self.os_path = os_path if file_exists and (mode == "a"): zipfile.ZipFile(filename).extractall(self.os_path) if timestamp is None: timestr = iso8601.now() else: # If given a time string, check that it is valid try: timestamp = iso8601.parse_date(timestamp) except TypeError: pass timestr = iso8601.format_date(timestamp) attrs['NX_class'] = 'NXroot' attrs['file_name'] = filename attrs['file_time'] = timestr attrs['NeXus_version'] = __version__ if creator is not None: attrs['creator'] = creator self.attrs.update(attrs) self.attrs._write()
def on_open(self, request): self.channel._publisher_connect(self) print now(), "publisher::%s" % self.endpoint, "open" return True
def on_close(self): print now(), "publisher::%s" % self.endpoint, "close" self.channel._publisher_disconnect(self)
def on_open(self, request): print now(), "subscriber::%s" % self.endpoint, "open" self.channel._subscriber_connect(self) return True
def on_close(self): print now(), "subscriber::%s" % self.endpoint, "close" self.channel._subscriber_disconnect(self)
def on_open(self, request): self.channel._publisher_connect(self) print now(), "publisher::%s"%self.endpoint, "open" return True
def on_close(self): print now(), "publisher::%s"%self.endpoint, "close" self.channel._publisher_disconnect(self)
def on_open(self, request): print now(), "subscriber::%s"%self.endpoint, "open" self.channel._subscriber_connect(self) return True
def on_close(self): print now(), "subscriber::%s"%self.endpoint, "close" self.channel._subscriber_disconnect(self)