Skip to content

Instantly share code, notes, and snippets.

import os
"""
as bash command: du -sb dir
+4906: add 4096bytes for the top dir
"""
def du_sb(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)])) + 4096;
def get_total_file_size(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)]) if os.path.isfile(f))
@liaoyw
liaoyw / robust_run.py
Created November 19, 2014 05:05
retry function for `retry` times
import functools
import sys
def robust(expected, retry=3):
def wrapper(func):
@functools.wraps(func)
def robust_run(*args, **kw):
n = 0;
result = None
while n < retry: