From cdecddf3455b2170c28883233197823d7343a4e1 Mon Sep 17 00:00:00 2001 From: "g@localhost.localdomain" Date: Sun, 24 Sep 2006 22:33:52 +0200 Subject: [PATCH] Error callback instead of print, also note that fast is private --- pysize/core/compute_size.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pysize/core/compute_size.py b/pysize/core/compute_size.py index 2d60d46..e4d6351 100644 --- a/pysize/core/compute_size.py +++ b/pysize/core/compute_size.py @@ -9,7 +9,10 @@ from pysize.core.pysize_global_fs_cache import cache_get_dir_size size_observable = observable() -def fast(path, dir_ino): +def log_error(text, e): + print text, e + +def _fast(path, dir_ino, error_cb): """Return the size of the file or directory at path, using or updating the cache. dir_ino is the inode of the directory containing the path, it is used only with hardlinks. @@ -26,7 +29,7 @@ def fast(path, dir_ino): cookie = chdir_browsing.init(path) try: for child in chdir_browsing.listdir(cookie): - size += fast(child, dir_ino) + size += _fast(child, dir_ino, error_cb) finally: chdir_browsing.finalize(cookie) cache_add_dir(dev_ino, size) @@ -41,10 +44,10 @@ def fast(path, dir_ino): size = st.st_blocks * 512 return size except OSError, e: - print 'size.fast(%s)' % (path), e + error_cb('size.fast(%s)' % (path), e) return 0 -def slow(path): +def slow(path, error_cb=log_error): """Same as _size_fast(path, dir_ino), except that dir_ino is computed.""" def parent_inode(): """Return the inode of the parent directory""" @@ -57,6 +60,6 @@ def slow(path): try: parent_ino = parent_inode() except OSError, e: - print 'size.slow(%s)' % (path), e + error_cb('size.slow(%s)' % (path), e) return 0 - return fast(path, parent_ino) + return _fast(path, parent_ino, error_cb) -- 2.11.4.GIT