Update copyright dates for changes files
[kamaki] / kamaki / clients / utils / __init__.py
index bb9dc72..abe0802 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011-2012 GRNET S.A. All rights reserved.
+# Copyright 2013-2014 GRNET S.A. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
@@ -90,3 +90,18 @@ def path4url(*args):
     while '//' in r:
         r = r.replace('//', '/')
     return ('/%s' % r.strip('/')) if r else ''
+
+
+def readall(openfile, size, retries=7):
+    """Read a file until size is reached"""
+    remains = size if size > 0 else 0
+    buf = ''
+    for i in range(retries):
+        tmp_buf = openfile.read(remains)
+        if tmp_buf:
+            buf += tmp_buf
+            remains -= len(tmp_buf)
+            if remains > 0:
+                continue
+        return buf
+    raise IOError('Failed to read %s bytes from file' % size)