Source code for pyrocko.io.io_common

# http://pyrocko.org - GPLv3
#
# The Pyrocko Developers, 21st Century
# ---|P------/S----------~Lg----------

import os


[docs]class FileError(Exception): def __init__(self, *args, **kwargs): Exception.__init__(self, *args, **kwargs) self.context = {}
[docs] def set_context(self, k, v): self.context[k] = v
def __str__(self): s = Exception.__str__(self) if not self.context: return s lines = [] for k in sorted(self.context.keys()): lines.append('%s: %s\n' % (k, self.context[k])) return '%s\n%s' % (s, '\n'.join(lines))
[docs]class FileLoadError(FileError): '''Raised when a problem occurred while loading of a file.'''
[docs]class FileSaveError(FileError): '''Raised when a problem occurred while saving of a file.'''
[docs]def get_stats(filename): try: s = os.stat(filename) return float(s.st_mtime), s.st_size except OSError as e: raise FileLoadError(e)