]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
create a personal (non-shared) vdrive, in addition to the global shared one
authorBrian Warner <warner@lothar.com>
Fri, 15 Jun 2007 08:33:24 +0000 (01:33 -0700)
committerBrian Warner <warner@lothar.com>
Fri, 15 Jun 2007 08:33:24 +0000 (01:33 -0700)
src/allmydata/client.py
src/allmydata/web/welcome.xhtml
src/allmydata/webish.py

index a51cfcdcd8a192beee4fafa1a958665133d70460..bdd9189e5da3b392510d5b740c1e3c8fdbd707cc 100644 (file)
@@ -28,6 +28,7 @@ class Client(node.Node, Referenceable):
     GLOBAL_VDRIVE_FURL_FILE = "vdrive.furl"
     MY_FURL_FILE = "myself.furl"
     SUICIDE_PREVENTION_HOTLINE_FILE = "suicide_prevention_hotline"
+    MY_VDRIVE_FURL_FILE = "my_vdrive.furl"
 
     # we're pretty narrow-minded right now
     OLDEST_SUPPORTED_VERSION = allmydata.__version__
@@ -61,6 +62,7 @@ class Client(node.Node, Referenceable):
             self.global_vdrive_furl = f.read().strip()
             f.close()
             #self.add_service(VDrive())
+        self._my_vdrive = None
 
         hotline_file = os.path.join(self.basedir,
                                     self.SUICIDE_PREVENTION_HOTLINE_FILE)
@@ -115,6 +117,8 @@ class Client(node.Node, Referenceable):
         self.log("connected to vdrive server")
         d = vdrive_server.callRemote("get_public_root_furl")
         d.addCallback(self._got_vdrive_root_furl, vdrive_server)
+        d.addCallback(self._create_my_vdrive)
+        d.addCallback(self._got_my_vdrive)
 
     def _got_vdrive_root_furl(self, vdrive_root_furl, vdrive_server):
         root = DirectoryNode(vdrive_root_furl, self)
@@ -131,6 +135,34 @@ class Client(node.Node, Referenceable):
             webish = self.getServiceNamed("webish")
             webish.set_vdrive_root(root)
 
+    def _create_my_vdrive(self, ignored=None):
+        MY_VDRIVE_FURL_FILE = os.path.join(self.basedir,
+                                           self.MY_VDRIVE_FURL_FILE)
+        try:
+            f = open(MY_VDRIVE_FURL_FILE, "r")
+            my_vdrive_furl = f.read().strip()
+            f.close()
+            return defer.succeed(DirectoryNode(my_vdrive_furl, self))
+        except EnvironmentError:
+            d = self._vdrive_server.callRemote("create_directory")
+            def _got_directory(dirnode):
+                f = open(MY_VDRIVE_FURL_FILE, "w")
+                f.write(dirnode.furl + "\n")
+                f.close()
+                dirnode._set_client(self)
+                return dirnode
+            d.addCallback(_got_directory)
+            return d
+
+    def _got_my_vdrive(self, my_vdrive):
+        assert isinstance(my_vdrive, DirectoryNode), my_vdrive
+        self._my_vdrive = my_vdrive
+
+        if "webish" in self.namedServices:
+            webish = self.getServiceNamed("webish")
+            webish.set_my_vdrive_root(my_vdrive)
+
+
     def remote_get_versions(self):
         return str(allmydata.__version__), str(self.OLDEST_SUPPORTED_VERSION)
 
index 16f5cda09d0a96511190bf817d2250ae25850015..b5cd72d994adc7b7fdd9e766f074422f0c55a187 100644 (file)
@@ -10,7 +10,8 @@
 
 <h1>Welcome To AllMyData! (tahoe2)</h1>
 
-<div n:render="vdrive" />
+<div n:render="global_vdrive" />
+<div n:render="my_vdrive" />
 
 <h2>Grid Status</h2>
 
index e40e15bd9050578cff970456c965d9f1b6e69330..9671ef6be68ffbb06242bc5651a76bc15d57b495 100644 (file)
@@ -63,12 +63,20 @@ class Welcome(rend.Page):
         ctx.fillSlots("peerid", nodeid_a)
         return ctx.tag
 
-    def render_vdrive(self, ctx, data):
-        if IClient(ctx).connected_to_vdrive():
+    def render_global_vdrive(self, ctx, data):
+        if self.has_global_vdrive:
             return T.p["To view the global shared filestore, ",
-                       T.a(href="../vdrive")["Click Here!"],
+                       T.a(href="../global_vdrive")["Click Here!"],
+                       ]
+        return T.p["vdrive.furl not specified (or vdrive server not "
+                   "responding), no vdrive available."]
+
+    def render_my_vdrive(self, ctx, data):
+        if self.has_my_vdrive:
+            return T.p["To view your personal private non-shared filestore, ",
+                       T.a(href="../my_vdrive")["Click Here!"],
                        ]
-        return T.p["vdrive.furl not specified, no vdrive available."]
+        return T.p["personal vdrive not available."]
 
     # this is a form where users can download files by URI
 
@@ -351,6 +359,8 @@ class WebishServer(service.MultiService):
     def __init__(self, webport):
         service.MultiService.__init__(self)
         self.root = Root()
+        self.root.child_welcome.has_global_vdrive = False
+        self.root.child_welcome.has_my_vdrive = False
         placeholder = static.Data("sorry, still initializing", "text/plain")
         self.root.putChild("vdrive", placeholder)
         self.root.putChild("", url.here.child("welcome"))#Welcome())
@@ -372,8 +382,13 @@ class WebishServer(service.MultiService):
         #self.site._client = self.parent
 
     def set_vdrive_root(self, root):
-        self.root.putChild("vdrive", Directory(root, "/"))
+        self.root.putChild("global_vdrive", Directory(root, "/"))
+        self.root.child_welcome.has_global_vdrive = True
         # I tried doing it this way and for some reason it didn't seem to work
         #print "REMEMBERING", self.site, dl, IDownloader
         #self.site.remember(dl, IDownloader)
 
+    def set_my_vdrive_root(self, my_vdrive):
+        self.root.putChild("my_vdrive", Directory(my_vdrive, "~"))
+        self.root.child_welcome.has_my_vdrive = True
+