diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-10 20:37:35 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-10 20:37:35 +1200 |
commit | 83bfb3def57a68ec2d68442437eee9bf461f2257 (patch) | |
tree | a7adf42e834e838138b1c2920b37714146053f58 | |
parent | ab4870473d5c42fef21ac1693a5b484ee33d0542 (diff) | |
download | obnam-83bfb3def57a68ec2d68442437eee9bf461f2257.tar.gz |
Move SftpFS into a plugin and start getting it to work.
Add test-sftpfs to test it. Since it requires access to a
working sftp server, can't run the tests using normal
unit tests, unless I create a dummy sftp server, and I
don't want to do that, so this is good enough for now.
Also make the plugins directory be a module so that I can
import from the sftp plugin in test-sftpfs.
-rw-r--r-- | obnamlib/plugins/__init__.py | 0 | ||||
-rw-r--r-- | obnamlib/plugins/sftp_plugin.py (renamed from obnamlib/vfs_sftp.py) | 26 | ||||
-rw-r--r-- | test-sftpfs | 48 | ||||
-rw-r--r-- | without-tests | 5 |
4 files changed, 73 insertions, 6 deletions
diff --git a/obnamlib/plugins/__init__.py b/obnamlib/plugins/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/obnamlib/plugins/__init__.py diff --git a/obnamlib/vfs_sftp.py b/obnamlib/plugins/sftp_plugin.py index e2ba0073..128fa253 100644 --- a/obnamlib/vfs_sftp.py +++ b/obnamlib/plugins/sftp_plugin.py @@ -22,7 +22,15 @@ import pwd import stat import urlparse -import paramiko +# As of 2010-07-10, Debian's paramiko package triggers +# RandomPool_DeprecationWarning. This will eventually be fixed. Until +# then, there is no point in spewing the warning to the user, who can't +# do nothing. +# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=586925 +import warnings +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + import paramiko import obnamlib @@ -31,10 +39,14 @@ class SftpFS(obnamlib.VirtualFileSystem): """A VFS implementation for SFTP.""" - def __init__(self, baseurl, progress): - obnamlib.VirtualFileSystem.__init__(self, baseurl, progress) + def __init__(self, baseurl): + obnamlib.VirtualFileSystem.__init__(self, baseurl) + self.reinit(baseurl) self.first_lutimes = True + def reinit(self, baseurl): + self.baseurl = baseurl + def connect(self): user = host = port = path = None scheme, netloc, path, query, fragment = urlparse.urlsplit(self.baseurl) @@ -49,7 +61,7 @@ class SftpFS(obnamlib.VirtualFileSystem): else: host = netloc port = 22 - if path.startswith("/~/"): + if path.startswith('/~/'): path = path[3:] self.basepath = path self.transport = paramiko.Transport((host, port)) @@ -202,3 +214,9 @@ class SftpFS(obnamlib.VirtualFileSystem): def overwrite_file(self, relative_path, contents): self.write_helper(relative_path, 'w', contents) + +class SftpPlugin(obnamlib.ObnamPlugin): + + def enable(self): + self.app.fsf.register('sftp', SftpFS) + diff --git a/test-sftpfs b/test-sftpfs new file mode 100644 index 00000000..06b98b93 --- /dev/null +++ b/test-sftpfs @@ -0,0 +1,48 @@ +#!/usr/bin/python +# Copyright 2010 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +'''Test SftpFS. + +This can't be part of the normal unit tests, since it requires access +to a (real) ssh server. + +''' + + +import os +import unittest + +import obnamlib +import obnamlib.plugins.sftp_plugin + + +class SftpTests(unittest.TestCase): + + def setUp(self): + self.baseurl = os.environ['OBNAM_SFTP_TEST'] + self.fs = obnamlib.plugins.sftp_plugin.SftpFS(self.baseurl) + self.fs.connect() + + def tearDown(self): + self.fs.close() + + def test_ok(self): + self.assert_(True) + + +if __name__ == '__main__': + unittest.main() diff --git a/without-tests b/without-tests index 97c8ed22..42660e06 100644 --- a/without-tests +++ b/without-tests @@ -3,7 +3,6 @@ ./obnamlib/app.py ./obnamlib/status.py ./obnamlib/vfs.py -./obnamlib/vfs_sftp.py ./obnamlib/objs.py ./obnamlib/plugins/foo_plugin.py ./obnamlib/plugins/backup_plugin.py @@ -15,7 +14,9 @@ ./test-plugins/oldhello_plugin.py ./test-plugins/aaa_hello_plugin.py ./test-plugins/wrongversion_plugin.py - ./obnamlib/plugins/forget_plugin.py ./obnamlib/plugins/fsck_plugin.py ./obnamlib/plugins/vfs_local_plugin.py +./obnamlib/plugins/sftp_plugin.py + +./obnamlib/plugins/__init__.py |