]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/webish.py
wui: improved columns in welcome page server list
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / webish.py
index 5ab9337d3bbbcbe5bd55bb71d76a803a11045e81..51286bdeedfb48615635d8fa64ac2d7f2049a6fa 100644 (file)
@@ -3,7 +3,7 @@ from twisted.application import service, strports, internet
 from twisted.web import http
 from twisted.internet import defer
 from nevow import appserver, inevow, static
-from allmydata.util import log
+from allmydata.util import log, fileutil
 
 from allmydata.web import introweb, root
 from allmydata.web.common import IOpHandleTable, MyExceptionHandler
@@ -129,14 +129,14 @@ class WebishServer(service.MultiService):
     name = "webish"
 
     def __init__(self, client, webport, nodeurl_path=None, staticdir=None,
-                                        clock=None):
+                 clock=None, now=None):
         service.MultiService.__init__(self)
         # the 'data' argument to all render() methods default to the Client
         # the 'clock' argument to root.Root is, if set, a
         # twisted.internet.task.Clock that is provided by the unit tests
         # so that they can test features that involve the passage of
         # time in a deterministic manner.
-        self.root = root.Root(client, clock)
+        self.root = root.Root(client, clock, now)
         self.buildServer(webport, nodeurl_path, staticdir)
         if self.root.child_operations:
             self.site.remember(self.root.child_operations, IOpHandleTable)
@@ -157,15 +157,20 @@ class WebishServer(service.MultiService):
         self._scheme = None
         self._portnum = None
         self._url = None
-        self.listener = s # stash it so the tests can query for the portnum
+        self._listener = s # stash it so we can query for the portnum
 
         self._started = defer.Deferred()
         if nodeurl_path:
-            self._started.addCallback(self._write_nodeurl_file, nodeurl_path)
+            def _write_nodeurl_file(ign):
+                # this file will be created with default permissions
+                line = self.getURL() + "\n"
+                fileutil.write_atomically(nodeurl_path, line, mode="")
+            self._started.addCallback(_write_nodeurl_file)
 
     def getURL(self):
         assert self._url
         return self._url
+
     def getPortnum(self):
         assert self._portnum
         return self._portnum
@@ -183,7 +188,7 @@ class WebishServer(service.MultiService):
             return f
 
         service.MultiService.startService(self)
-        s = self.listener
+        s = self._listener
         if hasattr(s, 'endpoint') and hasattr(s, '_waitingForPort'):
             # Twisted 10.2 gives us a StreamServerEndpointService. This is
             # ugly but should do for now.
@@ -206,13 +211,6 @@ class WebishServer(service.MultiService):
             self._started.errback(AssertionError("couldn't find out the scheme or port for the web-API server"))
 
 
-    def _write_nodeurl_file(self, junk, nodeurl_path):
-        if self._url:
-            f = open(nodeurl_path, 'wb')
-            # this file is world-readable
-            f.write(self._url + "\n")
-            f.close()
-
 class IntroducerWebishServer(WebishServer):
     def __init__(self, introducer, webport, nodeurl_path=None, staticdir=None):
         service.MultiService.__init__(self)