change imports; introducer client.read_config

This commit is contained in:
meejah 2018-02-28 11:13:14 -07:00
parent 4c7f60f42a
commit 2937c729e3
2 changed files with 22 additions and 16 deletions

View File

@ -28,9 +28,7 @@ from allmydata.history import History
from allmydata.interfaces import IStatsProducer, SDMF_VERSION, MDMF_VERSION
from allmydata.nodemaker import NodeMaker
from allmydata.blacklist import Blacklist
from allmydata.node import OldConfigOptionError, _common_config_sections
from allmydata.node import read_config
from allmydata.node import get_app_versions
from allmydata import node
KiB=1024
@ -40,7 +38,7 @@ TiB=1024*GiB
PiB=1024*TiB
def _valid_config_sections():
cfg = _common_config_sections()
cfg = node._common_config_sections()
cfg.update({
"client": (
"helper.furl",
@ -165,6 +163,14 @@ class Terminator(service.Service):
return service.Service.stopService(self)
def read_config(basedir, portnumfile, generated_files=[]):
return node.read_config(
basedir, portnumfile,
generated_files=generated_files,
_valid_config_sections=_valid_config_sections,
)
#@defer.inlineCallbacks
def create_client(basedir=u".", _client_factory=None):
"""
@ -175,9 +181,7 @@ def create_client(basedir=u".", _client_factory=None):
:param _client_factory: for testing; the class to instantiate
"""
node.create_node_dir(basedir, CLIENT_README)
# load configuration
config = read_config(basedir, u"client.port", _valid_config_sections=_valid_config_sections)
config = read_config(basedir, u"client.port")
if _client_factory is None:
_client_factory = _Client
@ -301,7 +305,7 @@ class _Client(node.Node, pollmixin.PollMixin):
self.nickname,
str(allmydata.__full_version__),
str(self.OLDEST_SUPPORTED_VERSION),
get_app_versions(), self._sequencer,
node.get_app_versions(), self._sequencer,
introducer_cache_filepath)
self.introducer_clients.append(ic)
self.introducer_furls.append(introducer['furl'])
@ -596,8 +600,10 @@ class _Client(node.Node, pollmixin.PollMixin):
def init_magic_folder(self):
#print "init_magic_folder"
if self.config.get_config("drop_upload", "enabled", False, boolean=True):
raise OldConfigOptionError("The [drop_upload] section must be renamed to [magic_folder].\n"
"See docs/frontends/magic-folder.rst for more information.")
raise node.OldConfigOptionError(
"The [drop_upload] section must be renamed to [magic_folder].\n"
"See docs/frontends/magic-folder.rst for more information."
)
if self.config.get_config("magic_folder", "enabled", False, boolean=True):
from allmydata.frontends import magic_folder

View File

@ -16,8 +16,8 @@ import foolscap.logging.log
from twisted.application import service
from allmydata.node import Node, formatTimeTahoeStyle, MissingConfigEntry, read_config, config_from_string, create_node_dir
from allmydata.introducer.server import create_introducer
from allmydata.client import create_client
from allmydata.client import _valid_config_sections as client_valid_config_sections
from allmydata import client
from allmydata.util import fileutil, iputil
from allmydata.util import i2p_provider, tor_provider
from allmydata.util.namespace import Namespace
@ -436,7 +436,7 @@ class Listeners(unittest.TestCase):
f.write("tub.location = tcp:example.org:1234\n")
# we're doing a lot of calling-into-setup-methods here, it might be
# better to just create a real Node instance, I'm not sure.
config = read_config(
config = client.read_config(
n.basedir,
"client.port",
_valid_config_sections=client_valid_config_sections,
@ -474,7 +474,7 @@ class ClientNotListening(unittest.TestCase):
f.write(NOLISTEN)
f.write(DISABLE_STORAGE)
f.close()
n = create_client(basedir)
n = client.create_client(basedir)
self.assertEqual(n.tub.getListeners(), [])
def test_disabled_but_storage(self):
@ -485,7 +485,7 @@ class ClientNotListening(unittest.TestCase):
f.write(NOLISTEN)
f.write(ENABLE_STORAGE)
f.close()
e = self.assertRaises(ValueError, create_client, basedir)
e = self.assertRaises(ValueError, client.create_client, basedir)
self.assertIn("storage is enabled, but tub is not listening", str(e))
def test_disabled_but_helper(self):
@ -497,7 +497,7 @@ class ClientNotListening(unittest.TestCase):
f.write(DISABLE_STORAGE)
f.write(ENABLE_HELPER)
f.close()
e = self.assertRaises(ValueError, create_client, basedir)
e = self.assertRaises(ValueError, client.create_client, basedir)
self.assertIn("helper is enabled, but tub is not listening", str(e))
class IntroducerNotListening(unittest.TestCase):