X-Git-Url: https://code.grnet.gr/git/snf-image-creator/blobdiff_plain/0dbc4db9360f0effe8b346607a6c0a432863609c..fba0968870e13efbe1926fa43363aa56efd79ee4:/image_creator/util.py?ds=sidebyside diff --git a/image_creator/util.py b/image_creator/util.py index 61cc2a6..8730143 100644 --- a/image_creator/util.py +++ b/image_creator/util.py @@ -34,6 +34,8 @@ import sys import sh import hashlib +import time +import os class FatalError(Exception): @@ -54,12 +56,34 @@ def get_command(command): return find_sbin_command(command, e) +def try_fail_repeat(command, *args): + + times = (0.1, 0.5, 1, 2) + i = iter(times) + while True: + try: + command(*args) + return + except sh.ErrorReturnCode: + try: + wait = i.next() + except StopIteration: + break + time.sleep(wait) + + raise FatalError("Command: `%s %s' failed" % (command, " ".join(args))) + + +def free_space(dirname): + stat = os.statvfs(dirname) + return stat.f_bavail * stat.f_frsize + + class MD5: def __init__(self, output): self.out = output def compute(self, filename, size): - MB = 2 ** 20 BLOCKSIZE = 4 * MB # 4MB