]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Finish writing the invite implementation
authorDavid Stainton <dstainton415@gmail.com>
Tue, 23 Jun 2015 03:40:55 +0000 (20:40 -0700)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 20 Jul 2015 23:42:34 +0000 (00:42 +0100)
src/allmydata/scripts/magic_folder_cli.py
src/allmydata/scripts/tahoe_ls.py
src/allmydata/test/test_cli_magic_folder.py

index efc5e0b46f4aa6e2867ef103c04fd050c21a3907..5a88ff75e1ea618aaa183b539cc2d80e58640a1d 100644 (file)
@@ -1,12 +1,12 @@
 
-import os
+import os, json
 from cStringIO import StringIO
 from twisted.python import usage, failure
 
 from allmydata.scripts.common import BaseOptions
 from .common import BaseOptions, BasedirOptions, get_aliases
-from .cli import MakeDirectoryOptions
-
+from .cli import MakeDirectoryOptions, ListOptions, LnOptions
+import tahoe_ls, tahoe_mv
 
 class CreateOptions(BasedirOptions):
     nickname = None
@@ -40,21 +40,69 @@ class InviteOptions(BasedirOptions):
         aliases = get_aliases(self['node-directory'])
         self.aliases = aliases
 
+def diminish_readonly(write_cap, node_url):
+    """
+    given a write cap and a node url I will return the corresponding readcap
+    or I'll return None on failure
+    """
+    list_options = ListOptions()
+    list_options.where = u"%s" % (write_cap,)
+    list_options["json"] = True
+    list_options.aliases = {}
+    list_options.stdin = StringIO("")
+    list_options.stdout = StringIO()
+    list_options.stderr = StringIO()
+    list_options['node-url'] = node_url
+
+    rc = tahoe_ls.list(list_options)
+    if rc != 0:
+        return None
+
+    ls_json = list_options.stdout.getvalue()
+    readonly_cap = json.loads(ls_json)[1][u"ro_uri"]
+    return readonly_cap
+
 def invite(options):
     from allmydata.scripts import tahoe_mkdir
     mkdir_options = MakeDirectoryOptions()
-    mkdir_options.where = "%s:%s" % (options.alias, options.nickname)
+    mkdir_options.where = None
     mkdir_options.stdout = options.stdout
     mkdir_options.stdin = options.stdin
     mkdir_options.stderr = options.stderr
     mkdir_options['node-url'] = options['node-url']
     mkdir_options.aliases = options.aliases
     mkdir_options['node-directory'] = options['node-directory']
+
     rc = tahoe_mkdir.mkdir(mkdir_options)
     if rc != 0:
+        # XXX failure
+        print "tahoe mkdir FAIL"
         return rc
-    write_capability = mkdir_options.stdout.getvalue().strip()
-    print "\nNEW write cap %s" % (write_capability,)
+    dmd_write_cap = mkdir_options.stdout.getvalue().strip()
+    dmd_readonly_cap = diminish_readonly(dmd_write_cap, options["node-url"])
+    if dmd_readonly_cap is None:
+        # XXX failure
+        print "failure to diminish dmd write cap"
+        return -1
+
+    magic_write_cap = get_aliases(options["node-directory"])[options.alias]
+    magic_readonly_cap = diminish_readonly(magic_write_cap, options["node-url"])
+
+    # tahoe ln CLIENT_READCAP COLLECTIVE_WRITECAP/NICKNAME
+    ln_options = LnOptions()
+    ln_options["node-url"] = options["node-url"]
+    ln_options.from_file = dmd_readonly_cap
+    ln_options.to_file = "%s/%s" % (magic_write_cap, options.nickname)
+    ln_options.aliases = options.aliases
+    ln_options.stdin = StringIO("")
+    ln_options.stdout = StringIO()
+    ln_options.stderr = StringIO()
+    rc = tahoe_mv.mv(ln_options, mode="link")
+    if rc != 0:
+        # XXX failure
+        print "tahoe ln FAIL"
+        return -1
+    print "\ninvite code:\n%s-%s\n" % (magic_readonly_cap, dmd_write_cap)
     return rc
 
 class JoinOptions(BasedirOptions):
index 78eea1f26ab1749bcc0147a46d6faad69c1f4a37..530cf850f35115888c7c9965034d20fb614a6afe 100644 (file)
@@ -151,7 +151,6 @@ def list(options):
             line.append(uri)
         if options["readonly-uri"]:
             line.append(quote_output(ro_uri or "-", quotemarks=False))
-
         rows.append((encoding_error, line))
 
     max_widths = []
index 684e1c914bf96e9f8b5c547f0c09f3efb8392e6c..820ac446ec41502e3065913f7c3dbb902edfbab9 100644 (file)
@@ -25,7 +25,7 @@ class CreateMagicFolder(GridTestMixin, CLITestMixin, unittest.TestCase):
         return d
 
     def _invite(self, ignore):
-        d = self.do_cli("magic-folder", "invite", "magic", u"Alice:")
+        d = self.do_cli("magic-folder", "invite", u"magic", u"Alice")
         return d
 
     def test_create_invite_join(self):