def open(self, filepath, mode): """Opens an hpss file""" #want to close any open files first try: if self._file: self.close() except ArchiveInterfaceError as ex: err_str = "Can't close previous hpss file before "\ "opening new one with error: " + str(ex) raise ArchiveInterfaceError(err_str) #try to open file try: fpath = un_abs_path(filepath) filename = os.path.join(self._prefix, path_info_munge(fpath)) self._filepath = filename hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() hpss_fopen = self._hpsslib.hpss_Fopen hpss_fopen.restype = c_void_p self._file = hpss_fopen(filename, mode) if self._file < 0: err_str = "Failed opening Hpss File, code: " + str(self._file) raise ArchiveInterfaceError(err_str) return self except Exception as ex: err_str = "Can't open hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def set_mod_time(self, mod_time): """Set the mod time for an hpss archive file """ try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() hpss.set_mod_time(mod_time) except Exception as ex: err_str = "Can't set hpss file mod time with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def status(self): """Get the status of a file in the hpss archive """ try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() return hpss.status() except Exception as ex: err_str = "Can't get hpss status with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def stage(self): """Stage an hpss file to the top level drive """ try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() hpss.stage() except Exception as ex: err_str = "Can't stage hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def close(self): """Close an HPSS File""" try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() rcode = self._hpsslib.hpss_Fclose(self._file) if rcode < 0: err_str = "Failed to close hpss file with code: "+str(rcode) raise ArchiveInterfaceError(err_str) self._file = None except Exception as ex: err_str = "Can't close hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def write(self, buf): """Write a file to the hpss archive""" try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() buf_char_p = cast(buf, c_char_p) rcode = self._hpsslib.hpss_Fwrite(buf_char_p, 1, len(buf), self._file) if rcode != len(buf): raise ArchiveInterfaceError("Short write for hpss file") except Exception as ex: err_str = "Can't write hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def write(self, buf): """Write a file to the hpss archive""" try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() buf_char_p = cast(buf, c_char_p) rcode = self._hpsslib.hpss_Fwrite( buf_char_p, 1, len(buf), self._file ) if rcode != len(buf): raise ArchiveInterfaceError("Short write for hpss file") except Exception as ex: err_str = "Can't write hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def close(self): """Close an HPSS File""" try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() rcode = self._hpsslib.hpss_Fclose(self._file) if rcode < 0: err_str = "Failed to close hpss file with code: " + str( rcode) raise ArchiveInterfaceError(err_str) self._file = None except Exception as ex: err_str = "Can't close hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def read(self, blocksize): """Read a file from the hpss archive""" try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() buf = create_string_buffer('\000'*blocksize) rcode = self._hpsslib.hpss_Fread(buf, 1, blocksize, self._file) if rcode < 0: err_str = "Failed During HPSS Fread,"\ "return value is: " + str(rcode) raise ArchiveInterfaceError(err_str) return buf.value except Exception as ex: err_str = "Can't read hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)
def read(self, blocksize): """Read a file from the hpss archive""" try: if self._file: hpss = HpssExtended(self._filepath, self._latency) hpss.ping_core() buf = create_string_buffer('\000' * blocksize) rcode = self._hpsslib.hpss_Fread(buf, 1, blocksize, self._file) if rcode < 0: err_str = "Failed During HPSS Fread,"\ "return value is: " + str(rcode) raise ArchiveInterfaceError(err_str) return buf.value except Exception as ex: err_str = "Can't read hpss file with error: " + str(ex) raise ArchiveInterfaceError(err_str)