summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-01-30 11:03:34 +0200
committerLars Wirzenius <liw@liw.fi>2016-01-30 11:05:59 +0200
commit2212a72a59641705a09533e5ad05b447ce4574ac (patch)
tree1cab5d7188dbf637811847e830c34b8f032ab5d9
parent428abfed9b507a6d20e35eafda695f566ed3941a (diff)
downloadobnam-2212a72a59641705a09533e5ad05b447ce4574ac.tar.gz
Fix check for paramiko version for 1.7.8...1.10.4
-rw-r--r--NEWS12
-rw-r--r--obnamlib/plugins/sftp_plugin.py28
2 files changed, 39 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 2061b691..f8620c23 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,18 @@ development, called `green-albatross`. It is **NOT** meant for real
use. It is likely to change in incompatible ways without warning. Do
not use it unless you're willing to lose your backup.
+Version 1.19.1, released UNRELEASED
+---------------------------------
+
+Bug fix:
+
+* The check for paramiko version turned out not to work with
+ versions 1.7.8 through 1.10.4, due to the
+ `paramiko.__version_info__` variable being missing. It's there in
+ earlier and later versions. Lars Wirzenius added code to make the
+ check work if the `paramiko.__version__` variable is there. Jan
+ Niggemann provided research and testing.
+
Version 1.19, released 2016-01-15
---------------------------------
diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py
index 47a3003c..ab87368f 100644
--- a/obnamlib/plugins/sftp_plugin.py
+++ b/obnamlib/plugins/sftp_plugin.py
@@ -80,6 +80,11 @@ class HardlinkError(obnamlib.ObnamError):
'''
+class UnknownParamikoVersion(obnamlib.ObnamError):
+
+ msg = '''Cannot find out version of Paramiko.'''
+
+
def ioerror_to_oserror(method):
'''Decorator to convert an IOError exception to OSError.
@@ -574,12 +579,33 @@ class SftpFS(obnamlib.VirtualFileSystem):
'''
- if paramiko.__version_info__ < (1, 16):
+ version_info = self._get_paramiko_version_info()
+ if version_info < (1, 16):
f.prefetch()
else:
file_size = self.lstat(pathname).st_size
f.prefetch(file_size)
+ def _get_paramiko_version_info(self):
+ '''Get the __version_info__ tuple for paramiko.
+
+ Some versions of paramiko (1.7.8 to 1.10.4, according to
+ research by Jan Niggemann) have no __version_info__ tuple. We
+ need that tuple to do version comparisons.
+
+ This method constructs the tuple from paramiko.__version__, if
+ paramiko.__version_info__ is missing. If __version__ is also
+ missing, it raises an exception.
+
+ '''
+
+ if hasattr(paramiko, '__version_info__'):
+ return paramiko.__version_info__
+ elif hasattr(paramiko, '__version__'):
+ return tuple(int(x) for x in paramiko.__version__.split('.'))
+ else:
+ raise UnknownParamikoVersion()
+
@ioerror_to_oserror
def write_file(self, pathname, contents):
mode = 'wbx'