Support python-sendfile 2.x
authorNikos Skalkotos <skalkoto@grnet.gr>
Wed, 16 Jan 2013 15:04:44 +0000 (17:04 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Wed, 16 Jan 2013 15:13:34 +0000 (17:13 +0200)
Support both versions (1.2.x and 2.x) of python-sendfile. In
v1.2.x (py-sendfile) the returning value of the sendfile function is a
tuple, where in v2.x (pysendfile) it's a simple integer.

image_creator/disk.py
setup.py

index 4209462..0a197c2 100644 (file)
@@ -480,8 +480,15 @@ class DiskDevice(object):
                 progressbar.next()
                 while left > 0:
                     length = min(left, blocksize)
                 progressbar.next()
                 while left > 0:
                     length = min(left, blocksize)
-                    _, sent = sendfile(dst.fileno(), src.fileno(), offset,
-                                       length)
+                    sent = sendfile(dst.fileno(), src.fileno(), offset, length)
+
+                    # Workaround for python-sendfile API change. In
+                    # python-sendfile 1.2.x (py-sendfile) the returning value
+                    # of sendfile is a tuple, where in version 2.x (pysendfile)
+                    # it is just a sigle integer.
+                    if isinstance(sent, tuple):
+                        sent = sent[1]
+
                     offset += sent
                     left -= sent
                     progressbar.goto((size - left) // MB)
                     offset += sent
                     left -= sent
                     progressbar.goto((size - left) // MB)
index 358d5a6..cf10237 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -48,7 +48,7 @@ setup(
     license='BSD',
     packages=find_packages(),
     include_package_data=True,
     license='BSD',
     packages=find_packages(),
     include_package_data=True,
-    install_requires=['sh', 'ansicolors', 'progress>=1.0.2', 'py-sendfile'],
+    install_requires=['sh', 'ansicolors', 'progress>=1.0.2'],
     entry_points={
         'console_scripts': [
                 'snf-image-creator = image_creator.main:main',
     entry_points={
         'console_scripts': [
                 'snf-image-creator = image_creator.main:main',