from allmydata.util.assertutil import precondition, _assert
from allmydata.util.fileutil import abspath_expanduser_unicode
from allmydata.util.encodingutil import get_filesystem_encoding, quote_output
+from allmydata.util import configutil
# Add our application versions to the data that Foolscap's LogPublisher
# reports.
% (quote_output(fn), section, option))
return default
- def set_config(self, section, option, value):
- if not self.config.has_section(section):
- self.config.add_section(section)
- self.config.set(section, option, value)
- assert self.config.get(section, option) == value
-
def read_config(self):
self.error_about_old_config_files()
self.config = ConfigParser.SafeConfigParser()
tahoe_cfg = os.path.join(self.basedir, "tahoe.cfg")
try:
- f = open(tahoe_cfg, "rb")
- try:
- # Skip any initial Byte Order Mark. Since this is an ordinary file, we
- # don't need to handle incomplete reads, and can assume seekability.
- if f.read(3) != '\xEF\xBB\xBF':
- f.seek(0)
- self.config.readfp(f)
- finally:
- f.close()
+ self.config = configutil.get_config(tahoe_cfg)
except EnvironmentError:
if os.path.exists(tahoe_cfg):
raise
# provide a value.
try:
file_tubport = fileutil.read(self._portnumfile).strip()
- self.set_config("node", "tub.port", file_tubport)
+ configutil.set_config(self.config, "node", "tub.port", file_tubport)
except EnvironmentError:
if os.path.exists(self._portnumfile):
raise
service.MultiService.startService(self)
d = defer.succeed(None)
- d.addCallback(lambda res: iputil.get_local_addresses_async())
d.addCallback(self._setup_tub)
def _ready(res):
self.log("%s running" % self.NODETYPE)
self.tub.setOption("log-gatherer-furl", lgfurl)
self.tub.setOption("log-gatherer-furlfile",
os.path.join(self.basedir, "log_gatherer.furl"))
- self.tub.setOption("bridge-twisted-logs", True)
+
incident_dir = os.path.join(self.basedir, "logs", "incidents")
foolscap.logging.log.setLogDir(incident_dir.encode(get_filesystem_encoding()))
def log(self, *args, **kwargs):
return log.msg(*args, **kwargs)
- def _setup_tub(self, local_addresses):
+ def _setup_tub(self, ign):
# we can't get a dynamically-assigned portnum until our Tub is
# running, which means after startService.
l = self.tub.getListeners()[0]
location = self.get_config("node", "tub.location", "AUTO")
- # Replace the location "AUTO" with the detected local addresses.
+ # Replace the location "AUTO", if present, with the detected local addresses.
split_location = location.split(",")
if "AUTO" in split_location:
- split_location.remove("AUTO")
- split_location.extend([ "%s:%d" % (addr, portnum)
- for addr in local_addresses ])
- location = ",".join(split_location)
-
- self.log("Tub location set to %s" % location)
- self.tub.setLocation(location)
-
- return self.tub
+ d = iputil.get_local_addresses_async()
+ def _add_local(local_addresses):
+ while "AUTO" in split_location:
+ split_location.remove("AUTO")
+
+ split_location.extend([ "%s:%d" % (addr, portnum)
+ for addr in local_addresses ])
+ return ",".join(split_location)
+ d.addCallback(_add_local)
+ else:
+ d = defer.succeed(location)
+
+ def _got_location(location):
+ self.log("Tub location set to %s" % (location,))
+ self.tub.setLocation(location)
+ return self.tub
+ d.addCallback(_got_location)
+ return d
def when_tub_ready(self):
return self._tub_ready_observerlist.when_fired()