summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-07-06 19:44:50 +1200
committerLars Wirzenius <liw@liw.fi>2010-07-06 19:44:50 +1200
commitab4870473d5c42fef21ac1693a5b484ee33d0542 (patch)
tree07524f2defd768e012a44e991a2cc16886e36191
parent7a858dde6bc97df244a907f9828742ab0eaa57d7 (diff)
downloadobnam-ab4870473d5c42fef21ac1693a5b484ee33d0542.tar.gz
Add plugin to register LocalFS with the app's VfsFactory.
This required changing a few places to using LocalFS directory, rather than via VfsFactory, since it makes no sense to have to load plugins in unit test suites just for this, especially since the unit tests will be using local files anyway.
-rwxr-xr-xblackboxtest6
-rw-r--r--obnamlib/plugins/vfs_local_plugin.py29
-rw-r--r--obnamlib/store_tests.py2
-rw-r--r--obnamlib/vfs.py19
-rw-r--r--without-tests1
5 files changed, 46 insertions, 11 deletions
diff --git a/blackboxtest b/blackboxtest
index 3621cb42..42abe3f2 100755
--- a/blackboxtest
+++ b/blackboxtest
@@ -388,8 +388,7 @@ class ReusesChunks(BlackBoxTest):
self.backup(store, [data])
restored = self.restore(store)
self.verify(data, restored)
- fsf = obnamlib.VfsFactory()
- fs = fsf.new(store)
+ fs = obnamlib.LocalFS(store)
s = obnamlib.Store(fs, obnamlib.DEFAULT_NODE_SIZE,
obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE)
s.open_host(self.hostid)
@@ -410,8 +409,7 @@ class UsesChunkGroups(BlackBoxTest):
self.backup(store, [data])
restored = self.restore(store)
self.verify(data, restored)
- fsf = obnamlib.VfsFactory()
- fs = fsf.new(store)
+ fs = obnamlib.LocalFS(store)
s = obnamlib.Store(fs, obnamlib.DEFAULT_NODE_SIZE,
obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE)
s.open_host(self.hostid)
diff --git a/obnamlib/plugins/vfs_local_plugin.py b/obnamlib/plugins/vfs_local_plugin.py
new file mode 100644
index 00000000..ff0fc048
--- /dev/null
+++ b/obnamlib/plugins/vfs_local_plugin.py
@@ -0,0 +1,29 @@
+# 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/>.
+
+
+import logging
+import os
+import re
+import stat
+
+import obnamlib
+
+
+class VfsLocalPlugin(obnamlib.ObnamPlugin):
+
+ def enable(self):
+ self.app.fsf.register('', obnamlib.LocalFS)
+
diff --git a/obnamlib/store_tests.py b/obnamlib/store_tests.py
index 38b8daef..5784ce66 100644
--- a/obnamlib/store_tests.py
+++ b/obnamlib/store_tests.py
@@ -654,7 +654,7 @@ class StoreGenspecTests(unittest.TestCase):
self.tempdir = tempfile.mkdtemp()
storedir = os.path.join(self.tempdir, 'store')
- fs = obnamlib.VfsFactory().new(storedir)
+ fs = obnamlib.LocalFS(storedir)
self.store = obnamlib.Store(fs, obnamlib.DEFAULT_NODE_SIZE,
obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE)
self.store.lock_host('hostname')
diff --git a/obnamlib/vfs.py b/obnamlib/vfs.py
index c3ff6e92..c539bbcb 100644
--- a/obnamlib/vfs.py
+++ b/obnamlib/vfs.py
@@ -42,7 +42,7 @@ class VirtualFileSystem(object):
for the relative paths: directory components separated by
slashes, and an initial slash indicating the root of the
filesystem (in this case, the base URL).
-
+
'''
def __init__(self, baseurl):
@@ -209,14 +209,21 @@ class VirtualFileSystem(object):
class VfsFactory:
'''Create new instances of VirtualFileSystem.'''
-
+
+ def __init__(self):
+ self.implementations = {}
+
+ def register(self, scheme, implementation):
+ if scheme in self.implementations:
+ raise obnamlib.Error('URL scheme %s already registered' % scheme)
+ self.implementations[scheme] = implementation
+
def new(self, url):
'''Create a new VFS appropriate for a given URL.'''
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
- if scheme == 'sftp':
- return obnamlib.SftpFS(url)
- else:
- return obnamlib.LocalFS(url)
+ if scheme in self.implementations:
+ return self.implementations[scheme](url)
+ raise obnamlib.Error('Unknown VFS type %s' % url)
class VfsTests(object): # pragma: no cover
diff --git a/without-tests b/without-tests
index 36388eb8..97c8ed22 100644
--- a/without-tests
+++ b/without-tests
@@ -18,3 +18,4 @@
./obnamlib/plugins/forget_plugin.py
./obnamlib/plugins/fsck_plugin.py
+./obnamlib/plugins/vfs_local_plugin.py