From 8415ba1a3bb37257a70999bec722200bb42e41a4 Mon Sep 17 00:00:00 2001
From: Daira Hopwood <david-sarah@jacaranda.org>
Date: Fri, 17 May 2013 17:39:20 +0100
Subject: [PATCH] Refactoring to make backend configuration accessible from
 outside Client. refs #1971

Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
---
 src/allmydata/client.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/allmydata/client.py b/src/allmydata/client.py
index 9f56a7d1..6218d5b9 100644
--- a/src/allmydata/client.py
+++ b/src/allmydata/client.py
@@ -262,16 +262,14 @@ class Client(node.Node, pollmixin.PollMixin):
             self.write_config("permutation-seed", seed+"\n")
         return seed.strip()
 
-    def init_storage(self):
-        self.accountant = None
-        # Should we run a storage server (and publish it for others to use)?
-        if not self.get_config("storage", "enabled", True, boolean=True):
-            return
+    @classmethod
+    def configure_backend(cls, config):
+        """This is also called directly by the implementation of 'tahoe admin create-container'."""
 
-        storedir = os.path.join(self.basedir, self.STOREDIR)
+        storedir = os.path.join(config.basedir, cls.STOREDIR)
 
         # What sort of backend?
-        backendtype = self.get_config("storage", "backend", "disk")
+        backendtype = config.get_config("storage", "backend", "disk")
         if backendtype == "s3":
             backendtype = "cloud.s3"
         backendprefix = backendtype.partition('.')[0]
@@ -285,9 +283,18 @@ class Client(node.Node, pollmixin.PollMixin):
 
         if backendprefix not in backend_configurators:
             raise InvalidValueError("%s is not supported; it must start with one of %s"
-                                    % (quote_output("[storage]backend = " + backendtype), backend_configurators.keys()) )
+                                    % (quote_output("[storage]backend = " + backendtype),
+                                    backend_configurators.keys()) )
+
+        return (backend_configurators[backendprefix](storedir, config), storedir)
+
+    def init_storage(self):
+        self.accountant = None
+        # Should we run a storage server (and publish it for others to use)?
+        if not self.get_config("storage", "enabled", True, boolean=True):
+            return
 
-        backend = backend_configurators[backendprefix](storedir, self)
+        (backend, storedir) = self.configure_backend(self)
 
         if self.get_config("storage", "debug_discard", False, boolean=True):
             raise OldConfigOptionError("[storage]debug_discard = True is no longer supported.")
-- 
2.45.2