From: Daira Hopwood Date: Fri, 17 May 2013 16:39:20 +0000 (+0100) Subject: Refactoring to make backend configuration accessible from outside Client. refs #1971 X-Git-Url: https://git.rkrishnan.org/%3C?a=commitdiff_plain;h=e786fcf1f771e7b61ffe47b769e834c0d54141fb;p=tahoe-lafs%2Ftahoe-lafs.git Refactoring to make backend configuration accessible from outside Client. refs #1971 Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index c2242c2f..d03b2c3e 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -256,16 +256,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] @@ -279,9 +277,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.")