mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-02 03:06:41 +00:00
Finish writing the invite implementation
This commit is contained in:
parent
2e96671a48
commit
632e5e1db0
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
import os
|
import os, json
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from twisted.python import usage, failure
|
from twisted.python import usage, failure
|
||||||
|
|
||||||
from allmydata.scripts.common import BaseOptions
|
from allmydata.scripts.common import BaseOptions
|
||||||
from .common import BaseOptions, BasedirOptions, get_aliases
|
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):
|
class CreateOptions(BasedirOptions):
|
||||||
nickname = None
|
nickname = None
|
||||||
@ -40,21 +40,69 @@ class InviteOptions(BasedirOptions):
|
|||||||
aliases = get_aliases(self['node-directory'])
|
aliases = get_aliases(self['node-directory'])
|
||||||
self.aliases = aliases
|
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):
|
def invite(options):
|
||||||
from allmydata.scripts import tahoe_mkdir
|
from allmydata.scripts import tahoe_mkdir
|
||||||
mkdir_options = MakeDirectoryOptions()
|
mkdir_options = MakeDirectoryOptions()
|
||||||
mkdir_options.where = "%s:%s" % (options.alias, options.nickname)
|
mkdir_options.where = None
|
||||||
mkdir_options.stdout = options.stdout
|
mkdir_options.stdout = options.stdout
|
||||||
mkdir_options.stdin = options.stdin
|
mkdir_options.stdin = options.stdin
|
||||||
mkdir_options.stderr = options.stderr
|
mkdir_options.stderr = options.stderr
|
||||||
mkdir_options['node-url'] = options['node-url']
|
mkdir_options['node-url'] = options['node-url']
|
||||||
mkdir_options.aliases = options.aliases
|
mkdir_options.aliases = options.aliases
|
||||||
mkdir_options['node-directory'] = options['node-directory']
|
mkdir_options['node-directory'] = options['node-directory']
|
||||||
|
|
||||||
rc = tahoe_mkdir.mkdir(mkdir_options)
|
rc = tahoe_mkdir.mkdir(mkdir_options)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
|
# XXX failure
|
||||||
|
print "tahoe mkdir FAIL"
|
||||||
return rc
|
return rc
|
||||||
write_capability = mkdir_options.stdout.getvalue().strip()
|
dmd_write_cap = mkdir_options.stdout.getvalue().strip()
|
||||||
print "\nNEW write cap %s" % (write_capability,)
|
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
|
return rc
|
||||||
|
|
||||||
class JoinOptions(BasedirOptions):
|
class JoinOptions(BasedirOptions):
|
||||||
|
@ -151,7 +151,6 @@ def list(options):
|
|||||||
line.append(uri)
|
line.append(uri)
|
||||||
if options["readonly-uri"]:
|
if options["readonly-uri"]:
|
||||||
line.append(quote_output(ro_uri or "-", quotemarks=False))
|
line.append(quote_output(ro_uri or "-", quotemarks=False))
|
||||||
|
|
||||||
rows.append((encoding_error, line))
|
rows.append((encoding_error, line))
|
||||||
|
|
||||||
max_widths = []
|
max_widths = []
|
||||||
|
@ -25,7 +25,7 @@ class CreateMagicFolder(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def _invite(self, ignore):
|
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
|
return d
|
||||||
|
|
||||||
def test_create_invite_join(self):
|
def test_create_invite_join(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user