from .common import BaseOptions, BasedirOptions, get_aliases
from .cli import MakeDirectoryOptions, ListOptions, LnOptions
import tahoe_ls, tahoe_mv
+from allmydata.util import fileutil
+
+
+INVITE_SEPERATOR = "~"
class CreateOptions(BasedirOptions):
nickname = None
rc = tahoe_add_alias.create_alias(options)
return rc
-class InviteOptions(BasedirOptions):
- nickname = None
- synopsis = "MAGIC_ALIAS: NICKNAME"
- stdin = StringIO("")
- def parseArgs(self, alias, nickname=None):
- BasedirOptions.parseArgs(self)
- self.alias = alias
- self.nickname = nickname
- node_url_file = os.path.join(self['node-directory'], "node.url")
- self['node-url'] = open(node_url_file, "r").read().strip()
- 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
readonly_cap = json.loads(ls_json)[1][u"ro_uri"]
return readonly_cap
+class InviteOptions(BasedirOptions):
+ nickname = None
+ synopsis = "MAGIC_ALIAS: NICKNAME"
+ stdin = StringIO("")
+ def parseArgs(self, alias, nickname=None):
+ BasedirOptions.parseArgs(self)
+ self.alias = alias
+ self.nickname = nickname
+ node_url_file = os.path.join(self['node-directory'], "node.url")
+ self['node-url'] = open(node_url_file, "r").read().strip()
+ aliases = get_aliases(self['node-directory'])
+ self.aliases = aliases
+
def invite(options):
from allmydata.scripts import tahoe_mkdir
mkdir_options = MakeDirectoryOptions()
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.stdin = StringIO("")
+ mkdir_options.stdout = StringIO()
+ mkdir_options.stderr = StringIO()
mkdir_options.aliases = options.aliases
+ mkdir_options['node-url'] = options['node-url']
mkdir_options['node-directory'] = options['node-directory']
rc = tahoe_mkdir.mkdir(mkdir_options)
if rc != 0:
# XXX failure
- print "tahoe mkdir FAIL"
+ print >>options.stderr, "magic-folder: failed to mkdir\n"
return rc
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"
+ print >>options.stderr, "magic-folder: failed to diminish dmd write cap\n"
return -1
magic_write_cap = get_aliases(options["node-directory"])[options.alias]
rc = tahoe_mv.mv(ln_options, mode="link")
if rc != 0:
# XXX failure
- print "tahoe ln FAIL"
+ print >>options.stderr, "magic-folder: failed to create link\n"
return -1
- print "\ninvite code:\n%s-%s\n" % (magic_readonly_cap, dmd_write_cap)
+
+ print >>options.stdout, "%s%s%s" % (magic_readonly_cap, INVITE_SEPERATOR, dmd_write_cap)
return rc
class JoinOptions(BasedirOptions):
- pass
+ synopsis = "INVITE_CODE LOCAL_DIR"
+ def parseArgs(self, invite_code, local_dir):
+ BasedirOptions.parseArgs(self)
+ self.invite_code = invite_code
+ self.local_dir = local_dir
def join(options):
- pass
+ fields = options.invite_code.split(INVITE_SEPERATOR)
+ assert len(fields) == 2
+ magic_readonly_cap, dmd_write_cap = fields
+
+ dmd_cap_file = os.path.join(options["node-directory"], "private/magic_folder_dircap")
+ fileutil.write(dmd_cap_file, dmd_write_cap)
+
+ collective_readcap_file = os.path.join(options["node-directory"], "private/collective_dircap")
+ fileutil.write(collective_readcap_file, magic_readonly_cap)
+
+ # Edit the client's tahoe.cfg to set [magic_folder] enabled = True and [magic_folder] local.directory = LOCAL_DIR.
+ # ...
class MagicFolderCommand(BaseOptions):
subCommands = [