diff --git a/lib/utils/io.py b/lib/utils/io.py index 8c785f7d791dcc6c08ea958053fa6e8e05bdb16d..ed55f92d6cef847be23a49c0736a6ad197f71be1 100644 --- a/lib/utils/io.py +++ b/lib/utils/io.py @@ -72,6 +72,25 @@ def ErrnoOrStr(err): return detail +class FileStatHelper: + """Helper to store file handle's C{fstat}. + + Useful in combination with L{ReadFile}'s C{preread} parameter. + + """ + def __init__(self): + """Initializes this class. + + """ + self.st = None + + def __call__(self, fh): + """Calls C{fstat} on file handle. + + """ + self.st = os.fstat(fh.fileno()) + + def ReadFile(file_name, size=-1, preread=None): """Reads a file. diff --git a/lib/watcher/__init__.py b/lib/watcher/__init__.py index 915dea031e6c7a153f491b57ecfa43f9197ffa16..0325cce155df6222b360d29826c687a8c717c66f 100644 --- a/lib/watcher/__init__.py +++ b/lib/watcher/__init__.py @@ -410,23 +410,6 @@ def _UpdateInstanceStatus(filename, instances): for inst in instances]) -class _StatCb: - """Helper to store file handle's C{fstat}. - - """ - def __init__(self): - """Initializes this class. - - """ - self.st = None - - def __call__(self, fh): - """Calls C{fstat} on file handle. - - """ - self.st = os.fstat(fh.fileno()) - - def _ReadInstanceStatus(filename): """Reads an instance status file. @@ -440,7 +423,7 @@ def _ReadInstanceStatus(filename): """ logging.debug("Reading per-group instance status from '%s'", filename) - statcb = _StatCb() + statcb = utils.FileStatHelper() try: content = utils.ReadFile(filename, preread=statcb) except EnvironmentError, err: